commit c771aabafeaea4ba903dd8f06ad6fc1e95504946
parent f481d14e9d9c5b2d57995aa0d9094500676e013e
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date: Thu, 7 Jan 2021 23:38:06 +0000
Doc clarification, QoL fix for s6-usertree-maker
Diffstat:
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/doc/s6-usertree-maker.html b/doc/s6-usertree-maker.html
@@ -39,7 +39,7 @@ for the <a href="//skarnet.org/software/s6-rc/">s6-rc</a> service manager.
[ -d <em>userscandir</em> ] \
[ -p <em>path</em> ] \
[ -E <em>envdir</em> [ -e <em>var</em> -e <em>var</em> ... ] ] \
- [ -r <em>service</em>/<em>logger</em>/<em>pipeline</em> ] \
+ [ -r <em>service</em>/<em>logger</em>[/<em>pipeline</em>] ] \
[ -l <em>loguser</em> ] \
[ -t <em>stamptype</em> ] \
[ -n <em>nfiles</em> ] \
@@ -208,7 +208,7 @@ then <a href="s6-svscan.html">s6-svscan</a> will be run on
<tt>/home/ska/service</tt>.
</p>
-<h2> Example </h2>
+<h2> Examples </h2>
<pre>
s6-usertree-maker -d '/run/user/${UID}/service' -p '${HOME}/bin:/usr/bin:/bin' -E /etc/user-env -e XDG_CONFIG_HOME -l catchlog ska /var/log/usertree/ska usertree-ska
@@ -225,6 +225,24 @@ as user catchlog, and storing its data in the <tt>/var/log/usertree/ska</tt>
directory.
</p>
+<p>
+ Note that simple quotes are used here to prevent the shell from
+interpreting <tt>${UID}</tt> and <tt>${HOME}</tt>.
+</p>
+
+<pre>
+ s6-usertree-maker -d '/run/user/${UID}/service' -p '${HOME}/bin:/usr/bin:/bin' -E /etc/user-env -e XDG_CONFIG_HOME -l catchlog -r usertree-ska/usertree-ska-log/usertree-ska-pipeline ska /var/log/usertree/ska usertree
+</pre>
+
+<p>
+ Same as above, except it does not create a service directory — instead, it
+creates a <tt>usertree</tt> directory containing two subdirectories: <tt>usertree-ska</tt>, the
+<a href="//skarnet.org/software/s6-rc/">s6-rc</a> source definition directory
+for the service, and <tt>usertree-ska-log</tt>, the source definition directory
+for its logger, and an implicit <tt>usertree-ska-pipeline</tt> bundle
+containing both the service and the logger.
+</p>
+
<h2> Notes </h2>
<ul>
diff --git a/src/usertree/s6-usertree-maker.c b/src/usertree/s6-usertree-maker.c
@@ -4,6 +4,7 @@
#include <string.h>
#include <sys/stat.h>
#include <sys/uio.h>
+#include <errno.h>
#include <skalibs/config.h>
#include <skalibs/uint64.h>
@@ -274,9 +275,8 @@ int main (int argc, char *const *argv)
mask = umask(0) ;
umask(mask) ;
mask = ~mask & 0666 ;
-
- if (mkdir(argv[2], 0755) < 0) strerr_diefu2sys(111, "mkdir ", argv[2]) ;
dirlen = strlen(argv[2]) ;
+
if (rcinfo[0])
{
size_t svclen = strlen(rcinfo[0]) ;
@@ -285,6 +285,8 @@ int main (int argc, char *const *argv)
memcpy(dir, argv[2], dirlen) ;
dir[dirlen] = '/' ;
memcpy(dir + dirlen + 1, rcinfo[0], svclen + 1) ;
+ if (mkdir(argv[2], 0755) < 0 && errno != EEXIST)
+ strerr_diefu2sys(111, "mkdir ", argv[2]) ;
if (mkdir(dir, 0755) < 0) strerr_diefu2sys(111, "mkdir ", dir) ;
write_service(dir, argv[0], userscandir, rcinfo[1], path, userenvdir, vars, varlen) ;
memcpy(dir + dirlen + 1, rcinfo[1], loglen + 1) ;
@@ -295,6 +297,7 @@ int main (int argc, char *const *argv)
char dir[dirlen + 5] ;
memcpy(dir, argv[2], dirlen) ;
memcpy(dir + dirlen, "/log", 5) ;
+ if (mkdir(argv[2], 0755) < 0) strerr_diefu2sys(111, "mkdir ", argv[2]) ;
write_service(argv[2], argv[0], userscandir, 0, path, userenvdir, vars, varlen) ;
write_logger(dir, loguser, argv[1], stamptype, nfiles, filesize, maxsize, 0, 0) ;
}