<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;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:#467886;
        text-decoration:underline;}
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">
<div id="mail-editor-reference-message-container">
<div>
<div>
<div>
<p class="MsoNormal"><span style="font-size:11.0pt">> > I have a program, init-jm, that forks and executes<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > /usr/lib/systemd/systemd in the parent (using execl() ) while the<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> > child collects some stats in a loop.<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">> Uh, you can do this, but it's not trivial to get right: you need to<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> move yourself down the cgroup tree, because otherwise you'll collide<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> with cgroup's no-processes-in-inner-cgroup-nodes rule. Create two<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> cgroups in the root of the cgroup tree, then put your stuff in one,<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> and invoke systemd in the other. That's the only "correct" way to do<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> this, so that your stuff runs reasonably isolated from systemd.<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">Thanks very much for your reply.<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 was not aware of this cgroup rule.  I will read more about 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">> > The child sets its argv[0][0] to '@'.<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">> > init-jm is invoked using the "init" kernel parameter on a switch-root system (it's Fedora 41).<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">> > Can someone explain why systemd (PID 1) sends SIGHUP to the child?<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">> Are you sure you are setting argv[0][0] properly? the killing spree we<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">> do on switch root should exclude processes marked like 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">When I check /proc/<pid>/cmdline, I see the '@' character.<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 is not clear to me if the '@' is necessary because the process is 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">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).<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">> 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 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">This pattern (fork and exec /usr/lib/systemd/systemd in the parent) is used by systemd-bootchart.<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">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).<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 appears to have been not working for a while (e.g. it does not work with systemd v251).<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 an strace log here: 
<a href="https://github.com/systemd/systemd-bootchart/issues/58">https://github.com/systemd/systemd-bootchart/issues/58</a><br>
<br>
<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">-James M<o:p></o:p></span></p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>