From 8a5a621baa9e756b34c507c3d8e2119dabe7f630 Mon Sep 17 00:00:00 2001
From: Laurent Bercot
Date: Thu, 9 Apr 2026 02:31:43 +0000
Subject: 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
---
INSTALL | 2 +-
NEWS | 1 +
doc/index.html | 58 +++++----
doc/s6-notify-fd-from-socket.html | 110 ++++++++++++++++
doc/s6-notify-socket-from-fd.html | 129 +++++++++++++++++++
doc/upgrade.html | 3 +
package/deps.mak | 6 +
package/modes | 2 +
package/targets.mak | 2 +
src/alias/deps-lib/.gitkeep | 0
src/conn-tools/deps-lib/.gitkeep | 0
src/daemontools-extras/deps-lib/.gitkeep | 0
src/fdholder/deps-lib/.gitkeep | 0
src/include-local/.gitkeep | 0
src/include-local/s6lockd.h | 8 --
src/instance/deps-lib/.gitkeep | 0
src/libs6/s6-ftrigrd.c | 2 +-
src/pipe-tools/deps-lib/.gitkeep | 0
src/supervision/deps-exe/s6-notify-fd-from-socket | 3 +
src/supervision/deps-exe/s6-notify-socket-from-fd | 3 +
src/supervision/deps-lib/.gitkeep | 0
src/supervision/s6-notify-fd-from-socket.c | 145 ++++++++++++++++++++++
src/supervision/s6-notify-socket-from-fd.c | 138 ++++++++++++++++++++
src/usertree/deps-lib/.gitkeep | 0
24 files changed, 577 insertions(+), 35 deletions(-)
create mode 100644 doc/s6-notify-fd-from-socket.html
create mode 100644 doc/s6-notify-socket-from-fd.html
create mode 100644 src/alias/deps-lib/.gitkeep
create mode 100644 src/conn-tools/deps-lib/.gitkeep
create mode 100644 src/daemontools-extras/deps-lib/.gitkeep
create mode 100644 src/fdholder/deps-lib/.gitkeep
create mode 100644 src/include-local/.gitkeep
delete mode 100644 src/include-local/s6lockd.h
create mode 100644 src/instance/deps-lib/.gitkeep
create mode 100644 src/pipe-tools/deps-lib/.gitkeep
create mode 100644 src/supervision/deps-exe/s6-notify-fd-from-socket
create mode 100644 src/supervision/deps-exe/s6-notify-socket-from-fd
create mode 100644 src/supervision/deps-lib/.gitkeep
create mode 100644 src/supervision/s6-notify-fd-from-socket.c
create mode 100644 src/supervision/s6-notify-socket-from-fd.c
create mode 100644 src/usertree/deps-lib/.gitkeep
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.
- Supervision system
+ Supervision system
s6-svscan and s6-supervise
@@ -180,17 +180,24 @@ a user interface to control those processes and monitor service states.
The s6-svperms program
The s6-svlink program
The s6-svunlink program
-The s6-svwait program
-The s6-svlisten1 program
-The s6-svlisten program
-The s6-notifyoncheck program
The s6-svdt program
The s6-svdt-clear program
The s6-permafailon program
The s6-background-watch program
- Daemontools-like utilities
+ Readiness notification for supervised services
+
+
+
+
These programs are a rewrite of the corresponding utilities from
@@ -211,14 +218,13 @@ a few extras.
The s6-tai64nlocal program
- Fifodir management, notification and subscription
+ Fifodir management, notification and subscription
-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
inter-process notification and
-synchronization.
+synchronization. They're a generalized interface to the same
+mechanisms used by tools like s6-svwait.
- Local service management and access control
+ Unix domain super-server, local service management and access control
- suidless privilege gain
+ suidless privilege gain
- Logging
+ Logging
- Management of user supervision trees
+ Management of user supervision trees
- Management of dynamic instances
+ Management of dynamic instances
- fd-holding, a.k.a. the sensible part of socket activation
+ fd-holding, a.k.a. the sensible part of socket activation
- The s6-fdholder-daemon program
@@ -334,10 +340,9 @@ synchronization.
s6 manual pages
Other components for s6-based init systems
@@ -346,10 +351,13 @@ as a set of man pages.
- s6-linux-init
is a package to help you create a /sbin/init binary booting a
Linux system with s6-svscan as process 1.
- - s6-overlay
-is a project that automates integration of s6 into Docker images.
- s6-rc is a
dependency-based service manager for s6.
+ - s6-frontend is
+a friendlier user interface to address the complete s6 ecosystem (this
+package, s6-linux-init and s6-rc).
+ - s6-overlay
+is a project that automates integration of s6 into Docker images.
- anopa is another dependency-based
service manager for s6.
- 66 is another
@@ -362,8 +370,8 @@ service manager working on top of s6.
- s6 is discussed on the
supervision mailing-list.
- - There is a #s6 IRC channel on OFTC. Sometimes people are there
-and answer questions.
+ - There is a #s6 IRC channel on OFTC. It hosts most discussions
+around supervision topics, and skaware in general.
Similar work
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 @@
+
+
+
+
+
+
+ s6: the s6-notify-fd-from-socket program
+
+
+
+
+
+
+
+s6
+Software
+skarnet.org
+
+
+ The s6-notify-fd-from-socket
+
+
+s6-notify-fd-from-socket is meant to be used in a run script,
+when you want to use s6 to supervise a program that follows systemd's
+NOTIFY_SOCKET
+protocol. It converts a readiness notification sent via that protocol
+into s6's native format.
+
+
+ Interface
+
+
+ s6-notify-fd-from-socket [ -3 fd ] [ -f ] [ -t timeout ] prog...
+
+
+
+ - s6-notify-fd-from-socket doubleforks and runs as the grandchild;
+the parent immediately execs into prog..., which is expected to use the
+NOTIFY_SOCKET protocol.
+ - If prog dies before sending its notification, or if the timeout
+(if any) expires, s6-notify-fd-from-socket just exits.
+ - If prog notifies readiness, s6-notify-fd-from-socket
+writes a newline to the file descriptor configured for the service,
+then it exits.
+
+
+ Exit codes
+
+
+ s6-notify-fd-from-socket can exit before executing into prog:
+
+
+
+ - 100: wrong usage
+ - 111: system call failed
+
+
+
+ After forking, s6-notify-fd-from-socket (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:
+
+
+
+ - 0: service readiness achieved and notification sent
+ - 99: timed out before readiness was achieved
+ - 111: system call failed
+
+
+ Options
+
+
+ - -3 fd, --notification-fd=fd
+ - Force writing the readiness notification to descriptor fd. By default,
+the notification is sent to the descriptor written in the notification-fd
+file of the service directory, and it is an error if this file does not exist
+(because the supervisor needs to be prepared to
+receive the notification).
+
+ - -t timeout, --timeout=timeout
+ - Exit without notifying the supervisor if prog hasn't notified
+readiness after timeout milliseconds. Default is 0,
+meaning infinite: s6-notify-fd-from-socket will wait forever for
+a notification, up to when prog exits.
+
+ - -f, --no-doublefork
+ - Make s6-notify-fd-from-socket live as a direct child of
+prog rather than doubleforking. It is less costly (it might
+save a millisecond), but it will leave a zombie around if prog
+does not know how to reap its bastards (children it doesn't know it has).
+If prog reaps everything, you can safely use this option;
+otherwise, leave it alone.
+
+
+ Notes
+
+
+ - s6-notify-fd-from-socket 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
+s6-notify-socket-from-fd program
+instead.
+
+
+
+
+
+
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 @@
+
+
+
+
+
+
+ s6: the s6-notify-socket-from-fd program
+
+
+
+
+
+
+
+s6
+Software
+skarnet.org
+
+
+ The s6-notify-socket-from-fd program
+
+
+s6-notify-socket-from-fd 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 not using s6, but another
+service manager that does not support the
+s6 readiness notification protocol,
+but supports the
+NOTIFY_SOCKET
+protocol.
+
+
+
+ Typically, you would use it if you have a daemon foobard that
+uses the s6 readiness notification protocol, but need to run that daemon
+under systemd. Instead of running it with ExecStart=foobard and
+having to use Type=main, losing the benefit of notification, you
+can use ExecStart="s6-notify-socket-from-fd foobard" and
+Type=notify, and systemd will handle readiness correctly.
+
+
+ Interface
+
+
+ s6-notify-socket-from-fd [ -d fd ] [ -f ] [ -t timeout ] [ -k ] prog...
+
+
+
+ - If the NOTIFY_SOCKET environment variable isn't defined,
+it means that s6-notify-socket-from-fd is not running under a
+supervisor expecting a systemd-style readiness notification. So it does nothing
+and just execs into prog.... If the variable is defined, the
+following points apply.
+ - s6-notify-socket-from-fd doubleforks and runs as the grandchild;
+the parent immediately execs into prog..., which is expected to use the
+s6 readiness notification protocol.
+ - If prog dies before sending its notification, or if the timeout
+(if any) expires, s6-notify-socket-from-fd just exits.
+ - If prog notifies readiness, s6-notify-socket-from-fd
+sends a systemd-style notification to the supervisor listening to the socket
+given in NOTIFY_SOCKET, then it exits.
+
+
+ Exit codes
+
+
+ s6-notify-socket-from-fd can exit before executing into prog:
+
+
+
+ - 100: wrong usage
+ - 111: system call failed
+
+
+
+ After forking, s6-notify-socket-from-fd (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:
+
+
+
+ - 0: service readiness achieved and notification sent
+ - 99: timed out before readiness was achieved
+ - 111: system call failed
+
+
+ Options
+
+
+ - -d fd, --notification-fd=fd
+ - Expect prog... to send its notification on descriptor fd.
+Default is 1.
+
+ - -t timeout, --timeout=timeout
+ - Exit without notifying the supervisor if prog hasn't notified
+readiness after timeout milliseconds. Default is 0,
+meaning infinite: s6-notify-socket-from-fd will wait forever for
+a notification, up to when prog exits.
+
+ - -f, --no-doublefork
+ - Make s6-notify-socket-from-fd live as a direct child of
+prog rather than doubleforking. It is less costly (it might
+save a millisecond), but it will leave a zombie around if prog
+does not know how to reap its bastards (children it doesn't know it has).
+If prog reaps everything, you can safely use this option;
+otherwise, leave it alone.
+
+ - -k, --keep-environment
+ - Keep the NOTIFY_SOCKET environment variable in prog's
+environment. By default, the variable is removed from it, because prog,
+not using the systemd notification protocol, normally has no use for it.
+
+
+ Notes
+
+
+ - This program was previously available on skarnet.org outside of any
+package, under the name sdnotify-wrapper.
+ - s6-notify-socket-from-fd 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
+s6-notify-fd-from-socket program
+instead.
+
+
+
+
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
The API of the ftrigr library
is somewhat different. .
+ New binaries:
+s6-notify-fd-from-socket,
+s6-notify-socket-from-fd.
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
diff --git a/src/conn-tools/deps-lib/.gitkeep b/src/conn-tools/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/src/daemontools-extras/deps-lib/.gitkeep b/src/daemontools-extras/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/src/fdholder/deps-lib/.gitkeep b/src/fdholder/deps-lib/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/src/include-local/.gitkeep b/src/include-local/.gitkeep
new file mode 100644
index 0000000..e69de29
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
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
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
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
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#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
+#include
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#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
--
cgit v1.3.1