diff --git a/src/lib/daemon/inc/daemon.h b/src/lib/daemon/inc/daemon.h index fdf12805..52239668 100644 --- a/src/lib/daemon/inc/daemon.h +++ b/src/lib/daemon/inc/daemon.h @@ -76,6 +76,7 @@ struct __daemon bool dn_auto_restart; /* Enable daemoness auto restart on error */ char *dn_pidfile_path; /* PID file */ bool dn_pidfile_create; /* true whether we should create the PID file */ + int dn_exit_status; /* Exit status of the daemon */ }; extern bool daemon_init(daemon_t *self, const char *exe_path, int flags); @@ -91,6 +92,7 @@ extern bool daemon_atexit(daemon_t *self, daemon_atexit_fn_t *fn); extern bool daemon_atrestart(daemon_t *self, daemon_atrestart_fn_t *fn); extern bool daemon_pidfile_set(daemon_t *self, const char *path, bool create); extern bool daemon_is_started(daemon_t *self, bool *started); +extern bool daemon_get_exit_status(const daemon_t *self, int *exit_status); #define daemon_arg_add(self, ...) \ daemon_arg_add_a(self, C_VPACK(__VA_ARGS__)) diff --git a/src/lib/daemon/src/daemon.c b/src/lib/daemon/src/daemon.c index 0380cff9..23c809d4 100644 --- a/src/lib/daemon/src/daemon.c +++ b/src/lib/daemon/src/daemon.c @@ -414,6 +414,7 @@ void __daemon_child_ev(struct ev_loop *loop, ev_child *w, int revent) void __daemon_teardown(daemon_t *self, int wstatus) { /* Figure out the reason the process died */ + self->dn_exit_status = WEXITSTATUS(wstatus); if (WIFSIGNALED(wstatus)) { #if defined(WCOREDUMP) @@ -1013,3 +1014,13 @@ static bool __daemon_set_nonblock(int fd, bool enable) return true; } + +bool daemon_get_exit_status(const daemon_t *self, int *exit_status) +{ + if (!self) + return false; + if (exit_status) + *exit_status = self->dn_exit_status; + return true; +} +