[systemd-devel] switch-root, init, SIGHUP

James Muir (jamesmui) jamesmui at cisco.com
Mon Jan 20 18:21:08 UTC 2025


> > I have a program, init-jm, that forks and executes
> > /usr/lib/systemd/systemd in the parent (using execl() ) while the
> > child collects some stats in a loop.
>
> Uh, you can do this, but it's not trivial to get right: you need to
> move yourself down the cgroup tree, because otherwise you'll collide
> with cgroup's no-processes-in-inner-cgroup-nodes rule. Create two
> cgroups in the root of the cgroup tree, then put your stuff in one,
> and invoke systemd in the other. That's the only "correct" way to do
> this, so that your stuff runs reasonably isolated from systemd.

Thanks very much for your reply.

I was not aware of this cgroup rule.  I will read more about that.

> > The child sets its argv[0][0] to '@'.
> >
> > init-jm is invoked using the "init" kernel parameter on a switch-root system (it's Fedora 41).
> >
> > Can someone explain why systemd (PID 1) sends SIGHUP to the child?
>
> Are you sure you are setting argv[0][0] properly? the killing spree we
> do on switch root should exclude processes marked like that.

When I check /proc/<pid>/cmdline, I see the '@' character.

It is not clear to me if the '@' is necessary because the process is invoked using the "init" kernel parameter.

Doesn't that mean it gets executed after the switch-root killing spree? (i.e. it gets executed when PID 1 from the initial ramdisk re-executes to run the new init).

I think the SIGHUP must come from the new PID 1.

> Note that we'll also possibly reinitialize the tty on switch root,
> maybe your tool has the tty open and gets a SIGHUP because of that.

Brian M also suggested that might be the cause, but I don't see any ttys when I do "ls -l /proc/<pid>/fd".

This pattern (fork and exec /usr/lib/systemd/systemd in the parent) is used by systemd-bootchart.

If you invoke systemd-bootchart using the "init" kernel parameter on Fedora 41 (which is the recommended way), then you will hit this SIGHUP (and bootchart exits when it receives SIGHUP, so this breaks it).

That appears to have been not working for a while (e.g. it does not work with systemd v251).

There is an strace log here:  https://github.com/systemd/systemd-bootchart/issues/58

-James M
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20250120/6513ce6d/attachment-0001.htm>


More information about the systemd-devel mailing list