[systemd-devel] Debugging sd_notify / tracing notifications?

Lennart Poettering lennart at poettering.net
Mon Mar 1 16:09:42 UTC 2021


On Mo, 01.03.21 10:20, John Ioannidis (systemd-devel at tla.org) wrote:

> How can I trace what sd_notify(3) calls a program makes?

strace. sd_notify() is just a wrapper around the sendmsg() syscall,
and you'll see that in strace.

> Obviously, I don't have the source, and running *strings* on it does reveal
> a *READY=1* line, but it is unclear whether the code makes it to the point
> where that gets sent.
>
> Here is what I am *really* trying to accomplish; maybe I am going about it
> the wrong way:
>
> I have some vendor code that is invoked by the following service file:
>
> *[Service]ExecStart=/opt/vendor/bin/fooRestart=alwaysUser=rootType=notifyNotifyAccess=execTimeoutStopSec=86400*

Your mailer is really broken.

> I occasionally need to send a SIGINT to the process, but finding it with
> the equivalent of ps ax | grep foo is annoying and maybe not terribly
> reliable. My first workaround was to create this script:

Try:

    systemctl show -P MainPID foobar.service

> *[Service]ExecStart=/usr/local/sbin/run-foo.shRestart=alwaysUser=root*
>
> *Type=notifyNotifyAccess=allTimeoutStopSec=86400*

You'd need to update the $NOTIFY_PID en vvar to the child process' PID
for this to work.

> the idea being that the original program will still send the *sd_notify(),* and
> I would have its pid.
>
> However, this is not happening; *systemctl start foo.service *hangs for
> about 30s, and then exits with:

Maybe the service actually checks if getppid() == 1 or so?

Lennart

--
Lennart Poettering, Berlin


More information about the systemd-devel mailing list