summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-07-23 23:24:43 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-07-23 23:24:43 +0000
commit37868cbc2525294d0ec7cd77be02e144080eeffa (patch)
treec9e82e55bc01265ce9f4141a722df0ad2ad423ca /src
parent1c338ec2f260b09d1085c13615b3ea9f8ec02d24 (diff)
downloads6-rc-37868cbc2525294d0ec7cd77be02e144080eeffa.tar.xz
- timeout-finish support in s6-rc-compile
- global timeout propagation to subprocesses in s6-rc
Diffstat (limited to 'src')
-rw-r--r--src/s6-rc/s6-rc-compile.c9
-rw-r--r--src/s6-rc/s6-rc-update.c18
-rw-r--r--src/s6-rc/s6-rc.c17
3 files changed, 37 insertions, 7 deletions
diff --git a/src/s6-rc/s6-rc-compile.c b/src/s6-rc/s6-rc-compile.c
index a16f311..1126967 100644
--- a/src/s6-rc/s6-rc-compile.c
+++ b/src/s6-rc/s6-rc-compile.c
@@ -1005,11 +1005,14 @@ static void write_servicedir (char const *compiled, char const *srcdir, char con
byte_copy(dstfn + clen + 14 + dstlen, 7, "finish") ;
byte_copy(srcfn + srcdirlen + srclen + 2, 7, "finish") ;
filecopy(srcfn, dstfn, 0755) ;
+ byte_copy(dstfn + clen + 14 + dstlen, 15, "timeout-finish") ;
+ byte_copy(srcfn + srcdirlen + srclen + 2, 15, "timeout-finish") ;
+ filecopy(srcfn, dstfn, 0644) ;
byte_copy(dstfn + clen + 14 + dstlen, 16, "notification-fd") ;
byte_copy(srcfn + srcdirlen + srclen + 2, 16, "notification-fd") ;
- filecopy(srcfn, dstfn, 0755) ;
+ filecopy(srcfn, dstfn, 0644) ;
- byte_copy(srcfn + srcdirlen + srclen + 2, 9, "nosetsid") ;
+ byte_copy(srcfn + srcdirlen + srclen + 4, 7, "setsid") ;
if (stat(srcfn, &st) < 0)
{
if (errno != ENOENT)
@@ -1021,7 +1024,7 @@ static void write_servicedir (char const *compiled, char const *srcdir, char con
else
{
int fd ;
- byte_copy(dstfn + clen + 14 + dstlen, 9, "nosetsid") ;
+ byte_copy(dstfn + clen + 16 + dstlen, 7, "setsid") ;
fd = open_trunc(dstfn) ;
if (fd < 0)
{
diff --git a/src/s6-rc/s6-rc-update.c b/src/s6-rc/s6-rc-update.c
index a146c99..7e9af38 100644
--- a/src/s6-rc/s6-rc-update.c
+++ b/src/s6-rc/s6-rc-update.c
@@ -6,12 +6,15 @@
#include <skalibs/bytestr.h>
#include <skalibs/sgetopt.h>
#include <skalibs/strerr2.h>
+#include <skalibs/stralloc.h>
#include <skalibs/djbunix.h>
+#include <skalibs/skamisc.h>
#include <s6/s6-supervise.h>
#include <s6-rc/s6rc-constants.h>
#define USAGE "s6-rc-update [ -l live ]"
#define dieusage() strerr_dieusage(100, USAGE)
+#define dienomem() strerr_diefu1sys(111, "build string") ;
static char const *live = S6RC_LIVE_BASE ;
@@ -80,9 +83,9 @@ static int safe_servicedir_update (char const *dst, char const *src, int h)
s6_svc_write(dstfn, "u", 1) ;
}
byte_copy(dstfn + dstlen + 1, 9, "data.old") ;
- rm_rf(dstfn) ;
+ if (rm_rf(dstfn) < 0) strerr_warnwu2sys("remove ", dstfn) ;
byte_copy(dstfn + dstlen + 1, 8, "env.old") ;
- rm_rf(dstfn) ;
+ if (rm_rf(dstfn) < 0) strerr_warnwu2sys("remove ", dstfn) ;
return 1 ;
err:
@@ -98,6 +101,17 @@ static int safe_servicedir_update (char const *dst, char const *src, int h)
static int servicedir_name_change (char const *live, char const *oldname, char const *newname)
{
+ unsigned int livelen = str_len(live) ;
+ unsigned int oldlen = str_len(oldname) ;
+ unsigned int newlen = str_len(oldname) ;
+ char oldfn[livelen + oldlen + 2] ;
+ char newfn[livelen + newlen + 2] ;
+ byte_copy(oldfn, livelen, live) ;
+ oldfn[livelen] = '/' ;
+ byte_copy(oldfn + livelen + 1, oldlen + 1, oldname) ;
+ byte_copy(newfn, livelen + 1, oldfn) ;
+ byte_copy(newfn + livelen + 1, newlen + 1, newname) ;
+ if (rename(oldfn, newfn) < 0) return 0 ;
return 1 ;
}
diff --git a/src/s6-rc/s6-rc.c b/src/s6-rc/s6-rc.c
index 82b4685..1f1ab3f 100644
--- a/src/s6-rc/s6-rc.c
+++ b/src/s6-rc/s6-rc.c
@@ -71,6 +71,19 @@ static void print_services (void)
strerr_diefu1sys(111, "write to stdout") ;
}
+static unsigned int compute_timeout (unsigned int i, int h)
+{
+ unsigned int t = db->services[i].timeout[h] ;
+ int globalt ;
+ tain_t globaltto ;
+ tain_sub(&globaltto, &deadline, &STAMP) ;
+ globalt = tain_to_millisecs(&globaltto) ;
+ if (!globalt) globalt = 1 ;
+ if (globalt > 0 && (!t || (unsigned int)globalt < t))
+ t = (unsigned int)globalt ;
+ return t ;
+}
+
static pid_t start_oneshot (unsigned int i, int h)
{
unsigned int argc = db->services[i].x.oneshot.argc[h] ;
@@ -82,7 +95,7 @@ static pid_t start_oneshot (unsigned int i, int h)
char socketfn[livelen + S6RC_ONESHOT_RUNNER_LEN + 12] ;
byte_copy(socketfn, livelen, live) ;
byte_copy(socketfn + livelen, 12 + S6RC_ONESHOT_RUNNER_LEN, "/scandir/" S6RC_ONESHOT_RUNNER "/s") ;
- fmt[uint32_fmt(fmt, db->services[i].timeout[h])] = 0 ;
+ fmt[uint32_fmt(fmt, compute_timeout(i, h))] = 0 ;
vfmt[uint_fmt(vfmt, verbosity)] = 0 ;
if (dryrun[0])
{
@@ -128,7 +141,7 @@ static pid_t start_longrun (unsigned int i, int h)
}
}
servicefn[livelen + 9 + svdlen] = 0 ;
- fmt[uint32_fmt(fmt, db->services[i].timeout[h])] = 0 ;
+ fmt[uint32_fmt(fmt, compute_timeout(i, h))] = 0 ;
vfmt[uint_fmt(vfmt, verbosity)] = 0 ;
if (dryrun[0])
{