Save process exit status to svc_t

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson
2020-02-05 07:23:06 +01:00
parent 225510a270
commit c3eca9fe8f
4 changed files with 11 additions and 6 deletions
+1 -1
View File
@@ -33,7 +33,7 @@ int api_exit (void);
int client (int argc, char *argv[]);
void service_monitor (pid_t lost);
void service_monitor (pid_t lost, int status);
const char *plugin_hook_str(hook_point_t no);
int plugin_exists (hook_point_t no);
+6 -3
View File
@@ -375,7 +375,8 @@ static int service_start(svc_t *svc)
switch (svc->type) {
case SVC_TYPE_RUN:
result = WEXITSTATUS(complete(svc->cmd, pid));
svc->status = complete(svc->cmd, pid);
result = WEXITSTATUS(svc->status);
svc->start_time = svc->pid = 0;
svc->once++;
svc_set_state(svc, SVC_STOPPING_STATE);
@@ -1029,7 +1030,7 @@ void service_unregister(svc_t *svc)
svc_del(svc);
}
void service_monitor(pid_t lost)
void service_monitor(pid_t lost, int status)
{
svc_t *svc;
@@ -1045,7 +1046,9 @@ void service_monitor(pid_t lost)
return;
}
_d("collected %s(%d)", svc->cmd, lost);
_d("collected %s(%d), normal exit: %d, signaled: %d, exit code: %d",
svc->cmd, lost, WIFEXITED(status), WIFSIGNALED(status), WEXITSTATUS(status));
svc->status = status;
/* Try removing PID file (in case service does not clean up after itself) */
if (svc_is_daemon(svc)) {
+3 -2
View File
@@ -316,6 +316,7 @@ static void sigterm_cb(uev_t *w, void *arg, int events)
static void sigchld_cb(uev_t *w, void *arg, int events)
{
pid_t pid;
int status;
if (UEV_ERROR == events) {
_e("Unrecoverable error in signal watcher");
@@ -324,10 +325,10 @@ static void sigchld_cb(uev_t *w, void *arg, int events)
/* Reap all the children! */
do {
pid = waitpid(-1, NULL, WNOHANG);
pid = waitpid(-1, &status, WNOHANG);
if (pid > 0) {
_d("Collected child %d", pid);
service_monitor(pid);
service_monitor(pid, status);
}
} while (pid > 0);
}
+1
View File
@@ -98,6 +98,7 @@ typedef struct svc {
pid_t pid;
char pidfile[256];
long start_time; /* Start time, as seconds since boot, from sysinfo() */
int status; /* From waitpid() when process is collected */
const svc_state_t state; /* Paused, Reloading, Restart, Running, ... */
svc_type_t type; /* Service, run, task, inetd, ... */
int protect; /* Services like dbus-daemon & udev by Finit */