Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/lib/daemon/inc/daemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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__))
Expand Down
11 changes: 11 additions & 0 deletions src/lib/daemon/src/daemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
}