Commit Graph

20 Commits

Author SHA1 Message Date
DaanDeMeyer
33a5cc768c socket-activate: Always send NOTIFY=ready
Even if we're not using --accept=, it's very useful to be able to
synchronize on systemd-socket-activate having binded to its listen
socket, so let's always send READY=1. This means the payload can't
send READY=1 anymore but it's doubtful whether that's useful in this
case in the first place.
2025-07-10 16:19:46 +02:00
Mike Yuan
151efb6d13 socket-activate: normalize COMMAND notation in help text + man 2025-06-25 13:34:41 +02:00
Daniel Foster
9e940164e9 socket-activate: add --now option
Add a --now option that starts the program instantly, instead of waiting for a
connection on the socket. This is useful, for instance, when developing:

Say I have a Rust, socket-activated web service. I can test it with:
systemd-socket-activate -l 8080 --fdname=http cargo run

However this delays running the service (which potentially involves compilation)
to when I try to connect to it, which wastes time. Since it delays compilation,
I also don't see any warning or errors in the code until it gets a connection
either.

The name's now a bit of a misnomer, since starting the service immediately isn't
really socket activation, but oh well ¯\_(ツ)_/⁻
2025-06-10 13:38:33 +10:00
Daniel Foster
dfbda58c33 socket-activate: validate more argument combinations earlier in runtime
Check user configuration errors and warnings (e.g. more than one socket passed
with --inetd) earlier in runtime. There's no reason not to do this, and it means
invalid configuration will be reported to the user earlier.

Also let the user know that --fdname= has no effect with --inetd.
2025-06-10 13:38:33 +10:00
Daan De Meyer
86b9a3e31d tree-wide: Clean up includes
This removes more unused includes from the components already cleaned
up in #37467 and #37457.

Split out of #37344.
2025-05-21 10:49:42 +02:00
Daan De Meyer
8857aa74e5 tree-wide: Clean up includes
This commit cleans up the includes for all the small tools across
the tree.

A few cases of returning EXIT_SUCCESS are replaced with returning
0 to avoid including <stdlib.h>.

Split out of #37344.
2025-05-14 22:34:02 +02:00
Daan De Meyer
792a8bfb8a daemon-util: Rename starting/stopping message constants
Currently, NOTIFY_READY from daemon-util.h conflicts with NOTIFY_READY
from NotifyState from service.h so let's rename the constants to avoid
the conflict.
2025-05-01 14:02:17 +02:00
Mike Yuan
2a2531b6c7 socket-activate: drop unused accept param for open_sockets() 2025-05-01 13:10:26 +09:00
Mike Yuan
93fcf15ae4 socket-activate: set up SIGCHLD handler only in --accept mode 2025-04-27 20:32:36 +02:00
Mike Yuan
3bff4701d8 socket-activate: signal READY=1 once sockets are open for --accept mode 2025-04-27 20:26:42 +02:00
Mike Yuan
8a157f78f2 socket-activate: clean up control flow a bit 2025-04-27 20:21:10 +02:00
Mike Yuan
0964b022fa socket-activate: remove effectively unused 'name' param for exec_process() 2025-04-27 20:21:10 +02:00
Mike Yuan
7e672795be socket-activate: drop arg_args
To follow our usual coding style.
2025-04-27 20:21:10 +02:00
Lennart Poettering
afdca6c6c2 nspawn,run,machinectl,socket-activate: propagate $COLORTERM + $NO_COLOR
When we pass information about our calling terminal on to some service
or command we invoke, propagate $COLORTERM + $NO_COLOR in addition to
$TERM, in order to always consider the triplet of the three env vars the
real deal.
2025-03-17 10:17:54 +01:00
Mike Yuan
70923ed358 meson: enable -Wzero-as-null-pointer-constant
Support for C added in gcc 15:
236c0829ee
2025-01-16 02:26:56 +01:00
Daan De Meyer
aa976d8788 tree-wide: Use log_setup() everywhere
Otherwise the default log target is the console and we won't use
the journal socket even if it is available.
2024-04-25 17:06:43 +02:00
Lennart Poettering
e9ccae3135 process-util: add new FORK_DEATHSIG_SIGKILL flag, rename FORK_DEATHSIG → FORK_DEATHSIG_SIGTERM
Sometimes it makes sense to hard kill a client if we die. Let's hence
add a third FORK_DEATHSIG flag for this purpose: FORK_DEATHSIG_SIGKILL.

To make things less confusing this also renames FORK_DEATHSIG to
FORK_DEATHSIG_SIGTERM to make clear it sends SIGTERM. We already had
FORK_DEATHSIG_SIGINT, hence this makes things nicely symmetric.

A bunch of users are switched over for FORK_DEATHSIG_SIGKILL where we
know it's safe to abort things abruptly. This should make some kernel
cases more robust, since we cannot get confused by signal masks or such.

While we are at it, also fix a bunch of bugs where we didn't take
FORK_DEATHSIG_SIGINT into account in safe_fork()
2023-11-02 14:09:23 +01:00
Frantisek Sumsal
be492020ec tree-wide: a bunch of Coccinelle-suggested tweaks
rc2 edition
2023-07-14 22:49:01 +01:00
Frantisek Sumsal
9ccd59f751 socket-activate: make a copy of the command name and arguments
When we call safe_fork() with the first argument set (process name), we
call rename_process() that zeroes out saved argv (that was saved by
save_argc_argv() in the main func defined by DEFINE_MAIN_FUNC()). In this
case this means that with --accept both the target executable name and
its arguments will be empty strings:

```
$ systemd-socket-activate --accept --listen 1111 cat &
Listening on [::]:1111 as 3.
$ curl localhost:1111
Communication attempt on fd 3.
Connection from 127.0.0.1:52948 to [::ffff:127.0.0.1]:1111
Spawned cat (cat) as PID 10576.
Execing  ()
Failed to execp  (): No such file or directory
Child 10576 died with code 1
curl: (56) Recv failure: Connection reset by peer
```

Let's make a copy of the necessary arguments beforehand and use it
instead to fix this.
2023-06-16 20:42:43 +02:00
Frantisek Sumsal
7f4544c9bc activate: rename to socket-activate
To make the naming consistent with the rest of the utils, i.e. binary
name minus the systemd- prefix.
2023-06-14 20:39:10 +02:00