summaryrefslogtreecommitdiff
path: root/src/supervision/s6-svstat.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-19 16:11:24 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-19 16:11:24 +0000
commit701540827e27a4f07ac725db3ce361d3be0c106f (patch)
tree98c4b2fb8ba8f69ef791feebdcd61cd5bca34140 /src/supervision/s6-svstat.c
parent83853a80eb18238796154164f9ea776b0c167ab7 (diff)
downloads6-701540827e27a4f07ac725db3ce361d3be0c106f.tar.xz
- added the s6_fdholder library to libs6. (Nothing useful yet.)
- fixed execline invocation in s6-log with slashpackage - integrated s6_svc_main.c's functionality into s6-svscanctl and deleted it - integrated Olivier Brunel's suggestions for wstat report in supervise/status - minor fixes to s6-supervise's status reports - separated sigaction calls in ftrigw_notifyb, this spares a few syscalls in s6-supervise - updated doc to reflect the changes - version bumped to 2.1.0.0 because API breakage (./finish, s6-svstat)
Diffstat (limited to 'src/supervision/s6-svstat.c')
-rw-r--r--src/supervision/s6-svstat.c48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/supervision/s6-svstat.c b/src/supervision/s6-svstat.c
index c986b8d..a4facf5 100644
--- a/src/supervision/s6-svstat.c
+++ b/src/supervision/s6-svstat.c
@@ -1,27 +1,46 @@
/* ISC license. */
-#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <sys/wait.h>
+#include <errno.h>
#include <skalibs/uint64.h>
#include <skalibs/uint.h>
#include <skalibs/bytestr.h>
#include <skalibs/buffer.h>
#include <skalibs/strerr2.h>
+#include <skalibs/sgetopt.h>
+#include <skalibs/sig.h>
#include <skalibs/tai.h>
#include <skalibs/djbunix.h>
#include <s6/s6-supervise.h>
-#define USAGE "s6-svstat servicedir"
+#define USAGE "s6-svstat [ -n ] servicedir"
+#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char const *const *argv)
{
s6_svstatus_t status ;
- char fmt[UINT_FMT] ;
+ int flagnum = 0 ;
int isup, normallyup ;
+ char fmt[UINT_FMT] ;
PROG = "s6-svstat" ;
- if (argc < 2) strerr_dieusage(100, USAGE) ;
- argv++ ; argc-- ;
+ {
+ subgetopt_t l = SUBGETOPT_ZERO ;
+ for (;;)
+ {
+ register int opt = subgetopt_r(argc, argv, "n", &l) ;
+ if (opt == -1) break ;
+ switch (opt)
+ {
+ case 'n' : flagnum = 1 ; break ;
+ default : dieusage() ;
+ }
+ }
+ argc -= l.ind ; argv += l.ind ;
+ }
+ if (!argc) dieusage() ;
+
if (!s6_svstatus_read(*argv, &status))
strerr_diefu2sys(111, "read status for ", *argv) ;
@@ -48,7 +67,24 @@ int main (int argc, char const *const *argv)
buffer_putnoflush(buffer_1small, fmt, uint_fmt(fmt, status.pid)) ;
buffer_putnoflush(buffer_1small, ") ", 2) ;
}
- else buffer_putnoflush(buffer_1small, "down ", 5) ;
+ else
+ {
+ buffer_putnoflush(buffer_1small, "down (", 6) ;
+ if (WIFSIGNALED(status.wstat))
+ {
+ buffer_putnoflush(buffer_1small, "signal ", 7) ;
+ if (flagnum)
+ buffer_putnoflush(buffer_1small, fmt, uint_fmt(fmt, WTERMSIG(status.wstat))) ;
+ else
+ buffer_putsnoflush(buffer_1small, sig_name(WTERMSIG(status.wstat))) ;
+ }
+ else
+ {
+ buffer_putnoflush(buffer_1small, "exitcode ", 9) ;
+ buffer_putnoflush(buffer_1small, fmt, uint_fmt(fmt, WEXITSTATUS(status.wstat))) ;
+ }
+ buffer_putnoflush(buffer_1small, ") ", 2) ;
+ }
buffer_putnoflush(buffer_1small, fmt, uint64_fmt(fmt, status.stamp.sec.x)) ;
buffer_putnoflush(buffer_1small," seconds", 8) ;