diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2015-09-21 12:49:39 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2015-09-21 12:49:39 +0000 |
commit | 10d06f7d21b7ab7400ea94936712d7dcb2ed94ca (patch) | |
tree | d0352e2a783f1eacaf92b3891628eee0dddc29ec | |
parent | e56e129434975a6b8c9f7db7d956d778e8696655 (diff) | |
download | s6-rc-10d06f7d21b7ab7400ea94936712d7dcb2ed94ca.tar.xz |
Add s6-rc-oneshot-run (without using it in s6-rc-compile or s6-rc yet)
-rw-r--r-- | doc/index.html | 3 | ||||
-rw-r--r-- | doc/s6-rc-oneshot-run.html | 65 | ||||
-rw-r--r-- | package/deps.mak | 3 | ||||
-rw-r--r-- | package/modes | 1 | ||||
-rw-r--r-- | package/targets.mak | 3 | ||||
-rw-r--r-- | src/s6-rc/deps-exe/s6-rc-oneshot-run | 2 | ||||
-rw-r--r-- | src/s6-rc/s6-rc-oneshot-run.c | 102 |
7 files changed, 177 insertions, 2 deletions
diff --git a/doc/index.html b/doc/index.html index 3e66a90..58e60e3 100644 --- a/doc/index.html +++ b/doc/index.html @@ -106,8 +106,9 @@ the previous versions of s6-rc and the current one. </li> <ul> <li> <a href="s6-rc-init.html">The <tt>s6-rc-init</tt> program</a> </li> <li> <a href="s6-rc.html">The <tt>s6-rc</tt> program</a> </li> - <li> <a href="s6-rc-dryrun.html">The <tt>s6-rc-dryrun</tt> internal program</a> </li> <li> <a href="s6-rc-update.html">The <tt>s6-rc-update</tt> program</a> </li> + <li> <a href="s6-rc-dryrun.html">The <tt>s6-rc-dryrun</tt> internal program</a> </li> + <li> <a href="s6-rc-oneshot-run.html">The <tt>s6-rc-oneshot-run</tt> internal program</a> </li> </ul> <h2> Related resources </h2> diff --git a/doc/s6-rc-oneshot-run.html b/doc/s6-rc-oneshot-run.html new file mode 100644 index 0000000..c2b422f --- /dev/null +++ b/doc/s6-rc-oneshot-run.html @@ -0,0 +1,65 @@ +<html> + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0" /> + <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> + <meta http-equiv="Content-Language" content="en" /> + <title>s6-rc: the s6-rc-oneshot-run program</title> + <meta name="Description" content="s6-rc: the s6-rc-oneshot-run program" /> + <meta name="Keywords" content="s6-rc dry run s6-rc-oneshot-run command oneshot runner service manager" /> + <!-- <link rel="stylesheet" type="text/css" href="http://skarnet.org/default.css" /> --> + </head> +<body> + +<p> +<a href="index.html">s6-rc</a><br /> +<a href="http://skarnet.org/software/">Software</a><br /> +<a href="http://skarnet.org/">skarnet.org</a> +</p> + +<h1> The s6-rc-oneshot-run internal program </h1> + +<p> + s6-rc-oneshot-run executes a oneshot service's <tt>up</tt> or +<tt>down</tt> script taken from the current live compiled database. +</p> + +<p> + s6-rc-oneshot-run is not meant to be used directly; it is used +in internal scripts created by +<a href="s6-rc-compile.html">s6-rc-compile</a>, which are invoked during an +<a href="s6-rc.html">s6-rc</a> execution. +</p> + +<h2> Interface </h2> + +<pre> + s6-rc-oneshot-run [ -l <em>live</em> ] up|down <em>n</em> +</pre> + +<ul> + <li> s6-rc-oneshot-run executes into the <tt>up</tt> or <tt>down</tt> script, +depending on its first argument, of the <em>n</em>th oneshot service defined +in the current compiled service database (i.e. the compiled linked from the +live directory). </li> +</ul> + +<h2> Options </h2> + +<ul> + <li> <tt>-l <em>live</em></tt> : use the live directory in +<em>live</em>. Default is <tt>/run/s6-rc</tt>, or what was given to the +<tt>--livedir</tt> configure option at compile time. </li> +</ul> + +<h2> Exit codes </h2> + +<ul> + <li> 3: invalid service number </li> + <li> 4: invalid service database </li> + <li> 100: wrong usage </li> + <li> 111: system call failed </li> + <li> other exit codes: returned from the executed <tt>up</tt> or <tt>down</tt> script </li> +</ul> + +</body> +</html> diff --git a/package/deps.mak b/package/deps.mak index d97c2c5..53af35a 100644 --- a/package/deps.mak +++ b/package/deps.mak @@ -26,6 +26,7 @@ src/s6-rc/s6-rc-db.o src/s6-rc/s6-rc-db.lo: src/s6-rc/s6-rc-db.c src/include/s6- src/s6-rc/s6-rc-dryrun.o src/s6-rc/s6-rc-dryrun.lo: src/s6-rc/s6-rc-dryrun.c src/s6-rc/s6-rc-fdholder-filler.o src/s6-rc/s6-rc-fdholder-filler.lo: src/s6-rc/s6-rc-fdholder-filler.c src/s6-rc/s6-rc-init.o src/s6-rc/s6-rc-init.lo: src/s6-rc/s6-rc-init.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h +src/s6-rc/s6-rc-oneshot-run.o src/s6-rc/s6-rc-oneshot-run.lo: src/s6-rc/s6-rc-oneshot-run.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h src/s6-rc/s6-rc-update.o src/s6-rc/s6-rc-update.lo: src/s6-rc/s6-rc-update.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h src/s6-rc/s6-rc.o src/s6-rc/s6-rc.lo: src/s6-rc/s6-rc.c src/include/s6-rc/config.h src/include/s6-rc/s6rc.h @@ -46,5 +47,7 @@ s6-rc-fdholder-filler: private EXTRA_LIBS := ${TAINNOW_LIB} ${SOCKET_LIB} s6-rc-fdholder-filler: src/s6-rc/s6-rc-fdholder-filler.o -ls6 -lskarnet s6-rc-init: private EXTRA_LIBS := ${TAINNOW_LIB} ${SOCKET_LIB} s6-rc-init: src/s6-rc/s6-rc-init.o ${LIBS6RC} -ls6 -lskarnet +s6-rc-oneshot-run: private EXTRA_LIBS := +s6-rc-oneshot-run: src/s6-rc/s6-rc-oneshot-run.o ${LIBS6RC} -lskarnet s6-rc-update: private EXTRA_LIBS := ${TAINNOW_LIB} ${SOCKET_LIB} s6-rc-update: src/s6-rc/s6-rc-update.o ${LIBS6RC} -ls6 -lexecline -lskarnet diff --git a/package/modes b/package/modes index 967fa37..64109f7 100644 --- a/package/modes +++ b/package/modes @@ -6,3 +6,4 @@ s6-rc-init 0755 s6-rc 0755 s6-rc-update 0755 s6-rc-fdholder-filler 0755 +s6-rc-oneshot-run 0755 diff --git a/package/targets.mak b/package/targets.mak index 1dcce9e..9953c80 100644 --- a/package/targets.mak +++ b/package/targets.mak @@ -10,6 +10,7 @@ s6-rc \ s6-rc-update LIBEXEC_TARGETS := \ -s6-rc-fdholder-filler +s6-rc-fdholder-filler \ +s6-rc-oneshot-run LIB_DEFS := S6RC=s6rc diff --git a/src/s6-rc/deps-exe/s6-rc-oneshot-run b/src/s6-rc/deps-exe/s6-rc-oneshot-run new file mode 100644 index 0000000..152b051 --- /dev/null +++ b/src/s6-rc/deps-exe/s6-rc-oneshot-run @@ -0,0 +1,2 @@ +${LIBS6RC} +-lskarnet diff --git a/src/s6-rc/s6-rc-oneshot-run.c b/src/s6-rc/s6-rc-oneshot-run.c new file mode 100644 index 0000000..60834c8 --- /dev/null +++ b/src/s6-rc/s6-rc-oneshot-run.c @@ -0,0 +1,102 @@ +/* ISC license. */ + +#include <skalibs/uint.h> +#include <skalibs/bytestr.h> +#include <skalibs/sgetopt.h> +#include <skalibs/strerr2.h> +#include <skalibs/djbunix.h> +#include <s6-rc/config.h> +#include <s6-rc/s6rc.h> + +#define USAGE "s6-rc-oneshot-run [ -l live ] up|down servicenumber" +#define dieusage() strerr_dieusage(100, USAGE) + +int main (int argc, char const *const *argv, char const *const *envp) +{ + char const *live = S6RC_LIVE_BASE ; + unsigned int number ; + int up ; + PROG = "s6-rc-db" ; + { + subgetopt_t l = SUBGETOPT_ZERO ; + for (;;) + { + register int opt = subgetopt_r(argc, argv, "l:", &l) ; + if (opt == -1) break ; + switch (opt) + { + case 'l' : live = l.arg ; break ; + default : dieusage() ; + } + } + argc -= l.ind ; argv += l.ind ; + } + + if (argc < 2) dieusage() ; + if (!case_diffs(argv[0], "up")) up = 1 ; + else if (!case_diffs(argv[0], "down")) up = 0 ; + else dieusage() ; + if (!uint0_scan(argv[1], &number)) dieusage() ; + + { + unsigned int livelen = str_len(live) ; + int fdcompiled, compiledlock ; + s6rc_db_t db ; + char compiled[livelen + 10] ; + byte_copy(compiled, livelen, live) ; + byte_copy(compiled + livelen, 10, "/compiled") ; + + if (!s6rc_lock(0, 0, 0, compiled, 1, &compiledlock)) + strerr_diefu2sys(111, "take lock on ", compiled) ; + fdcompiled = open_readb(compiled) ; + if (fdcompiled < 0) + strerr_diefu2sys(111, "open ", compiled) ; + + + /* Read the sizes of the compiled db */ + + fdcompiled = open_readb(compiled) ; + if (!s6rc_db_read_sizes(fdcompiled, &db)) + strerr_diefu3sys(111, "read ", compiled, "/n") ; + + if (number >= db.nshort) + strerr_dief1x(3, "invalid oneshot number") ; + + + /* Allocate enough stack for the db */ + + { + s6rc_service_t serviceblob[db.nshort + db.nlong] ; + char const *argvblob[db.nargvs] ; + uint32 depsblob[db.ndeps << 1] ; + char stringblob[db.stringlen] ; + register int r ; + + db.services = serviceblob ; + db.argvs = argvblob ; + db.deps = depsblob ; + db.string = stringblob ; + + + /* Read the db from the file */ + + r = s6rc_db_read(fdcompiled, &db) ; + if (r < 0) strerr_diefu3sys(111, "read ", compiled, "/db") ; + if (!r) strerr_dief3x(4, "invalid service database in ", compiled, "/db") ; + + + /* Run the script */ + + { + register unsigned int sargc = db.services[number].x.oneshot.argc[up] ; + char const *const *sargv = db.argvs + db.services[number].x.oneshot.argv[up] ; + char const *newargv[sargc + 1] ; + register char const **p = newargv ; + while (sargc--) *p++ = *sargv++ ; + *p = 0 ; + pathexec_run(newargv[0], newargv, envp) ; + strerr_dieexec(111, newargv[0]) ; + } + } + } +} |