<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:12.0pt;
font-family:"Aptos",sans-serif;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Aptos",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-CA" link="#467886" vlink="#96607D" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">> > It is not clear to me if the '@' is necessary because the process is<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > invoked using the "init" kernel parameter.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> That detail doesn't matter. It's irrelevant how the process gets<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> started. In particular as I understand you you fork()ed once,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> i.e. init= starts PID 1, but this is not PID 1 we are talking about<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> here...<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I did not mean to imply that a process forked from "init=" gets special treatment.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I only mentioned "init=" because I think it implies an ordering wrt the switch-root killing spree.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > Doesn't that mean it gets executed after the switch-root killing<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > spree? (i.e. it gets executed when PID 1 from the initial ramdisk<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > re-executes to run the new init).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> do you actually invoke the systemd binary in the initrd already, and<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> the ask it to switch root, or how does that work?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I am working with a vanilla Fedora 41 image. systemd runs as PID 1 in the initrd.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">The process I specify using "init=" is invoked as part of the normal switch-root flow (when systemd from the initrd calls execve() ).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > I think the SIGHUP must come from the new PID 1.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> sigaction() actually tells you exactly where a signal comes from, if<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> you let it via the siginfo_t structure optionally delivered to your<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> signal handler. hence you can relatively easily figure this out. The<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> si_pid specifies the source pid. And si_code tells you if this was<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> sent by the kernel or by userspace, i.e. SI_KERNEL, SI_USER and so on.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">The strace log I pointed to shows PID 1 sent the signal.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">However, there is PID 1 from the initrd and the new PID 1 from the real root file system.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">It must be the new PID 1 that sends the SIGHUP.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > Note that we'll also possibly reinitialize the tty on switch root,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > > maybe your tool has the tty open and gets a SIGHUP because of that.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> ><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > Brian M also suggested that might be the cause, but I don't see any<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > ttys when I do "ls -l /proc/<pid>/fd".<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> <o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> it's not so much about that, but about which ctty your process has.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">There is no controlling tty listed in the output of "ps".<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">-James M<o:p></o:p></span></p>
<div id="mail-editor-reference-message-container">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>