From 16ae6c00a6bff617084422a89d645bbd475501e5 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 25 Sep 2014 00:50:10 +0100 Subject: [PATCH] logging: Use lg_exitstatus Replace two open-coded exit status checks with calls to lg_exitstatus. In the case of slip.c and udp.c this has no significant effect other than a slight change to message format. In the case of process.c, we no longer log the command's first argument. I consider this tolerable for simplifying the code. Signed-off-by: Ian Jackson --- process.c | 13 ++----------- slip.c | 19 ++++++------------- udp.c | 11 ++--------- 3 files changed, 10 insertions(+), 33 deletions(-) diff --git a/process.c b/process.c index 0a718e2..b75b9c0 100644 --- a/process.c +++ b/process.c @@ -143,17 +143,8 @@ int sys_cmd(const char *path, const char *arg, ...) fatal("sys_cmd: waitpid for %s returned wrong process ID!", path); if (rv) { - /* If the command failed reporting its exit status */ - if (WIFEXITED(rv)) - Message(M_ERR, "sys_cmd(%s,%s,...) exited with status %d\n", - path, arg, WEXITSTATUS(rv)); - else if(WIFSIGNALED(rv)) - Message(M_ERR, "sys_cmd(%s,%s,...) exited with signal %d (%s)%s\n", - path, arg, WTERMSIG(rv), strsignal(WTERMSIG(rv)), - WCOREDUMP(rv) ? " - core dumped" : ""); - else - Message(M_ERR, "sys_cmd(%s,%s,...) exited with wstat %#x\n", - path, arg, rv); + /* If the command failed report its exit status */ + lg_exitstatus(0,"sys_cmd",0,M_ERR,rv,path); } } else if (c==0) { char *args[100]; diff --git a/slip.c b/slip.c index badbc5d..3f7935a 100644 --- a/slip.c +++ b/slip.c @@ -230,20 +230,13 @@ static void userv_userv_callback(void *sst, pid_t pid, int status) "(expected %d)\n",pid,st->pid); return; } - if (!st->expecting_userv_exit) { - if (WIFEXITED(status)) { - fatal("%s: userv exited unexpectedly with status %d", - st->slip.nl.name,WEXITSTATUS(status)); - } else if (WIFSIGNALED(status)) { - fatal("%s: userv exited unexpectedly: uncaught signal %d", - st->slip.nl.name,WTERMSIG(status)); - } else { - fatal("%s: userv stopped unexpectedly", - st->slip.nl.name); - } + if (!(st->expecting_userv_exit && + (!status || + (WIFSIGNALED(status) && WTERMSIG(status)==SIGTERM)))) { + lg_exitstatus(0,st->slip.nl.name,0, + st->expecting_userv_exit ? M_WARNING : M_FATAL, + status,"userv"); } - Message(M_WARNING,"%s: userv subprocess died with status %d\n", - st->slip.nl.name,WEXITSTATUS(status)); st->pid=0; } diff --git a/udp.c b/udp.c index 6ac8e0f..5a363e0 100644 --- a/udp.c +++ b/udp.c @@ -248,15 +248,8 @@ bool_t udp_make_socket(struct udpcommon *uc, struct udpsock *us, if (errno==EINTR) continue; FAIL("waitpid for authbind"); } - if (WIFSIGNALED(status)) { - lg_perror(FAIL_LG,0,"authbind died on signal %s (%d)", - strsignal(WTERMSIG(status)),WTERMSIG(status)); - goto failed; - } - if (WIFEXITED(status) && WEXITSTATUS(status)!=0) { - lg_perror(FAIL_LG,0, - "authbind died with error exit status %d", - WEXITSTATUS(status)); + if (status) { + lg_exitstatus(FAIL_LG,status,"authbind"); goto failed; } } else { -- 2.30.2