From 543c1405653c48d23e19d03d7c62e9534fc9a110 Mon Sep 17 00:00:00 2001
From: Laurent Bercot
Date: Thu, 23 Mar 2017 14:34:16 +0000
Subject: Don't wait on locks by default (fail instead); add a -b option to
get the waiting behaviour
Also fix a few types in s6-rc-compile (unsigned int -> uint32_t for avltree indices)
---
doc/s6-rc-bundle.html | 11 +++++--
doc/s6-rc-compile.html | 7 ++++-
doc/s6-rc-db.html | 27 ++++++++++-------
doc/s6-rc-fdholder-filler.html | 7 +++--
doc/s6-rc-init.html | 7 ++++-
doc/s6-rc-oneshot-run.html | 7 ++++-
doc/s6-rc-update.html | 7 ++++-
doc/s6-rc.html | 23 +++++++++++----
src/include/s6-rc/s6rc-utils.h | 2 +-
src/libs6rc/s6rc_lock.c | 16 ++++++++--
src/s6-rc/s6-rc-bundle.c | 8 +++--
src/s6-rc/s6-rc-compile.c | 66 +++++++++++++++++++++---------------------
src/s6-rc/s6-rc-db.c | 8 +++--
src/s6-rc/s6-rc-init.c | 8 +++--
src/s6-rc/s6-rc-oneshot-run.c | 8 +++--
src/s6-rc/s6-rc-update.c | 10 ++++---
src/s6-rc/s6-rc.c | 9 +++---
17 files changed, 148 insertions(+), 83 deletions(-)
diff --git a/doc/s6-rc-bundle.html b/doc/s6-rc-bundle.html
index 7647006..4bae71a 100644
--- a/doc/s6-rc-bundle.html
+++ b/doc/s6-rc-bundle.html
@@ -36,9 +36,9 @@ operation.
s6-rc-bundle help
- s6-rc-bundle [ -f ] [ -l live ] [ -c compiled ] add bundlename contents...
- s6-rc-bundle [ -f ] [ -l live ] [ -c compiled ] delete bundlenames...
- s6-rc-bundle [ -f ] [ -l live ] [ -c compiled ] multiple args...
+ s6-rc-bundle [ -f ] [ -l live ] [ -c compiled ] [ -b ] add bundlename contents...
+ s6-rc-bundle [ -f ] [ -l live ] [ -c compiled ] [ -b ] delete bundlenames...
+ s6-rc-bundle [ -f ] [ -l live ] [ -c compiled ] [ -b ] multiple args...
@@ -66,6 +66,11 @@ when given a nonexisting name to delete (it will do nothing), or
when given an existing name to add (it will replace the definition).
By default, s6-rc-bundle will complain and exit when asked to delete a
nonexistent name or to add an existing name.
+ - -b : blocking lock. If the database is currently
+being used by another program, s6-rc-bundle will wait until that
+other program has released its lock on the database, then proceed.
+By default, s6-rc-bundle fails with an error message if the database
+is currently in use.
Exit codes
diff --git a/doc/s6-rc-compile.html b/doc/s6-rc-compile.html
index 61f6dd2..cfacde1 100644
--- a/doc/s6-rc-compile.html
+++ b/doc/s6-rc-compile.html
@@ -36,7 +36,7 @@ the current service database via
Interface
- s6-rc-compile [ -v verbosity ] [ -u uids ] [ -g gids ] [ -h fdhuser ] compiled source...
+ s6-rc-compile [ -v verbosity ] [ -u uids ] [ -g gids ] [ -h fdhuser ] [ -b ] compiled source...
@@ -77,6 +77,11 @@ numerical GIDs.
program, which maintains the pipes for the longrun pipelines, to run
as user fdhuser. By default, it runs as the user owning
the supervision tree, i.e. most likely root.
+ - -b : make
+s6-rc-oneshot-runner
+invocations wait instead of fail on lock contention. This
+should not change anything in practice, and you can ignore
+that option.
diff --git a/doc/s6-rc-db.html b/doc/s6-rc-db.html
index a9d8b9d..5c664f5 100644
--- a/doc/s6-rc-db.html
+++ b/doc/s6-rc-db.html
@@ -37,17 +37,17 @@ operation.
s6-rc-db help
- s6-rc-db [ -l live ] [ -c compiled ] check
- s6-rc-db [ -l live ] [ -c compiled ] list all|services|oneshots|longruns|bundles
- s6-rc-db [ -l live ] [ -c compiled ] type servicename
- s6-rc-db [ -l live ] [ -c compiled ] [ -u | -d ] timeout atomicname
- s6-rc-db [ -l live ] [ -c compiled ] contents bundlename
- s6-rc-db [ -l live ] [ -c compiled ] [ -u | -d ] dependencies servicename
- s6-rc-db [ -l live ] [ -c compiled ] pipeline longrunname
- s6-rc-db [ -l live ] [ -c compiled ] [ -u | -d ] script oneshotname
- s6-rc-db [ -l live ] [ -c compiled ] flags atomicname
- s6-rc-db [ -l live ] [ -c compiled ] atomics servicename...
- s6-rc-db [ -l live ] [ -c compiled ] [ -u | -d ] all-dependencies servicename...
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] check
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] list all|services|oneshots|longruns|bundles
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] type servicename
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] [ -u | -d ] timeout atomicname
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] contents bundlename
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] [ -u | -d ] dependencies servicename
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] pipeline longrunname
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] [ -u | -d ] script oneshotname
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] flags atomicname
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] atomics servicename...
+ s6-rc-db [ -l live ] [ -c compiled ] [ -b ] [ -u | -d ] all-dependencies servicename...
@@ -78,6 +78,11 @@ ignored when it is irrelevant.
- -d : for commands that use different data
depending on whether it's about bringing the service up or down,
select the "down" data. This option is ignored when it is irrelevant.
+ - -b : blocking lock. If the database is currently
+being used by another program, s6-rc-db will wait until that
+other program has released its lock on the database, then proceed.
+By default, s6-rc-db fails with an error message if the database
+is currently in use.
Exit codes
diff --git a/doc/s6-rc-fdholder-filler.html b/doc/s6-rc-fdholder-filler.html
index 83132fd..a835663 100644
--- a/doc/s6-rc-fdholder-filler.html
+++ b/doc/s6-rc-fdholder-filler.html
@@ -34,7 +34,7 @@ in internal scripts created by
Interface
- s6-rc-fdholder-filler [ -1 ] [ -t timeout ] longrunnames...
+ s6-rc-fdholder-filler [ -1 ] [ -t timeout ] < longrunnamesfile
Typical usage
diff --git a/doc/s6-rc-oneshot-run.html b/doc/s6-rc-oneshot-run.html
index 351e9e1..8cddcb5 100644
--- a/doc/s6-rc-oneshot-run.html
+++ b/doc/s6-rc-oneshot-run.html
@@ -33,7 +33,7 @@ in internal scripts created by
Interface
- s6-rc-oneshot-run [ -l live ] up|down n
+ s6-rc-oneshot-run [ -l live ] [ -b ] up|down n
@@ -49,6 +49,11 @@ live directory).
- -l live : use the live directory in
live. Default is /run/s6-rc, or what was given to the
--livedir configure option at compile time.
+ - -b : blocking lock. If the service database is currently
+being used by another program, s6-rc-oneshot-run will wait until that
+other program has released its lock on the database, then proceed.
+By default, s6-rc-oneshot-run fails with an error message if the database
+is currently in use.
Exit codes
diff --git a/doc/s6-rc-update.html b/doc/s6-rc-update.html
index e424f98..52ab42d 100644
--- a/doc/s6-rc-update.html
+++ b/doc/s6-rc-update.html
@@ -38,7 +38,7 @@ situations it cannot solve.
Interface
- s6-rc-update [ -n ] [ -v verbosity ] [ -t timeout ] [ -l live ] [ -f convfile ] newdb
+ s6-rc-update [ -n ] [ -v verbosity ] [ -t timeout ] [ -l live ] [ -f convfile ] [ -b ] newdb
@@ -95,6 +95,11 @@ The default can be changed at compile-time by giving the
- -f convfile : use the conversion
file located at convfile. Default is /dev/null,
meaning no special instructions.
+ - -b : blocking lock. If the database is currently
+being used by another program, s6-rc-update will wait until that
+other program has released its lock on the database, then proceed.
+By default, s6-rc-update fails with an error message if the database
+is currently in use.
Transition details
diff --git a/doc/s6-rc.html b/doc/s6-rc.html
index 5e851d3..a6e64d9 100644
--- a/doc/s6-rc.html
+++ b/doc/s6-rc.html
@@ -44,9 +44,9 @@ especially when asking for a state change.
s6-rc help
- s6-rc [ -l live ] [ -a ] [ -u | -d ] list servicenames...
- s6-rc [ -l live ] [ -a ] [ -u | -d ] listall servicenames...
- s6-rc [ -l live ] [ -a ] [ -u | -d ] [ -p ] [ -v verbosity ] [ -n dryrunthrottle ] [ -t timeout ] change [ servicenames... ]
+ s6-rc [ -l live ] [ -b ] [ -a ] [ -u | -d ] list servicenames...
+ s6-rc [ -l live ] [ -b ] [ -a ] [ -u | -d ] listall servicenames...
+ s6-rc [ -l live ] [ -b ] [ -a ] [ -u | -d ] [ -p ] [ -v verbosity ] [ -n dryrunthrottle ] [ -t timeout ] change [ servicenames... ]
@@ -95,6 +95,14 @@ giving the --livedir=live option to ./configure. s6-rc -da change
will stop all services.
+ - -b : blocking lock. If the service database is currently
+being used by another program, s6-rc will wait until that
+other program has released its lock on the database, then proceed.
+By default, s6-rc fails with an error message if the service database
+is currently in use. The default is the safe behaviour: for instance,
+it will correctly detect and fail nested s6-rc invocations (which are
+an admin error), whereas s6-rc -b would deadlock in
+such a case.
Up or down
@@ -310,10 +318,13 @@ milliseconds to complete successfully.
bringing up all its dependencies first (recursively).
- s6-rc -ad change
+ s6-rc -bad change
- Brings down all the currently running services in an orderly manner.
-This is typically run at shutdown time.
+ Waits for any pending program of the s6-rc family to stop using
+the live database and current compiled service database, then
+brings down all the currently running services in an orderly manner.
+This is typically run at shutdown time. (And it's not necessarily
+a bad change!)
s6-rc -l /zork -ua listall myservicebundle
diff --git a/src/include/s6-rc/s6rc-utils.h b/src/include/s6-rc/s6rc-utils.h
index 4eb65f5..22d8324 100644
--- a/src/include/s6-rc/s6rc-utils.h
+++ b/src/include/s6-rc/s6rc-utils.h
@@ -8,7 +8,7 @@
#include
extern void s6rc_graph_closure (s6rc_db_t const *, unsigned char *, unsigned int, int) ;
-extern int s6rc_lock (char const *, int, int *, char const *, int, int *) ;
+extern int s6rc_lock (char const *, int, int *, char const *, int, int *, int) ;
extern int s6rc_read_uint (char const *, unsigned int *) ;
extern int s6rc_sanitize_dir (stralloc *, char const *, size_t *) ;
diff --git a/src/libs6rc/s6rc_lock.c b/src/libs6rc/s6rc_lock.c
index dab3035..2a623d0 100644
--- a/src/libs6rc/s6rc_lock.c
+++ b/src/libs6rc/s6rc_lock.c
@@ -5,7 +5,17 @@
#include
#include
-int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int cwhat, int *ccfd)
+static inline int lockex (int fd, int blocking)
+{
+ return blocking ? lock_ex(fd) : lock_exnb(fd) ;
+}
+
+static inline int locksh (int fd, int blocking)
+{
+ return blocking ? lock_sh(fd) : lock_shnb(fd) ;
+}
+
+int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int cwhat, int *ccfd, int blocking)
{
int e = 0 ;
int lfd = -1, cfd = -1 ;
@@ -18,7 +28,7 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int
memcpy(lfn + llen, "/lock", 6) ;
lfd = open_create(lfn) ;
if (lfd < 0) return 0 ;
- if ((lwhat > 1 ? lock_ex(lfd) : lock_sh(lfd)) < 0) { e = errno ; goto lerr ; }
+ if ((lwhat > 1 ? lockex(lfd, blocking) : locksh(lfd, blocking)) < 0) { e = errno ; goto lerr ; }
}
if (cwhat)
@@ -31,7 +41,7 @@ int s6rc_lock (char const *live, int lwhat, int *llfd, char const *compiled, int
if (cfd < 0)
if (cwhat > 1 || errno != EROFS) { e = errno ; goto lerr ; }
else cfd = -errno ;
- else if ((cwhat > 1 ? lock_ex(cfd) : lock_sh(cfd)) < 0) { e = errno ; goto cerr ; }
+ else if ((cwhat > 1 ? lockex(cfd, blocking) : locksh(cfd, blocking)) < 0) { e = errno ; goto cerr ; }
}
if (lwhat) *llfd = lfd ;
diff --git a/src/s6-rc/s6-rc-bundle.c b/src/s6-rc/s6-rc-bundle.c
index 78bfcbe..837d3b9 100644
--- a/src/s6-rc/s6-rc-bundle.c
+++ b/src/s6-rc/s6-rc-bundle.c
@@ -18,7 +18,7 @@
#include
#include
-#define USAGE "s6-rc-bundle [ -l live ] [ -c compiled ] command... (use s6-rc-bundle help for more information)"
+#define USAGE "s6-rc-bundle [ -l live ] [ -c compiled ] [ -b ] command... (use s6-rc-bundle help for more information)"
#define dieusage() strerr_dieusage(100, USAGE)
static void cleanup (char const *compiled)
@@ -259,18 +259,20 @@ int main (int argc, char const **argv)
char const *compiled = 0 ;
unsigned int what ;
int force = 0 ;
+ int blocking = 0 ;
PROG = "s6-rc-bundle" ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "fl:c:", &l) ;
+ int opt = subgetopt_r(argc, argv, "fl:c:b", &l) ;
if (opt == -1) break ;
switch (opt)
{
case 'f' : force = 1 ; break ;
case 'l' : live = l.arg ; break ;
case 'c' : compiled = l.arg ; break ;
+ case 'b' : blocking = 1 ; break ;
default : dieusage() ;
}
}
@@ -301,7 +303,7 @@ int main (int argc, char const **argv)
compiled = compiledblob ;
}
- if (!s6rc_lock(0, 0, 0, compiled, 2, &compiledlock))
+ if (!s6rc_lock(0, 0, 0, compiled, 2, &compiledlock, blocking))
strerr_diefu2sys(111, "take lock on ", compiled) ;
fdcompiled = open_readb(compiled) ;
if (fdcompiled < 0)
diff --git a/src/s6-rc/s6-rc-compile.c b/src/s6-rc/s6-rc-compile.c
index fdf2602..60bae6b 100644
--- a/src/s6-rc/s6-rc-compile.c
+++ b/src/s6-rc/s6-rc-compile.c
@@ -26,22 +26,12 @@
#include
#include
-#define USAGE "s6-rc-compile [ -v verbosity ] [ -u okuid,okuid... ] [ -g okgid,okgid... ] [ -h fdholder_user ] destdir sources..."
+#define USAGE "s6-rc-compile [ -v verbosity ] [ -u okuid,okuid... ] [ -g okgid,okgid... ] [ -h fdholder_user ] [ -b ] destdir sources..."
#define dieusage() strerr_dieusage(100, USAGE)
#define dienomem() strerr_dief1x(111, "out of memory") ;
#define S6RC_INTERNALS "s6-rc-compile internals"
-#define S6RC_ONESHOT_RUNNER_RUNSCRIPT \
-"#!" EXECLINE_SHEBANGPREFIX "execlineb -P\n" \
-EXECLINE_EXTBINPREFIX "fdmove -c 2 1\n" \
-EXECLINE_EXTBINPREFIX "fdmove 1 3\n" \
-S6_EXTBINPREFIX "s6-ipcserver-socketbinder -- s\n" \
-S6_EXTBINPREFIX "s6-ipcserverd -1 --\n" \
-S6_EXTBINPREFIX "s6-ipcserver-access -v0 -E -l0 -i data/rules --\n" \
-S6_EXTBINPREFIX "s6-sudod -t 2000 --\n" \
-S6RC_EXTLIBEXECPREFIX "s6-rc-oneshot-run -l ../.. --\n"
-
static unsigned int verbosity = 1 ;
static stralloc keep = STRALLOC_ZERO ;
static stralloc data = STRALLOC_ZERO ;
@@ -56,7 +46,6 @@ enum servicetype_e
} ;
-
/* The names tree */
@@ -84,7 +73,6 @@ static genalloc nameinfo = GENALLOC_ZERO ; /* nameinfo_t */
static avltree names_map = AVLTREE_INIT(8, 3, 8, &names_dtok, &names_cmp, &nameinfo) ;
-
/* Services before resolution */
@@ -137,7 +125,6 @@ struct before_s
#define BEFORE_ZERO { .indices = GENALLOC_ZERO, .oneshots = GENALLOC_ZERO, .longruns = GENALLOC_ZERO, .bundles = GENALLOC_ZERO, .nargvs = 0, .specialdeps = { 0, 0 } } ;
-
/* Read all the sources, populate the name map */
@@ -151,8 +138,7 @@ static char const *typestr (servicetype_t type)
static int add_name_nocheck (before_t *be, char const *srcdir, char const *name, servicetype_t type, unsigned int *pos, unsigned int *kpos)
{
- unsigned int id ;
-
+ uint32_t id ;
if (verbosity >= 4)
strerr_warnt6x("from ", srcdir, ": adding identifier ", name, " of type ", typestr(type)) ;
@@ -211,7 +197,7 @@ static int add_name_nocheck (before_t *be, char const *srcdir, char const *name,
.type = type
} ;
size_t namelen = strlen(name) ;
- unsigned int i = genalloc_len(nameinfo_t, &nameinfo) ;
+ uint32_t i = genalloc_len(nameinfo_t, &nameinfo) ;
if (type == SVTYPE_ONESHOT || type == SVTYPE_LONGRUN)
if (!stralloc_catb(&keep, name, namelen + 1)) dienomem() ;
if (!stralloc_catb(&data, name, namelen + 1)) dienomem() ;
@@ -528,7 +514,7 @@ static inline void add_pipeline_bundles (before_t *be)
while (i--) if (longruns[i].pipelinename)
{
bundle_t bundle = { .listindex = genalloc_len(unsigned int, &be->indices), .n = 1 } ;
- unsigned int id ;
+ uint32_t id ;
nameinfo_t const *info ;
unsigned int j = i ;
if (verbosity >= 3) strerr_warni2x("creating bundle for pipeline ", data.s + longruns[i].pipelinename) ;
@@ -554,7 +540,6 @@ static inline void add_pipeline_bundles (before_t *be)
}
-
/* Resolve all names and dependencies */
@@ -584,7 +569,7 @@ static void resolve_bundle_rec (bundle_recinfo_t *recinfo, unsigned int i)
recinfo->mark[i] |= 1 ;
for (; j < me->n ; j++)
{
- unsigned int id ;
+ uint32_t id ;
nameinfo_t const *p ;
avltree_search(&names_map, data.s + listindex[j], &id) ;
p = genalloc_s(nameinfo_t, &nameinfo) + id ;
@@ -650,7 +635,7 @@ static void resolve_deps (common_t const *me, unsigned int nlong, unsigned int n
unsigned int j = 0 ;
for (; j < me->ndeps ; j++)
{
- unsigned int id ;
+ uint32_t id ;
nameinfo_t const *p ;
avltree_search(&names_map, data.s + indices[me->depindex + j], &id) ;
p = genalloc_s(nameinfo_t, &nameinfo) + id ;
@@ -691,7 +676,7 @@ static void resolve_deps (common_t const *me, unsigned int nlong, unsigned int n
static uint32_t resolve_prodcons (longrun_t const *longruns, unsigned int i, int h, uint32_t nlong)
{
- unsigned int j ;
+ uint32_t j ;
nameinfo_t const *p ;
if (!longruns[i].pipeline[h]) return nlong ;
avltree_search(&names_map, data.s + longruns[i].pipeline[h], &j) ;
@@ -700,7 +685,7 @@ static uint32_t resolve_prodcons (longrun_t const *longruns, unsigned int i, int
{
case SVTYPE_LONGRUN :
{
- unsigned int k ;
+ uint32_t k ;
nameinfo_t const *q ;
avltree_search(&names_map, data.s + longruns[p->i].pipeline[!h], &k) ;
q = genalloc_s(nameinfo_t, &nameinfo) + k ;
@@ -808,7 +793,6 @@ static inline void flatlist_services (s6rc_db_t *db, unsigned char const *sarray
}
-
/* Write the compiled database */
@@ -884,7 +868,7 @@ static inline void init_compiled (char const *compiled)
int compiledlock ;
if (mkdir(compiled, 0755) < 0)
strerr_diefu2sys(111, "mkdir ", compiled) ;
- if (!s6rc_lock(0, 0, 0, compiled, 2, &compiledlock))
+ if (!s6rc_lock(0, 0, 0, compiled, 2, &compiledlock, 0))
strerr_diefu2sys(111, "take lock on ", compiled) ;
auto_dir(compiled, "servicedirs") ;
}
@@ -926,8 +910,9 @@ static void make_skel (char const *compiled, char const *name, uid_t const *uids
auto_dir(compiled, fn) ;
}
-static inline void write_oneshot_runner (char const *compiled, uid_t const *uids, size_t uidn, gid_t const *gids, size_t gidn)
+static inline void write_oneshot_runner (char const *compiled, uid_t const *uids, size_t uidn, gid_t const *gids, size_t gidn, int blocking)
{
+ size_t base = satmp.len ;
size_t i ;
char fn[34 + sizeof(S6RC_ONESHOT_RUNNER)] = "servicedirs/" S6RC_ONESHOT_RUNNER "/data/rules/gid/" ;
make_skel(compiled, S6RC_ONESHOT_RUNNER, uids, uidn, gids, gidn, 3) ;
@@ -953,7 +938,19 @@ static inline void write_oneshot_runner (char const *compiled, uid_t const *uids
memcpy(fn + 28 + S6RC_ONESHOT_RUNNER_LEN + len, "/allow", 7) ;
auto_file(compiled, fn, "", 0) ;
}
- auto_file(compiled, "servicedirs/" S6RC_ONESHOT_RUNNER "/run", S6RC_ONESHOT_RUNNER_RUNSCRIPT, sizeof(S6RC_ONESHOT_RUNNER_RUNSCRIPT) - 1) ;
+ if (!stralloc_cats(&satmp, "#!"
+ EXECLINE_SHEBANGPREFIX "execlineb -P\n"
+ EXECLINE_EXTBINPREFIX "fdmove -c 2 1\n"
+ EXECLINE_EXTBINPREFIX "fdmove 1 3\n"
+ S6_EXTBINPREFIX "s6-ipcserver-socketbinder -- s\n"
+ S6_EXTBINPREFIX "s6-ipcserverd -1 --\n"
+ S6_EXTBINPREFIX "s6-ipcserver-access -v0 -E -l0 -i data/rules --\n"
+ S6_EXTBINPREFIX "s6-sudod -t 2000 --\n"
+ S6RC_EXTLIBEXECPREFIX "s6-rc-oneshot-run -l ../.. ")
+ || (blocking && !stralloc_cats(&satmp, "-b "))
+ || !stralloc_cats(&satmp, "--\n")) dienomem() ;
+ auto_file(compiled, "servicedirs/" S6RC_ONESHOT_RUNNER "/run", satmp.s + base, satmp.len - base) ;
+ satmp.len = base ;
auto_rights(compiled, "servicedirs/" S6RC_ONESHOT_RUNNER "/run", 0755) ;
}
@@ -1058,9 +1055,9 @@ static inline void write_fdholder (char const *compiled, s6rc_db_t const *db, ui
auto_rights(compiled, "servicedirs/" S6RC_FDHOLDER "/run", 0755) ;
}
-static inline void write_specials (char const *compiled, s6rc_db_t const *db, uid_t const *uids, size_t uidn, gid_t const *gids, size_t gidn, char const *fdhuser)
+static inline void write_specials (char const *compiled, s6rc_db_t const *db, uid_t const *uids, size_t uidn, gid_t const *gids, size_t gidn, char const *fdhuser, int blocking)
{
- write_oneshot_runner(compiled, uids, uidn, gids, gidn) ;
+ write_oneshot_runner(compiled, uids, uidn, gids, gidn, blocking) ;
write_fdholder(compiled, db, uids, uidn, gids, gidn, fdhuser) ;
}
@@ -1367,7 +1364,8 @@ static inline void write_compiled (
size_t uidn,
gid_t const *gids,
size_t gidn,
- char const *fdhuser)
+ char const *fdhuser,
+ int blocking)
{
if (verbosity >= 2) strerr_warni2x("writing compiled information to ", compiled) ;
init_compiled(compiled) ;
@@ -1375,7 +1373,7 @@ static inline void write_compiled (
write_resolve(compiled, db, bundles, nbundles, bdeps) ;
stralloc_free(&data) ;
write_db(compiled, db) ;
- write_specials(compiled, db, uids, uidn, gids, gidn, fdhuser) ;
+ write_specials(compiled, db, uids, uidn, gids, gidn, fdhuser, blocking) ;
write_servicedirs(compiled, db, srcdirs) ;
}
@@ -1384,6 +1382,7 @@ int main (int argc, char const *const *argv)
before_t before = BEFORE_ZERO ;
char const *compiled ;
char const *fdhuser = 0 ;
+ int blocking = 0 ;
size_t uidn = 0, gidn = 0 ;
uid_t uids[256] ;
gid_t gids[256] ;
@@ -1392,7 +1391,7 @@ int main (int argc, char const *const *argv)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "v:u:g:h:", &l) ;
+ int opt = subgetopt_r(argc, argv, "v:u:g:h:b", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -1400,6 +1399,7 @@ int main (int argc, char const *const *argv)
case 'u' : if (!uid_scanlist(uids, 255, l.arg, &uidn)) dieusage() ; break ;
case 'g' : if (!gid_scanlist(gids, 255, l.arg, &gidn)) dieusage() ; break ;
case 'h' : fdhuser = l.arg ; break ;
+ case 'b' : blocking = 1 ; break ;
default : dieusage() ;
}
}
@@ -1446,7 +1446,7 @@ int main (int argc, char const *const *argv)
uint32_t deps[db.ndeps << 1] ;
db.deps = deps ;
flatlist_services(&db, sarray) ;
- write_compiled(compiled, &db, srcdirs, bundles, nbundles, bdeps, uids, uidn, gids, gidn, fdhuser) ;
+ write_compiled(compiled, &db, srcdirs, bundles, nbundles, bdeps, uids, uidn, gids, gidn, fdhuser, blocking) ;
}
}
diff --git a/src/s6-rc/s6-rc-db.c b/src/s6-rc/s6-rc-db.c
index 8e4b92a..ce983dc 100644
--- a/src/s6-rc/s6-rc-db.c
+++ b/src/s6-rc/s6-rc-db.c
@@ -13,7 +13,7 @@
#include
#include
-#define USAGE "s6-rc-db [ -u | -d ] [ -l live ] [ -c compiled ] command... (use s6-rc-db help for more information)"
+#define USAGE "s6-rc-db [ -u | -d ] [ -l live ] [ -c compiled ] [ -b ] command... (use s6-rc-db help for more information)"
#define dieusage() strerr_dieusage(100, USAGE)
static char const *compiled = 0 ;
@@ -344,12 +344,13 @@ int main (int argc, char const *const *argv)
char const *live = S6RC_LIVE_BASE ;
unsigned int what, subwhat = 0 ;
int up = 1 ;
+ int blocking = 0 ;
PROG = "s6-rc-db" ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "udl:c:", &l) ;
+ int opt = subgetopt_r(argc, argv, "udl:c:b", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -357,6 +358,7 @@ int main (int argc, char const *const *argv)
case 'c' : compiled = l.arg ; break ;
case 'u' : up = 1 ; break ;
case 'd' : up = 0 ; break ;
+ case 'b' : blocking = 1 ; break ;
default : dieusage() ;
}
}
@@ -387,7 +389,7 @@ int main (int argc, char const *const *argv)
compiled = compiledblob ;
}
- if (!s6rc_lock(0, 0, 0, compiled, 1, &compiledlock))
+ if (!s6rc_lock(0, 0, 0, compiled, 1, &compiledlock, blocking))
strerr_diefu2sys(111, "take lock on ", compiled) ;
fdcompiled = open_readb(compiled) ;
if (fdcompiled < 0)
diff --git a/src/s6-rc/s6-rc-init.c b/src/s6-rc/s6-rc-init.c
index 386fbe7..c749609 100644
--- a/src/s6-rc/s6-rc-init.c
+++ b/src/s6-rc/s6-rc-init.c
@@ -14,7 +14,7 @@
#include
#include
-#define USAGE "s6-rc-init [ -c compiled ] [ -l live ] [ -t timeout ] scandir"
+#define USAGE "s6-rc-init [ -c compiled ] [ -l live ] [ -t timeout ] [ -b ] scandir"
#define dieusage() strerr_dieusage(100, USAGE)
#define dienomem() strerr_diefu1sys(111, "stralloc_catb")
@@ -37,19 +37,21 @@ int main (int argc, char const *const *argv)
size_t dirlen ;
char const *live = S6RC_LIVE_BASE ;
char const *compiled = S6RC_COMPILED_BASE ;
+ int blocking = 0 ;
PROG = "s6-rc-init" ;
{
unsigned int t = 0 ;
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "c:l:t:", &l) ;
+ int opt = subgetopt_r(argc, argv, "c:l:t:b", &l) ;
if (opt == -1) break ;
switch (opt)
{
case 'c' : compiled = l.arg ; break ;
case 'l' : live = l.arg ; break ;
case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ;
+ case 'b' : blocking = 1 ; break ;
default : dieusage() ;
}
}
@@ -89,7 +91,7 @@ int main (int argc, char const *const *argv)
unlink(live) ;
rm_rf(satmp.s) ;
if (mkdir(satmp.s, 0755) < 0) strerr_diefu2sys(111, "mkdir ", satmp.s) ;
- if (!s6rc_lock(satmp.s, 2, &fdlock, 0, 0, 0))
+ if (!s6rc_lock(satmp.s, 2, &fdlock, 0, 0, 0, blocking))
{
char tmp[satmp.len] ;
memcpy(tmp, satmp.s, satmp.len) ;
diff --git a/src/s6-rc/s6-rc-oneshot-run.c b/src/s6-rc/s6-rc-oneshot-run.c
index 3bb38a8..01e51ba 100644
--- a/src/s6-rc/s6-rc-oneshot-run.c
+++ b/src/s6-rc/s6-rc-oneshot-run.c
@@ -10,7 +10,7 @@
#include
#include
-#define USAGE "s6-rc-oneshot-run [ -l live ] up|down servicenumber"
+#define USAGE "s6-rc-oneshot-run [ -l live ] [ -b ] up|down servicenumber"
#define dieusage() strerr_dieusage(100, USAGE)
int main (int argc, char const *const *argv, char const *const *envp)
@@ -18,16 +18,18 @@ int main (int argc, char const *const *argv, char const *const *envp)
char const *live = S6RC_LIVE_BASE ;
unsigned int number ;
int up ;
+ int blocking = 0 ;
PROG = "s6-rc-oneshot-run" ;
{
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "l:", &l) ;
+ int opt = subgetopt_r(argc, argv, "l:b", &l) ;
if (opt == -1) break ;
switch (opt)
{
case 'l' : live = l.arg ; break ;
+ case 'b' : blocking = 1 ; break ;
default : dieusage() ;
}
}
@@ -48,7 +50,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
memcpy(compiled, live, livelen) ;
memcpy(compiled + livelen, "/compiled", 10) ;
- if (!s6rc_lock(0, 0, 0, compiled, 1, &compiledlock))
+ if (!s6rc_lock(0, 0, 0, compiled, 1, &compiledlock, blocking))
strerr_diefu2sys(111, "take lock on ", compiled) ;
fdcompiled = open_readb(compiled) ;
if (fdcompiled < 0)
diff --git a/src/s6-rc/s6-rc-update.c b/src/s6-rc/s6-rc-update.c
index 4008388..5f4d25e 100644
--- a/src/s6-rc/s6-rc-update.c
+++ b/src/s6-rc/s6-rc-update.c
@@ -27,7 +27,7 @@
#include
#include
-#define USAGE "s6-rc-update [ -n ] [ -v verbosity ] [ -t timeout ] [ -l live ] [ -f conversion_file ] newdb"
+#define USAGE "s6-rc-update [ -n ] [ -v verbosity ] [ -t timeout ] [ -l live ] [ -f conversion_file ] [ -b ] newdb"
#define dieusage() strerr_dieusage(100, USAGE)
#define dienomem() strerr_diefu1sys(111, "build string") ;
@@ -611,13 +611,14 @@ int main (int argc, char const *const *argv, char const *const *envp)
char const *convfile = "/dev/null" ;
tain_t deadline ;
int dryrun = 0 ;
+ int blocking = 0 ;
PROG = "s6-rc-update" ;
{
unsigned int t = 0 ;
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "v:t:nl:f:", &l) ;
+ int opt = subgetopt_r(argc, argv, "v:t:nl:f:b", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -626,6 +627,7 @@ int main (int argc, char const *const *argv, char const *const *envp)
case 'n' : dryrun = 1 ; break ;
case 'l' : live = l.arg ; break ;
case 'f' : convfile = l.arg ; break ;
+ case 'b' : blocking = 1 ; break ;
default : dieusage() ;
}
}
@@ -658,9 +660,9 @@ int main (int argc, char const *const *argv, char const *const *envp)
memcpy(dbfn, live, livelen) ;
memcpy(dbfn + livelen, "/compiled", 10) ;
- if (!s6rc_lock(live, 2, &livelock, dbfn, 1, &oldlock))
+ if (!s6rc_lock(live, 2, &livelock, dbfn, 1, &oldlock, blocking))
strerr_diefu4sys(111, "take lock on ", live, " and ", dbfn) ;
- if (!s6rc_lock(0, 0, 0, argv[0], 1, &newlock))
+ if (!s6rc_lock(0, 0, 0, argv[0], 1, &newlock, blocking))
strerr_diefu2sys(111, "take lock on ", argv[0]) ;
diff --git a/src/s6-rc/s6-rc.c b/src/s6-rc/s6-rc.c
index f81d38d..615cbf8 100644
--- a/src/s6-rc/s6-rc.c
+++ b/src/s6-rc/s6-rc.c
@@ -21,7 +21,7 @@
#include
#include
-#define USAGE "s6-rc [ -v verbosity ] [ -n dryrunthrottle ] [ -t timeout ] [ -l live ] [ -u | -d ] [ -p ] [ -a ] help|list|listall|change [ servicenames... ]"
+#define USAGE "s6-rc [ -v verbosity ] [ -n dryrunthrottle ] [ -t timeout ] [ -l live ] [ -b ] [ -u | -d ] [ -p ] [ -a ] help|list|listall|change [ servicenames... ]"
#define dieusage() strerr_dieusage(100, USAGE)
typedef struct pidindex_s pidindex_t ;
@@ -374,7 +374,7 @@ static inline void print_help (void)
int main (int argc, char const *const *argv)
{
- int up = 1, prune = 0, selectlive = 0, takelocks = 1 ;
+ int up = 1, prune = 0, selectlive = 0, takelocks = 1, blocking = 0 ;
unsigned int what ;
PROG = "s6-rc" ;
{
@@ -382,7 +382,7 @@ int main (int argc, char const *const *argv)
subgetopt_t l = SUBGETOPT_ZERO ;
for (;;)
{
- int opt = subgetopt_r(argc, argv, "v:n:t:l:udpaX", &l) ;
+ int opt = subgetopt_r(argc, argv, "v:n:t:l:udpaXb", &l) ;
if (opt == -1) break ;
switch (opt)
{
@@ -401,6 +401,7 @@ int main (int argc, char const *const *argv)
case 'p' : prune = 1 ; break ;
case 'a' : selectlive = 1 ; break ;
case 'X' : takelocks = 0 ; break ;
+ case 'b' : blocking = 1 ; break ;
default : dieusage() ;
}
}
@@ -432,7 +433,7 @@ int main (int argc, char const *const *argv)
if (takelocks)
{
int livelock, compiledlock ;
- if (!s6rc_lock(live, 1 + (what >= 3), &livelock, dbfn, 1, &compiledlock))
+ if (!s6rc_lock(live, 1 + (what >= 3), &livelock, dbfn, 1, &compiledlock, blocking))
strerr_diefu1sys(111, "take locks") ;
if (coe(livelock) < 0)
strerr_diefu3sys(111, "coe ", live, "/lock") ;
--
cgit v1.2.3