s6

Mirror/fork of https://skarnet.org/software/s6/
git clone https://ccx.te2000.cz/git/s6
Log | Files | Refs | README | LICENSE

commit 2f8e7b245b7fe187c41ea3655fce7551cfd7a48c
parent a359fda48970b7d02ef914e3f7aa0a9c9ff73f7f
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Wed,  4 Sep 2019 17:52:22 +0000

 Separate wall clocks from stopwatches

Diffstat:
Msrc/conn-tools/s6-ioconnect.c | 1+
Msrc/conn-tools/s6-sudoc.c | 1+
Msrc/conn-tools/s6-sudod.c | 1+
Msrc/daemontools-extras/s6-log.c | 28+++++++++++++++++-----------
Msrc/daemontools-extras/s6-setlock.c | 1+
Msrc/fdholder/s6-fdholder-delete.c | 1+
Msrc/fdholder/s6-fdholder-getdump.c | 1+
Msrc/fdholder/s6-fdholder-list.c | 1+
Msrc/fdholder/s6-fdholder-retrieve.c | 1+
Msrc/fdholder/s6-fdholder-setdump.c | 1+
Msrc/fdholder/s6-fdholder-store.c | 1+
Msrc/fdholder/s6-fdholder-transferdump.c | 1+
Msrc/fdholder/s6-fdholderd.c | 3+++
Msrc/libs6/s6-ftrigrd.c | 1+
Msrc/libs6/s6lockd.c | 3++-
Msrc/pipe-tools/s6-ftrig-listen.c | 1+
Msrc/pipe-tools/s6-ftrig-listen1.c | 1+
Msrc/pipe-tools/s6-ftrig-wait.c | 1+
Msrc/supervision/s6-notifyoncheck.c | 1+
Msrc/supervision/s6-permafailon.c | 2+-
Msrc/supervision/s6-supervise.c | 11++++++-----
Msrc/supervision/s6-svlisten.c | 1+
Msrc/supervision/s6-svlisten1.c | 1+
Msrc/supervision/s6-svscan.c | 1+
Msrc/supervision/s6-svstat.c | 2+-
Msrc/supervision/s6-svwait.c | 1+
26 files changed, 50 insertions(+), 19 deletions(-)

diff --git a/src/conn-tools/s6-ioconnect.c b/src/conn-tools/s6-ioconnect.c @@ -106,6 +106,7 @@ int main (int argc, char const *const *argv) if (!iobuffer_init(&b[i], a[i][0].fd, a[i][1].fd)) strerr_diefu1sys(111, "iobuffer_init") ; } if (sig_ignore(SIGPIPE) == -1) strerr_diefu1sys(111, "sig_ignore") ; + tain_now_set_stopwatch() ; tain_now_g() ; x[0].fd = selfpipe_init() ; if (x[0].fd < 0) strerr_diefu1sys(111, "selfpipe_init") ; diff --git a/src/conn-tools/s6-sudoc.c b/src/conn-tools/s6-sudoc.c @@ -53,6 +53,7 @@ int main (int argc, char const *const *argv, char const *const *envp) if (!fd_sanitize() || !fd_ensure_open(2, 1)) strerr_diefu1sys(111, "sanitize stdin/stdout/stderr") ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &deadline) ; { diff --git a/src/conn-tools/s6-sudod.c b/src/conn-tools/s6-sudod.c @@ -55,6 +55,7 @@ int main (int argc, char const *const *argv, char const *const *envp) if ((ndelay_on(0) < 0) || (ndelay_on(1) < 0)) strerr_diefu1sys(111, "make socket non-blocking") ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &deadline) ; buffer_putnoflush(buffer_1small, S6_SUDO_BANNERB, S6_SUDO_BANNERB_LEN) ; diff --git a/src/daemontools-extras/s6-log.c b/src/daemontools-extras/s6-log.c @@ -898,18 +898,23 @@ static void script_run (scriptelem_t const *script, unsigned int scriptlen, char size_t hlen = 0 ; char hstamp[32] ; char tstamp[TIMESTAMP+1] ; - if (gflags & 1) + if (gflags & 3) { - timestamp_g(tstamp) ; - tstamp[TIMESTAMP] = ' ' ; - } - if (gflags & 2) - { - localtmn_t l ; - localtmn_from_tain_g(&l, 1) ; - hlen = localtmn_fmt(hstamp, &l) ; - hstamp[hlen++] = ' ' ; - hstamp[hlen++] = ' ' ; + tain_t now ; + tain_wallclock_read(&now) ; + if (gflags & 1) + { + timestamp_fmt(tstamp, &now) ; + tstamp[TIMESTAMP] = ' ' ; + } + if (gflags & 2) + { + localtmn_t l ; + localtmn_from_tain(&l, &now, 1) ; + hlen = localtmn_fmt(hstamp, &l) ; + hstamp[hlen++] = ' ' ; + hstamp[hlen++] = ' ' ; + } } for (; i < scriptlen ; i++) @@ -1179,6 +1184,7 @@ int main (int argc, char const *const *argv) if (linelimit && linelimit < LINELIMIT_MIN) linelimit = LINELIMIT_MIN ; if (compat_gflags && verbosity) strerr_warnw1x("options -t and -e are deprecated") ; if (!fd_sanitize()) strerr_diefu1sys(111, "ensure stdin/stdout/stderr are open") ; + tain_now_set_stopwatch() ; /* only for timeouts; wallclock is used for timestamping */ if (!tain_now_g() && verbosity) strerr_warnwu1sys("read current time - timestamps may be wrong for a while") ; if (ndelay_on(0) < 0) strerr_diefu3sys(111, "set std", "in", " non-blocking") ; if (ndelay_on(1) < 0) strerr_diefu3sys(111, "set std", "out", " non-blocking") ; diff --git a/src/daemontools-extras/s6-setlock.c b/src/daemontools-extras/s6-setlock.c @@ -57,6 +57,7 @@ int main (int argc, char const *const *argv, char const *const *envp) int p[2] = { 0, 1 } ; pid_t pid ; char c ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_from_millisecs(&deadline, timeout) ; tain_add_g(&deadline, &deadline) ; diff --git a/src/fdholder/s6-fdholder-delete.c b/src/fdholder/s6-fdholder-delete.c @@ -32,6 +32,7 @@ int main (int argc, char const *const *argv) else deadline = tain_infinite_relative ; } if (argc < 2) dieusage() ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &deadline) ; if (!s6_fdholder_start_g(&a, argv[0], &deadline)) diff --git a/src/fdholder/s6-fdholder-getdump.c b/src/fdholder/s6-fdholder-getdump.c @@ -39,6 +39,7 @@ int main (int argc, char const *const *argv, char const *const *envp) } if (argc < 2) dieusage() ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &deadline) ; if (!s6_fdholder_start_g(&a, argv[0], &deadline)) diff --git a/src/fdholder/s6-fdholder-list.c b/src/fdholder/s6-fdholder-list.c @@ -40,6 +40,7 @@ int main (int argc, char const *const *argv) } if (!argc) dieusage() ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &deadline) ; if (!s6_fdholder_start_g(&a, argv[0], &deadline)) diff --git a/src/fdholder/s6-fdholder-retrieve.c b/src/fdholder/s6-fdholder-retrieve.c @@ -37,6 +37,7 @@ int main (int argc, char const *const *argv, char const *const *envp) } if (argc < 3) dieusage() ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &deadline) ; if (!s6_fdholder_start_g(&a, argv[0], &deadline)) diff --git a/src/fdholder/s6-fdholder-setdump.c b/src/fdholder/s6-fdholder-setdump.c @@ -40,6 +40,7 @@ int main (int argc, char const *const *argv) x = getenv("S6_FD#") ; if (!x) strerr_dienotset(100, "S6_FD#") ; if (!uint0_scan(x, &dumplen)) strerr_dieinvalid(100, "S6_FD#") ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &deadline) ; if (!s6_fdholder_start_g(&a, argv[0], &deadline)) diff --git a/src/fdholder/s6-fdholder-store.c b/src/fdholder/s6-fdholder-store.c @@ -38,6 +38,7 @@ int main (int argc, char const *const *argv) } if (argc < 2) dieusage() ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &deadline) ; tain_add_g(&limit, &limit) ; diff --git a/src/fdholder/s6-fdholder-transferdump.c b/src/fdholder/s6-fdholder-transferdump.c @@ -53,6 +53,7 @@ int main (int argc, char const *const *argv) } if (argc < 2) dieusage() ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &deadline) ; if (!s6_fdholder_start_g(&a, argv[0], &deadline)) diff --git a/src/fdholder/s6-fdholderd.c b/src/fdholder/s6-fdholderd.c @@ -762,6 +762,9 @@ int main (int argc, char const *const *argv, char const *const *envp) fd_write(1, "\n", 1) ; fd_close(1) ; } + + /* We are long-lived and have to check absolute fd deadlines, + so we purposefully remain in wallclock mode. */ tain_now_g() ; for (;;) diff --git a/src/libs6/s6-ftrigrd.c b/src/libs6/s6-ftrigrd.c @@ -201,6 +201,7 @@ int main (void) { tain_t deadline ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_addsec_g(&deadline, 2) ; if (!textclient_server_01x_init_g(FTRIGR_BANNER1, FTRIGR_BANNER1_LEN, FTRIGR_BANNER2, FTRIGR_BANNER2_LEN, &deadline)) diff --git a/src/libs6/s6lockd.c b/src/libs6/s6lockd.c @@ -203,7 +203,8 @@ int main (int argc, char const *const *argv) if (selfpipe_trapset(&set) < 0) strerr_diefu1sys(111, "trap signals") ; } - + + tain_now_set_stopwatch() ; tain_now_g() ; tain_addsec_g(&deadline, 2) ; diff --git a/src/pipe-tools/s6-ftrig-listen.c b/src/pipe-tools/s6-ftrig-listen.c @@ -59,6 +59,7 @@ int main (int argc, char const **argv, char const *const *envp) argc1 = el_semicolon(argv) ; if (!argc1 || (argc1 & 1) || (argc == argc1 + 1)) dieusage() ; if (argc1 >= argc) strerr_dief1x(100, "unterminated fifodir+regex block") ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &tto) ; x[0].fd = selfpipe_init() ; diff --git a/src/pipe-tools/s6-ftrig-listen1.c b/src/pipe-tools/s6-ftrig-listen1.c @@ -55,6 +55,7 @@ int main (int argc, char const *const *argv, char const *const *envp) } if (argc < 3) strerr_dieusage(100, USAGE) ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &tto) ; diff --git a/src/pipe-tools/s6-ftrig-wait.c b/src/pipe-tools/s6-ftrig-wait.c @@ -36,6 +36,7 @@ int main (int argc, char const *const *argv) } if (argc < 2) strerr_dieusage(100, USAGE) ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &tto) ; diff --git a/src/supervision/s6-notifyoncheck.c b/src/supervision/s6-notifyoncheck.c @@ -140,6 +140,7 @@ int main (int argc, char const *const *argv, char const *const *envp) if (fcntl(fd, F_GETFD) < 0) strerr_dief2sys(111, "notification-fd", " sanity check failed") ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&globaldeadline, &globaldeadline) ; diff --git a/src/supervision/s6-permafailon.c b/src/supervision/s6-permafailon.c @@ -95,7 +95,7 @@ int main (int argc, char const *const *argv, char const *const *envp) tain_uint(&mintime, seconds) ; { tain_t now ; - tain_now(&now) ; + tain_wallclock_read(&now) ; tain_sub(&mintime, &now, &mintime) ; } diff --git a/src/supervision/s6-supervise.c b/src/supervision/s6-supervise.c @@ -109,7 +109,7 @@ static void set_down_and_ready (char const *s, unsigned int n) status.pid = 0 ; status.flagfinishing = 0 ; status.flagready = 1 ; - tain_copynow(&status.readystamp) ; + tain_wallclock_read(&status.readystamp) ; state = DOWN ; if (tain_future(&dontrespawnbefore)) deadline = dontrespawnbefore ; else tain_copynow(&deadline) ; @@ -310,7 +310,7 @@ static void trystart (void) state = UP ; status.pid = pid ; status.flagready = 0 ; - tain_copynow(&status.stamp) ; + tain_wallclock_read(&status.stamp) ; tain_addsec_g(&dontrespawnbefore, 1) ; announce() ; ftrigw_notifyb_nosig(S6_SUPERVISE_EVENTDIR, "u", 1) ; @@ -354,7 +354,7 @@ static int uplastup_z (void) status.flagready = 0 ; status.flagthrottled = 0 ; flagdying = 0 ; - tain_copynow(&status.stamp) ; + tain_wallclock_read(&status.stamp) ; if (notifyfd >= 0) { fd_close(notifyfd) ; @@ -559,7 +559,7 @@ static inline void handle_notifyfd (void) r = sanitize_read(fd_read(notifyfd, buf, 4096)) ; if (r > 0 && memchr(buf, '\n', r)) { - tain_copynow(&status.readystamp) ; + tain_wallclock_read(&status.readystamp) ; status.flagready = 1 ; announce() ; ftrigw_notifyb_nosig(S6_SUPERVISE_EVENTDIR, "U", 1) ; @@ -669,9 +669,10 @@ int main (int argc, char const *const *argv) else if (errno != ENOENT) strerr_diefu1sys(111, "access ./down") ; + tain_now_set_stopwatch() ; tain_now_g() ; settimeout(0) ; - tain_copynow(&status.stamp) ; + tain_wallclock_read(&status.stamp) ; status.readystamp = status.stamp ; announce() ; ftrigw_notifyb_nosig(S6_SUPERVISE_EVENTDIR, "s", 1) ; diff --git a/src/supervision/s6-svlisten.c b/src/supervision/s6-svlisten.c @@ -56,6 +56,7 @@ int main (int argc, char const **argv, char const *const *envp) strerr_warnw3x("-o is unsupported when combined with -", wantready ? "R" : "r", "- using -a instead") ; } + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &tto) ; spfd = s6_svlisten_selfpipe_init() ; diff --git a/src/supervision/s6-svlisten1.c b/src/supervision/s6-svlisten1.c @@ -45,6 +45,7 @@ int main (int argc, char const *const *argv, char const *const *envp) if (t) tain_from_millisecs(&tto, t) ; else tto = tain_infinite_relative ; } if (argc < 2) dieusage() ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &tto) ; spfd = s6_svlisten_selfpipe_init() ; diff --git a/src/supervision/s6-svscan.c b/src/supervision/s6-svscan.c @@ -520,6 +520,7 @@ int main (int argc, char const *const *argv) { struct svinfo_s blob[max] ; /* careful with that stack, Eugene */ services = blob ; + tain_now_set_stopwatch() ; /* now try a backwards clock jump, bitch */ tain_now_g() ; diff --git a/src/supervision/s6-svstat.c b/src/supervision/s6-svstat.c @@ -274,7 +274,7 @@ int main (int argc, char const *const *argv) if (!s6_svstatus_read(argv[0], &status)) strerr_diefu2sys(111, "read status for ", argv[0]) ; - tain_now_g() ; + tain_wallclock_read_g() ; if (tain_future(&status.stamp)) tain_copynow(&status.stamp) ; { diff --git a/src/supervision/s6-svwait.c b/src/supervision/s6-svwait.c @@ -41,6 +41,7 @@ int main (int argc, char const *const *argv) } if (!argc) dieusage() ; + tain_now_set_stopwatch() ; tain_now_g() ; tain_add_g(&deadline, &tto) ;