<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 7, 2017 at 1:27 PM, Aleksander Morgado <span dir="ltr"><<a href="mailto:aleksander@aleksander.es" target="_blank">aleksander@aleksander.es</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="gmail-HOEnZb"><div class="gmail-h5">On Mon, Aug 7, 2017 at 10:09 PM, Dan Williams <<a href="mailto:dcbw@redhat.com">dcbw@redhat.com</a>> wrote:<br>
> On Mon, 2017-08-07 at 11:58 -0700, Ben Chan wrote:<br>
>><br>
>><br>
>> On Mon, Aug 7, 2017 at 8:58 AM, Dan Williams <<a href="mailto:dcbw@redhat.com">dcbw@redhat.com</a>> wrote:<br>
>> > On Sun, 2017-08-06 at 13:13 +0200, Aleksander Morgado wrote:<br>
>> > > If e.g. mbim-proxy is started by ModemManager and we send a<br>
>> > Ctrl+C to<br>
>> > > it, the signal would be propagated to the mbim-proxy process and<br>
>> > we<br>
>> > > would kill it right away, while leaving ModemManager still around<br>
>> > > wondering why the socket to the proxy got a HUP.<br>
>> > ><br>
>> > > Avoid this, by making sure the mbim-proxy gets its own process<br>
>> > group.<br>
>> ><br>
>><br>
>> lgtm<br>
>><br>
>> > The way you've done it here is AFAIK the standard way to detach a<br>
>> > child<br>
>> > process and make it standalone.  We've done that for years in most<br>
>> > of<br>
>> > the things NetworkManager spawns, for example (VPN daemons, DHCP<br>
>> > daemon, avahi-autoipd, dnsmasq, teamd, etc).<br>
>> ><br>
>> > Though instead of (0,0) NM uses:<br>
>> ><br>
>> >         pid_t pid;<br>
>> ><br>
>> >         pid = getpid ();<br>
>> >         setpgid (pid, pid);<br>
>> ><br>
>> > Which I think is a bit more idiomatic.<br>
>><br>
>> Isn't that equivalent to `setpgid (0, 0)`? Is `setgpid (pid, pid)`<br>
>> preferred for some reason?<br>
><br>
> It should get called after the fork(), so it'll get the child's pid.<br>
> Maybe you read getuid() instead (which since MM is root *would* be 0?)<br>
><br>
<br>
</div></div>I believe they're equivalent, doc says:<br>
<br>
If pid is zero, then the process ID of the calling process is used.<br>
If pgid is zero, then the PGID of the process specified by pid is made<br>
the same as its process ID. So both 0 is really the same as getpid()<br>
in both.<br></blockquote><div><br></div><div>That's what I think too.  Given that `<span style="font-size:12.8px">spawn_child_setup` is run on the child process before exec(), getpid() returns the child pid. `setpgid (0, 0)` should be equivalent to `setpgid (getpid(), </span><span style="font-size:12.8px">getpid())` in such scenario. Unless there is some benefit to split the call into getpid + setpgid, </span><span style="font-size:12.8px">`setpgid (0, 0)` seems more preferable.</span></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class="gmail-HOEnZb"><font color="#888888"><br>
--<br>
Aleksander<br>
<a href="https://aleksander.es" rel="noreferrer" target="_blank">https://aleksander.es</a><br>
</font></span></blockquote></div><br></div></div>