On Sun, Mar 2, 2025, at 3:10 AM, Jan Braun wrote:
> But grepping tailsacale's source indicates that they only sdnotify
> readiness, thus you should get working and correct readiness status by
> just setting up the notification-fd.
I'm not sure how to do this, since the sd-notify protocol[1] doesn't inherit an fd; instead it looks at env var NOTIFY_SOCKET to read a path to a unix socket, which the ready service opens and uses to send datagrams. There needs to be something receiving on the other end of that socket file.
If there's a way to connect a unix datagram socket to the notification-fd provided by s6 more directly than I've done here, I'd love to know how!
> No attachment arrived here.
Attached again with a different content type.
Emily
[1]:
https://www.freedesktop.org/software/systemd/man/latest/sd_notify.html
#include <stdlib.h>
#include <skalibs/allreadwrite.h>
#include <skalibs/exec.h>
#include <skalibs/socket.h>
#include <skalibs/strerr.h>
#include <skalibs/types.h>
#define USAGE "sdnotifywrapper fd socket prog..."
int newsock(char const *p)
{
int s = ipc_datagram_coe();
if (s == -1)
return -1;
if (ipc_bind_reuse(s, p) == -1)
return -1;
return s;
}
int monitor(int nfd, int sfd)
{
pid_t pid = doublefork();
if (pid != 0)
return pid > 0 ? 0 : -1;
size_t len = 100, n;
ssize_t r;
char p[len];
for (;;) {
memset(&p, 0, sizeof p);
r = ipc_recv(sfd, p, len-1, NULL);
if (r == -1)
strerr_diefu1sys(111, "ipc_recv") ;
char *s = p;
while (s) {
char *t = strsep(&s, "\n");
if (strcmp(t, "READY=1") == 0) {
if (allwrite(nfd, "\n", 1) == -1)
strerr_diefu1sys(111, "write to nfd") ;
exit(0);
}
}
}
}
int main (int argc, char const *const *argv)
{
int nfd, sfd;
PROG = "sdnotifywrapper" ;
if ((argc < 4) || !uint0_scan(argv[1], (unsigned int *)&nfd))
strerr_dieusage(100, USAGE) ;
sfd = newsock(argv[2]);
if (sfd == -1)
strerr_diefu1sys(111, "create sock") ;
if (monitor(nfd, sfd) == -1)
strerr_diefu1sys(111, "monitor") ;
if (setenv("NOTIFY_SOCKET", argv[2], 1) == -1)
strerr_diefu1sys(111, "setenv") ;
xexec(argv+3) ;
}
Received on Mon Mar 03 2025 - 22:47:56 CET