Dear Austin Group,

may I ask a question regarding posix_spawn().

Based on my understanding, posix_spawn() in its current form does not
provide sufficient functionality to replace the fork/exec sequence when
implementing a POSIX shell. This is why shells such as fish who attempted
to use it for this purpose had to switch back to fork/exec [1].

As you probably recall, the reason this functionality is necessary is
because the parent process cannot perform this action until after it learns
of the child's process (group) id, by which time the child may already act
under the assumption that it has terminal ownership (and might then be
suspended with SIGTTOU/SIGTTIN). In a fork/exec implementation, the call to
tcsetpgrp is made by the child process prior to exec'ing the new program.

Some vendors (e.g., Blackberry 10 OS) have added extension flags to
posix_spawn [2], one of which is POSIX_SPAWN_TCSETPGROUP.  IBM's zOS
2.4.0's spawn call supports this functionality in similar form as well [5].

While researching the mailing list archives, I discovered that in 2016 a
proposal was accepted by this group [3] to support setting the session
(POSIX_SPAWN_SETSID), which is supported in GNU libc as of 2017 [4].

Based on my own experience working with shells, I believe that the lack of
the ability to set the foreground process group of the controlling terminal
may be the only (?) missing functionality that prevents posix_spawn() from
being used in lieu of fork/exec by a POSIX job control shell. (I am
ignoring posix_spawn's limited ability to report errors in its file spawn
actions in this argument.) Others have put forth arguments in favor of
improving posix_spawn, most recently Baumann et al in their HotOS'19 paper
[6].

My question is whether my assessment is correct and if it were, are there
efforts to require support for setting the controlling
terminal's foreground process group to posix_spawn so that it could be used
as a fork/exec replacement for POSIX job control shells?

 - Godmar

References:
[1]
https://github.com/fish-shell/fish-shell/commit/5e371e8fe7cbdecd87678d50d06c12851213776e
[2]
https://developer.blackberry.com/native/reference/core/com.qnx.doc.neutrino.lib_ref/topic/p/posix_spawnattr_setxflags.html
[3] https://www.austingroupbugs.net/view.php?id=1044
[4] https://sourceware.org/bugzilla/show_bug.cgi?id=21340
[5]
https://www.ibm.com/docs/en/zos/2.4.0?topic=functions-spawn-spawnp-spawn-new-process
[6]
https://www.microsoft.com/en-us/research/uploads/prod/2019/04/fork-hotos19.pdf

Reply via email to