[systemd-devel] Help with making socket activation work.

Stef Bon stefbon at gmail.com
Fri Jun 27 11:59:15 UTC 2025


Hi,

I've got a system daemon, and I want to make use of socket activation. It has a
socket /run/osns/system.sock, where clients belonging to user sessions
can connect to.

What I've tried I do not get it to work.
It used to fork, and the forked process created the socket. I've
changed this using the code on
http://0pointer.de/blog/projects/socket-activation.html

the osns-system.socket file:

[Socket]
ListenStream=/run/osns/system.sock

[Install]
WantedBy=socket.target

and osns-system.service file

[Unit]
Description=OSNS System Service
After=syslog.target

[Service]
Type=forking
KillMode=process
ExecStart=/usr/libexec/osns/osnssystem
Restart=no

[Install]
WantedBy=multi-user.target

I've used sd-listen_fds to get the fd when the socket
/run/osns/system.sock is created, but there is none. The environment
var LISTEN_PID is the pid of the process before forking. So the
session manager is not aware of the new main process. So I've added

PIDFile=/run/osns/osns-system.pid

to the [Service], but no effect.
I've changed the Type to notify, and make sd aware of the new pid
using sd_notifyf(0, "READY=1\n" "MAINPID=%lu", (unsigned long) pid)
where the pid is of the new forked process.
I've used this call in the starting process, and when that did not
work, used it in the new forked process.
That also did not work. The environment var LISTEN_PID remains the pid
of the starting process.
What is wrong?

S. Bon


More information about the systemd-devel mailing list