From 45736f7396593c2f4ef9ebf35c561e7a32111f63 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Thu, 25 Sep 2014 00:47:47 +0100 Subject: [PATCH] logging: Provide lg_exitstatus This will allow us to remove a bunch of formulaic exit status handling. Signed-off-by: Ian Jackson --- log.c | 17 +++++++++++++++++ secnet.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/log.c b/log.c index 156f354..3748f91 100644 --- a/log.c +++ b/log.c @@ -225,6 +225,23 @@ void lg_perror(struct log_if *lg, const char *desc, struct cloc *loc, va_end(al); } +void lg_exitstatus(struct log_if *lg, const char *desc, struct cloc *loc, + int class, int status, const char *progname) +{ + if (!status) + lg_perror(lg,desc,loc,class,0,"%s exited",progname); + else if (WIFEXITED(status)) + lg_perror(lg,desc,loc,class,0,"%s exited with error exit status %d", + progname,WEXITSTATUS(status)); + else if (WIFSIGNALED(status)) + lg_perror(lg,desc,loc,class,0,"%s died due to fatal signal %s (%d)%s", + progname,strsignal(WTERMSIG(status)),WTERMSIG(status), + WCOREDUMP(status)?" (core dumped)":""); + else + lg_perror(lg,desc,loc,class,0,"%s died with unknown wait status %d", + progname,status); +} + struct log_if *init_log(list_t *ll) { int i=0; diff --git a/secnet.h b/secnet.h index 5d72f95..3b54def 100644 --- a/secnet.h +++ b/secnet.h @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -597,6 +598,8 @@ void lg_vperror(struct log_if *lg, const char *desc, struct cloc *loc, void lg_perror(struct log_if *lg, const char *desc, struct cloc *loc, int class, int errnoval, const char *fmt, ...) FORMAT(printf,6,7); +void lg_exitstatus(struct log_if *lg, const char *desc, struct cloc *loc, + int class, int status, const char *progname); /* The cfgfatal() family of functions require messages that end in '\n' */ extern NORETURN(cfgfatal(struct cloc loc, cstring_t facility, -- 2.30.2