Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 05 Jan 2020 23:41:32 +0100
From:      Peter <peter@citylink.dinoex.sub.org>
To:        freebsd-stable@FreeBSD.ORG
Subject:   session mgmt: does POSIX indeed prohibit NOOP execution?
Message-ID:  <op.0dxynipoaas8k8@localhost>

next in thread | raw e-mail | index | archive | help
>    pgrp = getpid();
>    if(setpgid(0, pgrp) < 0)
>        err(1, "setpgid");

This appears to me a program trying to deemonize itself (in the old style  
when there was only job control but no session management).

In the case this program is already properly daemonized, e.g. by starting  
it from /usr/sbin/daemon, this code now fails, invoking the err() clause  
and thereby aborting.

 From what I could find out, POSIX does not allow a session leader to do  
setpgid() on itself.
When a program is invoked via /usr/sbin/daemon, it should already be  
session leader AND group leader, and then the above code WOULD be a NOOP,  
unless POSIX would require the setpgid() to fail and thereby the program  
to abort - which, btw, is NOT a NOOP :(

So, where is the mistake here?

Option 1: I have completely misunderstood something. Then please tell me  
what.
Option 2: The quoted code is bogus. Then why is it in base?
option 3: The setpgid() behaviour is bogus. It may stop a session leader  
 from executing it, but it should detect a NOOP and just go thru with it.  
Then why don't we fix that?
Option 4: POSIX is bogus. Unlikely, because as far as I could find out,  
that part of it was written following the Berkeley implementation.



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?op.0dxynipoaas8k8>