aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2026-04-09 02:31:43 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2026-04-09 02:31:43 +0000
commit8a5a621baa9e756b34c507c3d8e2119dabe7f630 (patch)
tree7a04e091de081a764ffc76ddde7cb84ee93662d0
parent1863ed9af17071fb733905534eb9c9433e86715a (diff)
downloads6-8a5a621baa9e756b34c507c3d8e2119dabe7f630.tar.gz
Add s6-notify-fd-from-socket and s6-notify-socket-from-fd
Also add .gitkeep files, remove old include-local/s6lockd.h, update a little bit of doc, make s6-ftrigrd pipe-only
-rw-r--r--INSTALL2
-rw-r--r--NEWS1
-rw-r--r--doc/index.html58
-rw-r--r--doc/s6-notify-fd-from-socket.html110
-rw-r--r--doc/s6-notify-socket-from-fd.html129
-rw-r--r--doc/upgrade.html3
-rw-r--r--package/deps.mak6
-rw-r--r--package/modes2
-rw-r--r--package/targets.mak2
-rw-r--r--src/alias/deps-lib/.gitkeep0
-rw-r--r--src/conn-tools/deps-lib/.gitkeep0
-rw-r--r--src/daemontools-extras/deps-lib/.gitkeep0
-rw-r--r--src/fdholder/deps-lib/.gitkeep0
-rw-r--r--src/include-local/.gitkeep0
-rw-r--r--src/include-local/s6lockd.h8
-rw-r--r--src/instance/deps-lib/.gitkeep0
-rw-r--r--src/libs6/s6-ftrigrd.c2
-rw-r--r--src/pipe-tools/deps-lib/.gitkeep0
-rw-r--r--src/supervision/deps-exe/s6-notify-fd-from-socket3
-rw-r--r--src/supervision/deps-exe/s6-notify-socket-from-fd3
-rw-r--r--src/supervision/deps-lib/.gitkeep0
-rw-r--r--src/supervision/s6-notify-fd-from-socket.c145
-rw-r--r--src/supervision/s6-notify-socket-from-fd.c138
-rw-r--r--src/usertree/deps-lib/.gitkeep0
24 files changed, 577 insertions, 35 deletions
diff --git a/INSTALL b/INSTALL
index 89fae31..340d2d2 100644
--- a/INSTALL
+++ b/INSTALL
@@ -7,7 +7,7 @@ Build Instructions
- A POSIX-compliant C development environment
- GNU make version 3.81 or later
- skalibs version 2.15.0.0 or later: https://skarnet.org/software/skalibs/
- - Recommended: execline version 2.9.8.2 or later: https://skarnet.org/software/execline/
+ - Recommended: execline version 2.9.9.0 or later: https://skarnet.org/software/execline/
(You can disable this requirement at configure time, but will
lose some functionality.)
- Optional: nsss version 0.2.1.2 or later: https://skarnet.org/software/nsss/
diff --git a/NEWS b/NEWS
index c3959da..d9e6c0b 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ except the next point.
- s6-ftrig-wait and s6-ftrig-listen1 now print the whole
sequence of events (followed by a newline) to stdout, rather than
just the triggering event.
+ - New binaries: s6-notify-fd-from-socket, s6-notify-socket-from-fd
In 2.14.0.1
diff --git a/doc/index.html b/doc/index.html
index 721c5f1..bb1d762 100644
--- a/doc/index.html
+++ b/doc/index.html
@@ -162,7 +162,7 @@ ports the s6 documentation to a set of man pages.
Short-lived commands exit 0 on success.
</p>
-<h4> Supervision system </h4>
+<h4 id="supervision"> Supervision system </h4>
<p>
<a href="s6-svscan.html">s6-svscan</a> and <a href="s6-supervise.html">s6-supervise</a>
@@ -180,17 +180,24 @@ a user interface to control those processes and monitor service states.
<li><a href="s6-svperms.html">The <tt>s6-svperms</tt> program</a></li>
<li><a href="s6-svlink.html">The <tt>s6-svlink</tt> program</a></li>
<li><a href="s6-svunlink.html">The <tt>s6-svunlink</tt> program</a></li>
-<li><a href="s6-svwait.html">The <tt>s6-svwait</tt> program</a></li>
-<li><a href="s6-svlisten1.html">The <tt>s6-svlisten1</tt> program</a></li>
-<li><a href="s6-svlisten.html">The <tt>s6-svlisten</tt> program</a></li>
-<li><a href="s6-notifyoncheck.html">The <tt>s6-notifyoncheck</tt> program</a></li>
<li><a href="s6-svdt.html">The <tt>s6-svdt</tt> program</a></li>
<li><a href="s6-svdt-clear.html">The <tt>s6-svdt-clear</tt> program</a></li>
<li><a href="s6-permafailon.html">The <tt>s6-permafailon</tt> program</a></li>
<li><a href="s6-background-watch.html">The <tt>s6-background-watch</tt> program</a></li>
</ul>
-<h4> Daemontools-like utilities </h4>
+<h4 id="notification"> Readiness notification for supervised services </h4>
+
+<ul>
+ <li><a href="s6-svwait.html">The <tt>s6-svwait</tt> program</a></li>
+ <li><a href="s6-svlisten1.html">The <tt>s6-svlisten1</tt> program</a></li>
+ <li><a href="s6-svlisten.html">The <tt>s6-svlisten</tt> program</a></li>
+ <li><a href="s6-notifyoncheck.html">The <tt>s6-notifyoncheck</tt> program</a></li>
+ <li><a href="s6-notify-fd-from-socket.html">The <tt>s6-notify-fd-from-socket</tt> program</a></li>
+ <li><a href="s6-notify-socket-from-fd.html">The <tt>s6-notify-socket-from-fd</tt> program</a></li>
+</ul>
+
+<h4 id="daemontools"> Misc utilities for run scripts </h4>
<p>
These programs are a rewrite of the corresponding utilities from
@@ -211,14 +218,13 @@ a few extras.
<li><a href="s6-tai64nlocal.html">The <tt>s6-tai64nlocal</tt> program</a></li>
</ul>
-<h4> Fifodir management, notification and subscription </h4>
+<h4 id="fifodir"> Fifodir management, notification and subscription </h4>
<p>
-These programs are a clean rewrite of the obsolete "pipe-tools" package; they
-are now based on a properly designed notification library.
-They provide a command-line interface to
+These programs provide a command-line interface to
<a href="ftrig.html#notification">inter-process notification and
-synchronization</a>.
+synchronization</a>. They're a generalized interface to the same
+mechanisms used by tools like <a href="s6-svwait.html">s6-svwait</a>.
</p>
<ul>
@@ -237,7 +243,7 @@ synchronization</a>.
<li><a href="libs6/s6-ftrigrd.html">The <tt>s6-ftrigrd</tt> internal program</a></li>
</ul>
-<h4> Local service management and access control </h4>
+<h4 id="unixsocket"> Unix domain super-server, local service management and access control </h4>
<ul>
<li><a href="s6-ipcclient.html">The <tt>s6-ipcclient</tt> program</a></li>
@@ -255,7 +261,7 @@ synchronization</a>.
<li><a href="s6-accessrules-fs-from-cdb.html">The <tt>s6-accessrules-fs-from-cdb</tt> program</a></li>
</ul>
-<h4> suidless privilege gain </h4>
+<h4 id="nosuid"> suidless privilege gain </h4>
<ul>
<li><a href="s6-sudo.html">The <tt>s6-sudo</tt> program</a></li>
@@ -263,7 +269,7 @@ synchronization</a>.
<li><a href="s6-sudod.html">The <tt>s6-sudod</tt> program</a></li>
</ul>
-<h4> Logging </h4>
+<h4 id="log"> Logging </h4>
<ul>
<li><a href="s6-log.html">The <tt>s6-log</tt> program</a></li>
@@ -271,13 +277,13 @@ synchronization</a>.
<li><a href="ucspilogd.html">The <tt>ucspilogd</tt> program</a></li>
</ul>
-<h4> Management of user supervision trees </h4>
+<h4 id="usertree"> Management of user supervision trees </h4>
<ul>
<li><a href="s6-usertree-maker.html">The <tt>s6-usertree-maker</tt> program</a></li>
</ul>
-<h4> Management of dynamic instances </h4>
+<h4 id="instance"> Management of dynamic instances </h4>
<ul>
<li>An <a href="instances.html">overview</a> of dynamic instantiation in s6</li>
@@ -289,7 +295,7 @@ synchronization</a>.
<li><a href="s6-instance-list.html">The <tt>s6-instance-list</tt> program</a></li>
</ul>
-<h4> fd-holding, a.k.a. the sensible part of socket activation </h4>
+<h4 id="fdholder"> fd-holding, a.k.a. the sensible part of socket activation </h4>
<ul>
<li><a href="s6-fdholder-daemon.html">The <tt>s6-fdholder-daemon</tt> program</a></li>
@@ -334,10 +340,9 @@ synchronization</a>.
<h3> s6 manual pages </h3>
<ul>
- <li> <a href="https://github.com/flexibeast">flexibeast</a> is doing the ungrateful
-but valuable work of
-<a href="https://github.com/flexibeast/s6-man-pages">providing the s6 documentation
-as a set of man pages</a>. </li>
+ <li> <a href="https://git.sr.ht/~humm/">Lennart Jablonka</a> is doing the ungrateful
+but valuable work of providing the s6 documentation
+<a href="https://git.sr.ht/~humm/s6-man-pages">as a set of man pages</a>. </li>
</ul>
<h3> Other components for s6-based init systems </h3>
@@ -346,10 +351,13 @@ as a set of man pages</a>. </li>
<li> <a href="//skarnet.org/software/s6-linux-init/">s6-linux-init</a>
is a package to help you create a <tt>/sbin/init</tt> binary booting a
Linux system with s6-svscan as process 1. </li>
- <li> <a href="https://github.com/just-containers/s6-overlay">s6-overlay</a>
-is a project that automates integration of s6 into Docker images. </li>
<li> <a href="//skarnet.org/software/s6-rc/">s6-rc</a> is a
dependency-based service manager for s6. </li>
+ <li> <a href="//skarnet.org/software/s6-frontend/">s6-frontend</a> is
+a friendlier user interface to address the complete s6 ecosystem (this
+package, s6-linux-init and s6-rc). </li>
+ <li> <a href="https://github.com/just-containers/s6-overlay">s6-overlay</a>
+is a project that automates integration of s6 into Docker images. </li>
<li> <a href="https://jjacky.com/anopa">anopa</a> is another dependency-based
service manager for s6. </li>
<li> <a href="https://web.obarun.org/software/66/latest/">66</a> is another
@@ -362,8 +370,8 @@ service manager working on top of s6. </li>
<ul>
<li> <tt>s6</tt> is discussed on the
<a href="//skarnet.org/lists/#supervision">supervision</a> mailing-list. </li>
- <li> There is a <tt>#s6</tt> IRC channel on OFTC. Sometimes people are there
-and answer questions. </li>
+ <li> There is a <tt>#s6</tt> IRC channel on OFTC. It hosts most discussions
+around supervision topics, and skaware in general. </li>
</ul>
<h3> Similar work </h3>
diff --git a/doc/s6-notify-fd-from-socket.html b/doc/s6-notify-fd-from-socket.html
new file mode 100644
index 0000000..2a8ea62
--- /dev/null
+++ b/doc/s6-notify-fd-from-socket.html
@@ -0,0 +1,110 @@
+<html>
+ <head>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <meta name="color-scheme" content="dark light" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <meta http-equiv="Content-Language" content="en" />
+ <title>s6: the s6-notify-fd-from-socket program</title>
+ <meta name="Description" content="s6: the s6-notify-fd-from-socket program" />
+ <meta name="Keywords" content="s6 command s6-notify-fd-from-socket NOTIFY_SOCKET systemd notification service check" />
+ <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> -->
+ </head>
+<body>
+
+<p>
+<a href="index.html">s6</a><br />
+<a href="//skarnet.org/software/">Software</a><br />
+<a href="//skarnet.org/">skarnet.org</a>
+</p>
+
+<h1> The s6-notify-fd-from-socket </h1>
+
+<p>
+<tt>s6-notify-fd-from-socket</tt> is meant to be used in a run script,
+when you want to use s6 to supervise a program that follows systemd's
+<a href="https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html">NOTIFY_SOCKET</a>
+protocol. It converts a readiness notification sent via that protocol
+into s6's <a href="notifywhenup.html">native format</a>.
+</p>
+
+<h2 id="interface"> Interface </h2>
+
+<pre>
+ s6-notify-fd-from-socket [ -3 <em>fd</em> ] [ -f ] [ -t <em>timeout</em> ] <em>prog...</em>
+</pre>
+
+<ul>
+ <li> <tt>s6-notify-fd-from-socket</tt> doubleforks and runs as the grandchild;
+the parent immediately execs into <em>prog...</em>, which is expected to use the
+NOTIFY_SOCKET protocol. </li>
+ <li> If <em>prog</em> dies before sending its notification, or if the timeout
+(if any) expires, <tt>s6-notify-fd-from-socket</tt> just exits. </li>
+ <li> If <em>prog</em> notifies readiness, <tt>s6-notify-fd-from-socket</tt>
+writes a newline to the file descriptor configured for the service,
+then it exits. </li>
+</ul>
+
+<h2 id="exitcodes"> Exit codes </h2>
+
+<p>
+ <tt>s6-notify-fd-from-socket</tt> can exit before executing into <em>prog</em>:
+</p>
+
+<ul>
+ <li> 100: wrong usage </li>
+ <li> 111: system call failed </li>
+</ul>
+
+<p>
+ After forking, <tt>s6-notify-fd-from-socket</tt> (running as a child or
+grandchild) can
+exit with the following exit codes, but those are meaningless
+because no process will, or should, check them. They are only
+differentiated for clarity in the source code:
+</p>
+
+<ul>
+ <li> 0: service readiness achieved and notification sent </li>
+ <li> 99: timed out before readiness was achieved </li>
+ <li> 111: system call failed </li>
+</ul>
+
+<h2 id="options"> Options </h2>
+
+<dl>
+ <dt> <tt>-3 <em>fd</em></tt>, <tt>--notification-fd=<em>fd</em></tt> </dt>
+ <dd> Force writing the readiness notification to descriptor <em>fd</em>. By default,
+the notification is sent to the descriptor written in the <tt>notification-fd</tt>
+file of the service directory, and it is an error if this file does not exist
+(because the <a href="s6-supervise.html">supervisor</a> needs to be prepared to
+receive the notification). </dd>
+
+ <dt> <tt>-t <em>timeout</em></tt>, <tt>--timeout=<em>timeout</em></tt> </dt>
+ <dd> Exit without notifying the supervisor if <em>prog</em> hasn't notified
+readiness after <em>timeout</em> milliseconds. Default is <strong>0</strong>,
+meaning infinite: <tt>s6-notify-fd-from-socket</tt> will wait forever for
+a notification, up to when <em>prog</em> exits. </dd>
+
+ <dt> <tt>-f</tt>, <tt>--no-doublefork</tt> </dt>
+ <dd> Make <tt>s6-notify-fd-from-socket</tt> live as a direct child of
+<em>prog</em> rather than doubleforking. It is less costly (it might
+save a millisecond), but it will leave a zombie around if <em>prog</em>
+does not know how to reap its bastards (children it doesn't know it has).
+If <em>prog</em> reaps everything, you can safely use this option;
+otherwise, leave it alone. </dd>
+</dl>
+
+<h2 id="notes"> Notes </h2>
+
+<ul>
+ <li> <tt>s6-notify-fd-from-socket</tt> is for daemons using the systemd
+protocol that you want to run under s6. If you want to do the opposite, i.e.
+run under systemd a daemon that uses the s6 notification protocol, use the
+<a href="s6-notify-socket-from-fd.html">s6-notify-socket-from-fd</a> program
+instead. </li>
+</ul>
+
+
+
+</body>
+</html>
diff --git a/doc/s6-notify-socket-from-fd.html b/doc/s6-notify-socket-from-fd.html
new file mode 100644
index 0000000..ec2a57a
--- /dev/null
+++ b/doc/s6-notify-socket-from-fd.html
@@ -0,0 +1,129 @@
+<html>
+ <head>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
+ <meta name="color-scheme" content="dark light" />
+ <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+ <meta http-equiv="Content-Language" content="en" />
+ <title>s6: the s6-notify-socket-from-fd program</title>
+ <meta name="Description" content="s6: the s6-notify-socket-from-fd program" />
+ <meta name="Keywords" content="s6 command s6-notify-socket-from-fd NOTIFY_SOCKET systemd notification service check" />
+ <!-- <link rel="stylesheet" type="text/css" href="//skarnet.org/default.css" /> -->
+ </head>
+<body>
+
+<p>
+<a href="index.html">s6</a><br />
+<a href="//skarnet.org/software/">Software</a><br />
+<a href="//skarnet.org/">skarnet.org</a>
+</p>
+
+<h1> The s6-notify-socket-from-fd program </h1>
+
+<p>
+<tt>s6-notify-socket-from-fd</tt> is different from other chainloading
+tools in s6, in as it's not meant to be used in s6 run scripts. Instead,
+it's meant to be used when you're <em>not</em> using s6, but another
+service manager that does not support the
+<a href="notifywhenup.html">s6 readiness notification protocol</a>,
+but supports the
+<a href="https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html">NOTIFY_SOCKET</a>
+protocol.
+</p>
+
+<p>
+ Typically, you would use it if you have a daemon <tt>foobard</tt> that
+uses the s6 readiness notification protocol, but need to run that daemon
+under systemd. Instead of running it with <tt>ExecStart=foobard</tt> and
+having to use <tt>Type=main</tt>, losing the benefit of notification, you
+can use <tt>ExecStart="s6-notify-socket-from-fd foobard"</tt> and
+<tt>Type=notify</tt>, and systemd will handle readiness correctly.
+</p>
+
+<h2 id="interface"> Interface </h2>
+
+<pre>
+ s6-notify-socket-from-fd [ -d <em>fd</em> ] [ -f ] [ -t <em>timeout</em> ] [ -k ] <em>prog...</em>
+</pre>
+
+<ul>
+ <li> If the <tt>NOTIFY_SOCKET</tt> environment variable isn't defined,
+it means that <tt>s6-notify-socket-from-fd</tt> is not running under a
+supervisor expecting a systemd-style readiness notification. So it does nothing
+and just execs into <em>prog...</em>. If the variable is defined, the
+following points apply. </li>
+ <li> <tt>s6-notify-socket-from-fd</tt> doubleforks and runs as the grandchild;
+the parent immediately execs into <em>prog...</em>, which is expected to use the
+s6 readiness notification protocol. </li>
+ <li> If <em>prog</em> dies before sending its notification, or if the timeout
+(if any) expires, <tt>s6-notify-socket-from-fd</tt> just exits. </li>
+ <li> If <em>prog</em> notifies readiness, <tt>s6-notify-socket-from-fd</tt>
+sends a systemd-style notification to the supervisor listening to the socket
+given in <tt>NOTIFY_SOCKET</tt>, then it exits. </li>
+</ul>
+
+<h2 id="exitcodes"> Exit codes </h2>
+
+<p>
+ <tt>s6-notify-socket-from-fd</tt> can exit before executing into <em>prog</em>:
+</p>
+
+<ul>
+ <li> 100: wrong usage </li>
+ <li> 111: system call failed </li>
+</ul>
+
+<p>
+ After forking, <tt>s6-notify-socket-from-fd</tt> (running as a child or
+grandchild) can
+exit with the following exit codes, but those are meaningless
+because no process will, or should, check them. They are only
+differentiated for clarity in the source code:
+</p>
+
+<ul>
+ <li> 0: service readiness achieved and notification sent </li>
+ <li> 99: timed out before readiness was achieved </li>
+ <li> 111: system call failed </li>
+</ul>
+
+<h2 id="options"> Options </h2>
+
+<dl>
+ <dt> <tt>-d <em>fd</em></tt>, <tt>--notification-fd=<em>fd</em></tt> </dt>
+ <dd> Expect <em>prog...</em> to send its notification on descriptor <em>fd</em>.
+Default is <strong>1</strong>. </dd>
+
+ <dt> <tt>-t <em>timeout</em></tt>, <tt>--timeout=<em>timeout</em></tt> </dt>
+ <dd> Exit without notifying the supervisor if <em>prog</em> hasn't notified
+readiness after <em>timeout</em> milliseconds. Default is <strong>0</strong>,
+meaning infinite: <tt>s6-notify-socket-from-fd</tt> will wait forever for
+a notification, up to when <em>prog</em> exits. </dd>
+
+ <dt> <tt>-f</tt>, <tt>--no-doublefork</tt> </dt>
+ <dd> Make <tt>s6-notify-socket-from-fd</tt> live as a direct child of
+<em>prog</em> rather than doubleforking. It is less costly (it might
+save a millisecond), but it will leave a zombie around if <em>prog</em>
+does not know how to reap its bastards (children it doesn't know it has).
+If <em>prog</em> reaps everything, you can safely use this option;
+otherwise, leave it alone. </dd>
+
+ <dt> <tt>-k</tt>, <tt>--keep-environment</tt> </dt>
+ <dd> Keep the <tt>NOTIFY_SOCKET</tt> environment variable in <em>prog</em>'s
+environment. By default, the variable is removed from it, because <em>prog</em>,
+not using the systemd notification protocol, normally has no use for it. </dd>
+</dl>
+
+<h2 id="notes"> Notes </h2>
+
+<ul>
+ <li> This program was previously available on skarnet.org outside of any
+package, under the name <tt>sdnotify-wrapper</tt>. </li>
+ <li> <tt>s6-notify-socket-from-fd</tt> is for s6-style daemons that you
+want to run under systemd. If you want to do the opposite, i.e. run under
+s6 a daemon that uses the systemd protocol, use the
+<a href="s6-notify-fd-from-socket.html">s6-notify-fd-from-socket</a> program
+instead. </li>
+</ul>
+
+</body>
+</html>
diff --git a/doc/upgrade.html b/doc/upgrade.html
index c31b001..e8cedc5 100644
--- a/doc/upgrade.html
+++ b/doc/upgrade.html
@@ -38,6 +38,9 @@ s6-ftrigrd now always runs as a child of the client </li>
<li> The API of the <a href="libs6/ftrigr.html">ftrigr library</a>
is somewhat different. </li>.
</ul> </li>
+ <li> New binaries:
+<a href="s6-notify-fd-from-socket.html">s6-notify-fd-from-socket</a>,
+<a href="s6-notify-socket-from-fd.html">s6-notify-socket-from-fd</a>. </li>
</ul>
diff --git a/package/deps.mak b/package/deps.mak
index b6bae62..4f58086 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -121,6 +121,8 @@ src/pipe-tools/s6-ftrig-notify.o src/pipe-tools/s6-ftrig-notify.lo: src/pipe-too
src/pipe-tools/s6-ftrig-wait.o src/pipe-tools/s6-ftrig-wait.lo: src/pipe-tools/s6-ftrig-wait.c src/include/s6/ftrigr.h
src/pipe-tools/s6-mkfifodir.o src/pipe-tools/s6-mkfifodir.lo: src/pipe-tools/s6-mkfifodir.c src/include/s6/ftrigw.h
src/supervision/s6-background-watch.o src/supervision/s6-background-watch.lo: src/supervision/s6-background-watch.c
+src/supervision/s6-notify-fd-from-socket.o src/supervision/s6-notify-fd-from-socket.lo: src/supervision/s6-notify-fd-from-socket.c
+src/supervision/s6-notify-socket-from-fd.o src/supervision/s6-notify-socket-from-fd.lo: src/supervision/s6-notify-socket-from-fd.c
src/supervision/s6-notifyoncheck.o src/supervision/s6-notifyoncheck.lo: src/supervision/s6-notifyoncheck.c src/include/s6/s6.h
src/supervision/s6-permafailon.o src/supervision/s6-permafailon.lo: src/supervision/s6-permafailon.c src/include/s6/supervise.h
src/supervision/s6-supervise.o src/supervision/s6-supervise.lo: src/supervision/s6-supervise.c src/include/s6/config.h src/include/s6/ftrigw.h src/include/s6/supervise.h
@@ -263,6 +265,10 @@ s6-mkfifodir: EXTRA_LIBS :=
s6-mkfifodir: src/pipe-tools/s6-mkfifodir.o ${LIBS6} -lskarnet
s6-background-watch: EXTRA_LIBS := ${SPAWN_LIB} ${KEVENTPTHREAD_LIB}
s6-background-watch: src/supervision/s6-background-watch.o -lskarnet
+s6-notify-fd-from-socket: EXTRA_LIBS := ${SOCKET_LIB} ${SYSCLOCK_LIB}
+s6-notify-fd-from-socket: src/supervision/s6-notify-fd-from-socket.o -lskarnet
+s6-notify-socket-from-fd: EXTRA_LIBS := ${SOCKET_LIB} ${SYSCLOCK_LIB}
+s6-notify-socket-from-fd: src/supervision/s6-notify-socket-from-fd.o -lskarnet
s6-notifyoncheck: EXTRA_LIBS := ${SOCKET_LIB} ${SYSCLOCK_LIB} ${SPAWN_LIB}
s6-notifyoncheck: src/supervision/s6-notifyoncheck.o ${LIBS6} -lskarnet
s6-permafailon: EXTRA_LIBS := ${SYSCLOCK_LIB}
diff --git a/package/modes b/package/modes
index 007d9dd..d7b6953 100644
--- a/package/modes
+++ b/package/modes
@@ -25,6 +25,8 @@ s6-svlisten 0755
s6-background-watch 0755
s6-svperms 0755
s6-notifyoncheck 0755
+s6-notify-fd-from-socket 0755
+s6-notify-socket-from-fd 0755
s6-permafailon 0755
s6-applyuidgid 0755
s6-envdir 0755
diff --git a/package/targets.mak b/package/targets.mak
index 0dfcd04..a607f2b 100644
--- a/package/targets.mak
+++ b/package/targets.mak
@@ -61,6 +61,8 @@ s6-instance-control \
s6-instance-status \
s6-instance-list \
s6-background-watch \
+s6-notify-fd-from-socket \
+s6-notify-socket-from-fd \
LIBEXEC_TARGETS := \
s6-ftrigrd \
diff --git a/src/alias/deps-lib/.gitkeep b/src/alias/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/alias/deps-lib/.gitkeep
diff --git a/src/conn-tools/deps-lib/.gitkeep b/src/conn-tools/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/conn-tools/deps-lib/.gitkeep
diff --git a/src/daemontools-extras/deps-lib/.gitkeep b/src/daemontools-extras/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/daemontools-extras/deps-lib/.gitkeep
diff --git a/src/fdholder/deps-lib/.gitkeep b/src/fdholder/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/fdholder/deps-lib/.gitkeep
diff --git a/src/include-local/.gitkeep b/src/include-local/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/include-local/.gitkeep
diff --git a/src/include-local/s6lockd.h b/src/include-local/s6lockd.h
deleted file mode 100644
index 61a23b8..0000000
--- a/src/include-local/s6lockd.h
+++ /dev/null
@@ -1,8 +0,0 @@
-/* ISC license. */
-
-#ifndef S6LOCKD_H
-#define S6LOCKD_H
-
-extern int s6lockd_openandlock (char const *, int, int) ;
-
-#endif
diff --git a/src/instance/deps-lib/.gitkeep b/src/instance/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/instance/deps-lib/.gitkeep
diff --git a/src/libs6/s6-ftrigrd.c b/src/libs6/s6-ftrigrd.c
index a037e31..cee705d 100644
--- a/src/libs6/s6-ftrigrd.c
+++ b/src/libs6/s6-ftrigrd.c
@@ -159,7 +159,7 @@ int main (void)
{
tain deadline ;
tain_addsec_g(&deadline, 5) ;
- sassserver_init_g(&a, FTRIGR_BANNER1, FTRIGR_BANNER2, &ftrigio_add, &ftrigio_remove, sizeof(ftrigio), &cleanup, 0, &deadline) ;
+ sassserver_init_frompipe_g(&a, FTRIGR_BANNER1, FTRIGR_BANNER2, &ftrigio_add, &ftrigio_remove, sizeof(ftrigio), &cleanup, 0, &deadline) ;
}
while (!r)
diff --git a/src/pipe-tools/deps-lib/.gitkeep b/src/pipe-tools/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/pipe-tools/deps-lib/.gitkeep
diff --git a/src/supervision/deps-exe/s6-notify-fd-from-socket b/src/supervision/deps-exe/s6-notify-fd-from-socket
new file mode 100644
index 0000000..720fe7d
--- /dev/null
+++ b/src/supervision/deps-exe/s6-notify-fd-from-socket
@@ -0,0 +1,3 @@
+-lskarnet
+${SOCKET_LIB}
+${SYSCLOCK_LIB}
diff --git a/src/supervision/deps-exe/s6-notify-socket-from-fd b/src/supervision/deps-exe/s6-notify-socket-from-fd
new file mode 100644
index 0000000..720fe7d
--- /dev/null
+++ b/src/supervision/deps-exe/s6-notify-socket-from-fd
@@ -0,0 +1,3 @@
+-lskarnet
+${SOCKET_LIB}
+${SYSCLOCK_LIB}
diff --git a/src/supervision/deps-lib/.gitkeep b/src/supervision/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/supervision/deps-lib/.gitkeep
diff --git a/src/supervision/s6-notify-fd-from-socket.c b/src/supervision/s6-notify-fd-from-socket.c
new file mode 100644
index 0000000..b5a6233
--- /dev/null
+++ b/src/supervision/s6-notify-fd-from-socket.c
@@ -0,0 +1,145 @@
+/* ISC license. */
+
+#include <skalibs/nonposix.h>
+
+#include <sys/types.h>
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <skalibs/posixplz.h>
+#include <skalibs/uint64.h>
+#include <skalibs/types.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/envexec.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/tai.h>
+#include <skalibs/iopause.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/socket.h>
+
+#define USAGE "s6-notify-fd-from-socket [ -f ] [ -3 fd ] [ -t timeout ] prog..."
+#define dieusage() strerr_dieusage(100, USAGE)
+
+enum golb_e
+{
+ GOLB_SINGLEFORK = 0x01,
+} ;
+
+enum gola_e
+{
+ GOLA_NOTIF,
+ GOLA_TIMEOUT,
+ GOLA_N
+} ;
+
+static void bindit (int sock, char *name)
+{
+ struct sockaddr_un addr = { .sun_family = AF_UNIX, .sun_path = "" } ;
+ socklen_t addrlen = sizeof(struct sockaddr_un) ;
+ if (bind(sock, (struct sockaddr *)&addr, sizeof(sa_family_t)) == -1) /* autobind */
+ strerr_diefu1sys(111, "bind") ;
+ if (getsockname(sock, (struct sockaddr *)&addr, &addrlen) == -1)
+ strerr_diefu1sys(111, "getsockname") ;
+ if (addr.sun_path[0])
+ strerr_diefu1x(111, "autobind to an abstract socket") ;
+ memcpy(name, addr.sun_path + 1, 5) ;
+ name[5] = 0 ;
+}
+
+static inline int run_child (int sock, int fd, unsigned int timeout)
+{
+ char buf[8192] ;
+ iopause_fd x = { .fd = fd, .events = IOPAUSE_READ } ;
+ int found = 0 ;
+ tain deadline = TAIN_INFINITE_RELATIVE ;
+ tain_now_g() ;
+ if (timeout) tain_from_millisecs(&deadline, timeout) ;
+ tain_add_g(&deadline, &deadline) ;
+ while (!found)
+ {
+ int r = iopause_g(&x, 1, &deadline) ;
+ if (r == -1) strerr_diefu1sys(111, "iopause") ;
+ if (!r) strerr_dief1x(99, "timed out waiting for notification") ;
+ r = sanitize_read(fd_recv(sock, buf, 8191, 0)) ;
+ if (r == -1)
+ {
+ if (errno == EPIPE) _exit(0) ;
+ else strerr_diefu1sys(111, "recv") ;
+ }
+ if (r)
+ {
+ buf[r++] = 0 ;
+ if (!strncmp(buf, "READY=1\n", 8) || strstr(buf, "\nREADY=1\n"))
+ found = 1 ;
+ }
+ }
+ fd_write(fd, "\n", 1) ;
+ _exit(0) ;
+}
+
+static inline int read_uint (char const *file, unsigned int *fd)
+{
+ char buf[UINT_FMT + 1] ;
+ ssize_t r = openreadnclose_nb(file, buf, UINT_FMT) ;
+ if (r == -1) return -1 ;
+ buf[byte_chr(buf, r, '\n')] = 0 ;
+ return !!uint0_scan(buf, fd) ;
+}
+
+int main (int argc, char const *const *argv)
+{
+ static gol_bool const rgolb[] =
+ {
+ { .so = 'f', .lo = "no-doublefork", .clear = 0, .set = GOLB_SINGLEFORK },
+ { .so = 0, .lo = "doublefork", .clear = GOLB_SINGLEFORK, .set = 0 },
+ } ;
+ static gol_arg const rgola[] =
+ {
+ { .so = '3', .lo = "notification-fd", .i = GOLA_NOTIF },
+ { .so = 't', .lo = "timeout", .i = GOLA_TIMEOUT },
+ } ;
+ unsigned int fd = 0 ;
+ unsigned int timeout = 0 ;
+ uint64_t wgolb = 0 ;
+ char const *wgola[GOLA_N] = { 0 } ;
+ pid_t pid ;
+ int sock ;
+ unsigned int golc ;
+ char modif[21] = "NOTIFY_SOCKET=@XXXXX" ;
+ PROG = "s6-notify-fd-from-socket" ;
+
+ golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ;
+ argc -= golc ; argv += golc ;
+ if (!argc) dieusage() ;
+
+ if (wgola[GOLA_TIMEOUT] && !uint0_scan(wgola[GOLA_TIMEOUT], &timeout))
+ strerr_dief2x(100, "timeout", " must be an unsigned integer") ;
+ if (wgola[GOLA_NOTIF])
+ {
+ if (!uint0_scan(wgola[GOLA_NOTIF], &fd))
+ strerr_dief2x(100, "notification-fd", " must be an unsigned integer") ;
+ }
+ else
+ {
+ int r = read_uint("notification-fd", &fd) ;
+ if (r == -1) strerr_diefu2sys(111, "read ", "./notification-fd") ;
+ if (!r) strerr_dief2x(100, "invalid ", "./notification-fd") ;
+ }
+ if (fcntl(fd, F_GETFD) == -1)
+ strerr_dief2sys(111, "notification-fd", " sanity check failed") ;
+
+ sock = ipc_datagram_nbcoe() ;
+ if (sock == -1) strerr_diefu1sys(111, "create socket") ;
+ bindit(sock, modif + 15) ;
+
+ pid = wgolb & GOLB_SINGLEFORK ? fork() : doublefork() ;
+ if (pid == -1) strerr_diefu1sys(111, wgolb & GOLB_SINGLEFORK ? "fork" : "doublefork") ;
+ if (!pid) run_child(sock, fd, timeout) ;
+ fd_close(sock) ;
+ fd_close(fd) ;
+ xmexec_n(argv, modif, 21, 1) ;
+}
diff --git a/src/supervision/s6-notify-socket-from-fd.c b/src/supervision/s6-notify-socket-from-fd.c
new file mode 100644
index 0000000..c443b40
--- /dev/null
+++ b/src/supervision/s6-notify-socket-from-fd.c
@@ -0,0 +1,138 @@
+/* ISC license. */
+
+#include <sys/types.h>
+#include <string.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+
+#include <skalibs/uint64.h>
+#include <skalibs/types.h>
+#include <skalibs/bytestr.h>
+#include <skalibs/envexec.h>
+#include <skalibs/allreadwrite.h>
+#include <skalibs/tai.h>
+#include <skalibs/iopause.h>
+#include <skalibs/djbunix.h>
+#include <skalibs/socket.h>
+
+#define USAGE "s6-notify-socket-from-fd [ -d fd ] [ -f ] [ -t timeout ] [ -k ] prog..."
+#define dieusage() strerr_dieusage(100, USAGE)
+
+#define VAR "NOTIFY_SOCKET"
+
+enum golb_e
+{
+ GOLB_SINGLEFORK = 0x01,
+ GOLB_KEEP = 0x02,
+} ;
+
+enum gola_e
+{
+ GOLA_NOTIF,
+ GOLA_TIMEOUT,
+ GOLA_N
+} ;
+
+static inline int ipc_sendto (int fd, char const *s, size_t len, char const *path)
+{
+ struct sockaddr_un sa ;
+ size_t l = strlen(path) ;
+ if (l > IPCPATH_MAX) return (errno = ENAMETOOLONG, 0) ;
+ memset(&sa, 0, sizeof sa) ;
+ sa.sun_family = AF_UNIX ;
+ memcpy(sa.sun_path, path, l+1) ;
+ if (path[0] == '@') sa.sun_path[0] = 0 ;
+ return sendto(fd, s, len, MSG_NOSIGNAL, (struct sockaddr *)&sa, sizeof sa) >= 0 ;
+}
+
+static inline void notify_systemd (pid_t pid, char const *socketpath)
+{
+ size_t n = 16 ;
+ char fmt[16 + PID_FMT] = "READY=1\nMAINPID=" ;
+ int fd = ipc_datagram_b() ;
+ if (fd == -1) strerr_diefu1sys(111, "create socket") ;
+ n += pid_fmt(fmt + n, pid) ;
+ fmt[n++] = '\n' ;
+ if (!ipc_sendto(fd, fmt, n, socketpath))
+ strerr_diefu2sys(111, "send notification message to ", socketpath) ;
+ fd_close(fd) ;
+}
+
+static inline int run_child (int fd, unsigned int timeout, pid_t pid, char const *s)
+{
+ char dummy[4096] ;
+ iopause_fd x = { .fd = fd, .events = IOPAUSE_READ } ;
+ tain deadline = TAIN_INFINITE_RELATIVE ;
+ tain_now_g() ;
+ if (timeout) tain_from_millisecs(&deadline, timeout) ;
+ tain_add_g(&deadline, &deadline) ;
+ for (;;)
+ {
+ int r = iopause_g(&x, 1, &deadline) ;
+ if (r == -1) strerr_diefu1sys(111, "iopause") ;
+ if (!r) return 99 ;
+ r = sanitize_read(fd_read(fd, dummy, 4096)) ;
+ if (r < 0)
+ if (errno == EPIPE) return 1 ;
+ else strerr_diefu1sys(111, "read from parent") ;
+ else if (r && memchr(dummy, '\n', r)) break ;
+ }
+ fd_close(fd) ;
+ notify_systemd(pid, s) ;
+ return 0 ;
+}
+
+int main (int argc, char const *const *argv)
+{
+ static gol_bool const rgolb[] =
+ {
+ { .so = 0, .lo = "doublefork", .clear = GOLB_SINGLEFORK, .set = 0 },
+ { .so = 'f', .lo = "no-doublefork", .clear = 0, .set = GOLB_SINGLEFORK },
+ { .so = 'k', .lo = "keep-environment", .clear = 0, .set = GOLB_KEEP },
+ } ;
+ static gol_arg const rgola[] =
+ {
+ { .so = 'd', .lo = "notification-fd", .i = GOLA_NOTIF },
+ { .so = 't', .lo = "timeout", .i = GOLA_TIMEOUT },
+ } ;
+ char const *s = getenv(VAR) ;
+ unsigned int fd = 1 ;
+ unsigned int timeout = 0 ;
+ uint64_t wgolb = 0 ;
+ char const *wgola[GOLA_N] = { 0 } ;
+ unsigned int golc ;
+ PROG = "s6-notify-socket-from-fd" ;
+
+ golc = GOL_main(argc, argv, rgolb, rgola, &wgolb, wgola) ;
+ argc -= golc ; argv += golc ;
+ if (!argc) dieusage() ;
+
+ if (wgola[GOLA_NOTIF] && !uint0_scan(wgola[GOLA_NOTIF], &fd))
+ strerr_dief2x(100, "notification-fd", " must be an unsigned integer") ;
+ if (wgola[GOLA_TIMEOUT] && !uint0_scan(wgola[GOLA_TIMEOUT], &timeout))
+ strerr_dief2x(100, "timeout", " must be an unsigned integer") ;
+
+ if (!s) xexec(argv) ;
+ else
+ {
+ pid_t parent = getpid() ;
+ pid_t child ;
+ int p[2] ;
+ if (pipe(p) == -1) strerr_diefu1sys(111, "pipe") ;
+ child = wgolb & GOLB_SINGLEFORK ? fork() : doublefork() ;
+ if (child == -1) strerr_diefu1sys(111, wgolb & GOLB_SINGLEFORK ? "fork" : "doublefork") ;
+ else if (!child)
+ {
+ PROG = "s6-notify-socket-from-fd (child)" ;
+ fd_close(p[1]) ;
+ return run_child(p[0], timeout, parent, s) ;
+ }
+ fd_close(p[0]) ;
+ if (fd_move(fd, p[1]) == -1) strerr_diefu1sys(111, "fd_move") ;
+ if (wgolb & GOLB_KEEP) xexec(argv) ;
+ else xmexec_n(argv, VAR, sizeof(VAR), 1) ;
+ }
+}
diff --git a/src/usertree/deps-lib/.gitkeep b/src/usertree/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/src/usertree/deps-lib/.gitkeep