Re: Implementing a helper for systemd's LISTEN_* environment variables using execline

2021-10-28 Thread Laurent Bercot

socket-helper { name1 /run/name1.socket name2 /run/name2.socket } prog

Currently socket-helper is a shell script, as I haven't found a way to
generate the unknown number of `s6-ipcserver-socketbinder /path/sock
fdmove N 0` using just execline. Is this socket-helper (or an
easier-to-implement analogue of it) possible in execline? I know
`getpid` allows a one-line implementation of the first environment
variable, but I'm at a loss on how to implement the last two.


 Do you mean you have a variable number of (name, socket) pairs?
 In any case, it is certainly *possible* to implement something like
this in execline, because execline is Turing-complete, but it doesn't
mean that it's easy or even a good idea. To handle a variable number
of arguments, you need to iterate over them, and maintaining a state
is difficult in execline, so it would very likely be more complicated
than is worth.
 I'd advise you to stick with your shell script. To be honest, if I were
writing such a helper, I'd make it a small C program.

 The best course of action would naturally be to convince the gpg-agent
authors that socket pre-opening (for which LISTEN_FDS is a terrible
interface but that's not our concern here) has nothing to do with
foregrounding, and they should entirely decouple these.

--
 Laurent



Implementing a helper for systemd's LISTEN_* environment variables using execline

2021-10-28 Thread Carlos Eduardo
I'm supervising the gpg-agent daemon using s6. Unfortunately, the only
official way of getting it to cooperate with a supervision suite is by
pre-opening sockets and passing information about them through
systemd's LISTEN_* (LISTEN_PID, LISTEN_FDS, LISTEN_FDNAMES)
environment variables. It'll only open the sockets itself if you pass
an argument that will background it. Thankfully it does not link
against libsystemd, and therefore s6 has all the tools needed to
fulfill this requirement.

The run script ended up being quite verbose due to all the
s6-ipcserver-socketbinder'ing, so I thought of writing a helper. The
usage I envisioned would be:

socket-helper { name1 /run/name1.socket name2 /run/name2.socket } prog

Currently socket-helper is a shell script, as I haven't found a way to
generate the unknown number of `s6-ipcserver-socketbinder /path/sock
fdmove N 0` using just execline. Is this socket-helper (or an
easier-to-implement analogue of it) possible in execline? I know
`getpid` allows a one-line implementation of the first environment
variable, but I'm at a loss on how to implement the last two.