> 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.
Christoph Moench-Tegeder
2020-Jan-06 00:10 UTC
session mgmt: does POSIX indeed prohibit NOOP execution?
## Peter (peter at citylink.dinoex.sub.org):> 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 :(https://pubs.opengroup.org/onlinepubs/9699919799/ "The setpgid() function shall fail if: [...] The process indicated by the pid argument is a session leader." Not much room to argue? Regards, Christoph -- Spare Space