summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-01-20 22:35:45 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-01-20 22:35:45 +0000
commit5af73b17714076498a98b6a5679a4700399eaaa0 (patch)
treed81912cf894edfb056e4a59caf7530c2b754181f /src
parent2844097114fe7b36e03ff863ce8daaaf9d6583c7 (diff)
downloads6-5af73b17714076498a98b6a5679a4700399eaaa0.tar.xz
Add readiness support to s6-svstat
Diffstat (limited to 'src')
-rw-r--r--src/include/s6/s6-fdholder.h1
-rw-r--r--src/libs6/s6_fdholder_store_async.c4
-rw-r--r--src/supervision/deps-exe/s6-notifywhenup (renamed from src/daemontools-extras/deps-exe/s6-notifywhenup)0
-rw-r--r--src/supervision/s6-notifywhenup.c (renamed from src/daemontools-extras/s6-notifywhenup.c)7
-rw-r--r--src/supervision/s6-svstat.c31
5 files changed, 32 insertions, 11 deletions
diff --git a/src/include/s6/s6-fdholder.h b/src/include/s6/s6-fdholder.h
index 0285a21..7907607 100644
--- a/src/include/s6/s6-fdholder.h
+++ b/src/include/s6/s6-fdholder.h
@@ -10,6 +10,7 @@
#include <skalibs/unixconnection.h>
#define S6_FDHOLDER_ID_SIZE 255
+#define S6_FDHOLDER_MAX 16
typedef struct s6_fdholder_s s6_fdholder_t, *s6_fdholder_t_ref ;
struct s6_fdholder_s
diff --git a/src/libs6/s6_fdholder_store_async.c b/src/libs6/s6_fdholder_store_async.c
index dfaab05..2f783b1 100644
--- a/src/libs6/s6_fdholder_store_async.c
+++ b/src/libs6/s6_fdholder_store_async.c
@@ -14,7 +14,7 @@ int s6_fdholder_store_async (s6_fdholder_t *a, int fd, char const *id, tain_t co
siovec_t v[2] = { { .s = pack, .len = 2 + TAIN_PACK }, { .s = id, .len = idlen + 1 } } ;
unixmessage_v_t m = { .v = v, .vlen = 2, .fds = &fd, .nfds = 1 } ;
if (idlen > S6_FDHOLDER_ID_SIZE) return (errno = ENAMETOOLONG, 0) ;
- pack[1] = (unsigned char)idlen ;
- tain_pack(pack + 2, limit) ;
+ tain_pack(pack + 1, limit) ;
+ pack[1+TAIN_PACK] = (unsigned char)idlen ;
return unixmessage_putv(&a->connection.out, &m) ;
}
diff --git a/src/daemontools-extras/deps-exe/s6-notifywhenup b/src/supervision/deps-exe/s6-notifywhenup
index 077e863..077e863 100644
--- a/src/daemontools-extras/deps-exe/s6-notifywhenup
+++ b/src/supervision/deps-exe/s6-notifywhenup
diff --git a/src/daemontools-extras/s6-notifywhenup.c b/src/supervision/s6-notifywhenup.c
index e1c02b7..98f0401 100644
--- a/src/daemontools-extras/s6-notifywhenup.c
+++ b/src/supervision/s6-notifywhenup.c
@@ -21,6 +21,7 @@ static int run_child (int fd, char const *fifodir, unsigned int timeout)
char dummy[4096] ;
iopause_fd x = { .fd = fd, .events = IOPAUSE_READ } ;
tain_t deadline ;
+ char pack[TAIN_PACK] ;
if (!tain_now_g()) strerr_diefu1sys(111, "tain_now") ;
if (timeout) tain_from_millisecs(&deadline, timeout) ;
else deadline = tain_infinite_relative ;
@@ -38,9 +39,9 @@ static int run_child (int fd, char const *fifodir, unsigned int timeout)
if (byte_chr(dummy, r, '\n') < r) break ;
}
close(fd) ;
- fd = open_create(S6_SUPERVISE_READY_FILENAME) ;
- if (fd < 0) strerr_warnwu1sys("touch " S6_SUPERVISE_READY_FILENAME) ;
- else close(fd) ;
+ tain_pack(pack, &STAMP) ;
+ if (!openwritenclose_suffix(S6_SUPERVISE_READY_FILENAME, pack, TAIN_PACK, ".new"))
+ strerr_warnwu1sys("open " S6_SUPERVISE_READY_FILENAME " for writing") ;
ftrigw_notify(fifodir, 'U') ;
return 0 ;
}
diff --git a/src/supervision/s6-svstat.c b/src/supervision/s6-svstat.c
index 4f95a0c..de8fe0d 100644
--- a/src/supervision/s6-svstat.c
+++ b/src/supervision/s6-svstat.c
@@ -23,6 +23,7 @@ int main (int argc, char const *const *argv)
s6_svstatus_t status ;
int flagnum = 0 ;
int isup, normallyup ;
+ tain_t readytime = TAIN_ZERO ;
char fmt[UINT_FMT] ;
PROG = "s6-svstat" ;
{
@@ -44,22 +45,32 @@ int main (int argc, char const *const *argv)
if (!s6_svstatus_read(*argv, &status))
strerr_diefu2sys(111, "read status for ", *argv) ;
+ tain_now_g() ;
+ if (tain_future(&status.stamp)) tain_copynow(&status.stamp) ;
+
{
+ char pack[TAIN_PACK] ;
struct stat st ;
unsigned int dirlen = str_len(*argv) ;
- char fn[dirlen + 6] ;
+ char fn[dirlen + sizeof(S6_SUPERVISE_READY_FILENAME) + 1] ;
byte_copy(fn, dirlen, *argv) ;
byte_copy(fn + dirlen, 6, "/down") ;
if (stat(fn, &st) == -1)
if (errno != ENOENT) strerr_diefu2sys(111, "stat ", fn) ;
else normallyup = 1 ;
else normallyup = 0 ;
+ byte_copy(fn + dirlen, sizeof(S6_SUPERVISE_READY_FILENAME) + 1, "/" S6_SUPERVISE_READY_FILENAME) ;
+ if (openreadnclose(fn, pack, TAIN_PACK) < TAIN_PACK)
+ {
+ if (errno != ENOENT) strerr_warnwu2sys("read ", fn) ;
+ }
+ else
+ {
+ tain_unpack(pack, &readytime) ;
+ if (tain_future(&readytime)) tain_copynow(&readytime) ;
+ }
}
- tain_now_g() ;
- if (tain_future(&status.stamp)) tain_copynow(&status.stamp) ;
- tain_sub(&status.stamp, &STAMP, &status.stamp) ;
-
isup = status.pid && !status.flagfinishing ;
if (isup)
{
@@ -89,8 +100,9 @@ int main (int argc, char const *const *argv)
buffer_putnoflush(buffer_1small, ") ", 2) ;
}
+ tain_sub(&status.stamp, &STAMP, &status.stamp) ;
buffer_putnoflush(buffer_1small, fmt, uint64_fmt(fmt, status.stamp.sec.x)) ;
- buffer_putnoflush(buffer_1small," seconds", 8) ;
+ buffer_putnoflush(buffer_1small, " seconds", 8) ;
if (isup && !normallyup)
buffer_putnoflush(buffer_1small, ", normally down", 15) ;
@@ -103,6 +115,13 @@ int main (int argc, char const *const *argv)
if (isup && (status.flagwant == 'd'))
buffer_putnoflush(buffer_1small, ", want down", 12) ;
+ if (readytime.sec.x)
+ {
+ tain_sub(&readytime, &STAMP, &readytime) ;
+ buffer_putnoflush(buffer_1small, ", ready ", 8) ;
+ buffer_putnoflush(buffer_1small, fmt, uint64_fmt(fmt, readytime.sec.x)) ;
+ buffer_putnoflush(buffer_1small, " seconds", 8) ;
+ }
if (buffer_putflush(buffer_1small, "\n", 1) < 0)
strerr_diefu1sys(111, "write to stdout") ;
return 0 ;