Re: switch-root, init, SIGHUP

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi James,

On Sat, Jan 18, 2025 at 05:40:17AM +0000, James Muir (jamesmui) wrote:
> 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.
> 
> 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?
> 
> This happens just before the statement log_execution_mode(&first_boot) is
> executed inside main().
> 
> Sending SIGHUP to the child seems to be particular to the re-execution of
> the systemd binary during switch-root because it is not sent when init-jm is
> invoked using “rdinit”.

I suspect that your process has a controlling tty based on this comment
in the killall() function at src/shared/killall.c:

    if (send_sighup) {
            /* Optionally, also send a SIGHUP signal, but only if the process has a controlling
             * tty. This is useful to allow handling of shells which ignore SIGTERM but react to
             * SIGHUP. We do not send this to processes that have no controlling TTY since we
             * don't want to trigger reloads of daemon processes. Also we make sure to only send
             * this after SIGTERM so that SIGTERM is always first in the queue. */
             ...
    }

Also systemd >= v255 (Fedora 41 has v256) has the directive
SurviveFinalKillSignal=yes that can be used instead of setting
argv[0][0] = '@'.

Brian




[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux