diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-05-16 14:25:30 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-05-16 14:25:30 +0000 |
commit | ee7925ff752efa272d335bca53240abca9256f6f (patch) | |
tree | 01fd1f6cec6c95427b313306906ee1bb8dd91c5c | |
parent | 9a81557a41d295f026ddb021090ddf18828e733a (diff) | |
download | s6-rc-ee7925ff752efa272d335bca53240abca9256f6f.tar.xz |
Add -d option to s6-rc-init, to dereference compiled
-rw-r--r-- | doc/s6-rc-init.html | 13 | ||||
-rw-r--r-- | src/s6-rc/s6-rc-init.c | 16 |
2 files changed, 23 insertions, 6 deletions
diff --git a/doc/s6-rc-init.html b/doc/s6-rc-init.html index f24c20a..c0ae6fc 100644 --- a/doc/s6-rc-init.html +++ b/doc/s6-rc-init.html @@ -32,8 +32,8 @@ invocation of the </pre> <ul> - <li> <em>compiled</em>, <em>live</em> and <em>scandir</em> must be -absolute paths. </li> + <li> <em>compiled</em> (if the <tt>-d</tt> option hasn't been given), +<em>live</em> and <em>scandir</em> must be absolute paths. </li> <li> s6-rc-init expects to find a <em>compiled service database</em> in <em>compiled</em>. It expects to be able to create a directory named <em>live</em>. It also expects that an instance of @@ -79,6 +79,15 @@ being used by another program, s6-rc-init will wait until that other program has released its lock on the database, then proceed. By default, s6-rc-init fails with an error message if the database is currently in use. </li> + <li><tt>-d</tt> : dereference <em>compiled</em>. Fully resolve +the <em>compiled</em> path before declaring it as the current +compiled service database for the upcoming live state. This allows +<em>compiled</em> to be a symlink that can be updated later without +impacting the current live state. Using this flag in your init scripts' +<tt>s6-rc-init</tt> invocation means that it's possible to boot on a +compiled service database whose validity has not previously been +guaranteed by a successful <a href="s6-rc-update.html">s6-rc-update</a> +invocation: you should know what you are doing. </li> </ul> <h2> Typical usage </h2> diff --git a/src/s6-rc/s6-rc-init.c b/src/s6-rc/s6-rc-init.c index c749609..37134e2 100644 --- a/src/s6-rc/s6-rc-init.c +++ b/src/s6-rc/s6-rc-init.c @@ -4,6 +4,7 @@ #include <string.h> #include <unistd.h> #include <errno.h> +#include <stdlib.h> #include <skalibs/types.h> #include <skalibs/sgetopt.h> #include <skalibs/strerr2.h> @@ -14,7 +15,7 @@ #include <s6-rc/config.h> #include <s6-rc/s6rc.h> -#define USAGE "s6-rc-init [ -c compiled ] [ -l live ] [ -t timeout ] [ -b ] scandir" +#define USAGE "s6-rc-init [ -c compiled ] [ -l live ] [ -t timeout ] [ -b ] [ -d ] scandir" #define dieusage() strerr_dieusage(100, USAGE) #define dienomem() strerr_diefu1sys(111, "stralloc_catb") @@ -37,14 +38,14 @@ 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 ; + int blocking = 0, deref = 0 ; PROG = "s6-rc-init" ; { unsigned int t = 0 ; subgetopt_t l = SUBGETOPT_ZERO ; for (;;) { - int opt = subgetopt_r(argc, argv, "c:l:t:b", &l) ; + int opt = subgetopt_r(argc, argv, "c:l:t:bd", &l) ; if (opt == -1) break ; switch (opt) { @@ -52,6 +53,7 @@ int main (int argc, char const *const *argv) case 'l' : live = l.arg ; break ; case 't' : if (!uint0_scan(l.arg, &t)) dieusage() ; break ; case 'b' : blocking = 1 ; break ; + case 'd' : deref = 1 ; break ; default : dieusage() ; } } @@ -61,7 +63,7 @@ int main (int argc, char const *const *argv) } if (!argc) dieusage() ; - if (compiled[0] != '/') + if (!deref && compiled[0] != '/') strerr_dief2x(100, compiled, " is not an absolute path") ; if (live[0] != '/') strerr_dief2x(100, live, " is not an absolute path") ; @@ -111,6 +113,12 @@ int main (int argc, char const *const *argv) /* compiled */ + if (deref) + { + char *x = realpath(compiled, 0) ; + if (!x) strerr_diefu2sys(111, "realpath ", compiled) ; + compiled = x ; + } fdcompiled = open_readb(compiled) ; if (fdcompiled < 0) { |