Skip to content

Commit be3c3a0

Browse files
authored
bpo-35823: Allow setsid() after vfork() on Linux. (GH-22945)
It should just be a syscall updating a couple of fields in the kernel side process info. Confirming, in glibc is appears to be a shim for the setsid syscall (based on not finding any code implementing anything special for it) and in uclibc (*much* easier to read) it is clearly just a setsid syscall shim. A breadcrumb _suggesting_ that it is not allowed on Darwin/macOS comes from a commit in emacs: https://lists.gnu.org/archive/html/bug-gnu-emacs/2017-04/msg00297.html but I don't have a way to verify if that is true or not. As we are not supporting vfork on macOS today I just left a note in a comment.
1 parent 8cd1dba commit be3c3a0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Modules/_posixsubprocess.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
#if defined(__linux__) && defined(HAVE_VFORK) && defined(HAVE_SIGNAL_H) && \
4040
defined(HAVE_PTHREAD_SIGMASK) && !defined(HAVE_BROKEN_PTHREAD_SIGMASK)
41+
/* If this is ever expanded to non-Linux platforms, verify what calls are
42+
* allowed after vfork(). Ex: setsid() may be disallowed on macOS? */
4143
# include <signal.h>
4244
# define VFORK_USABLE 1
4345
#endif
@@ -712,7 +714,6 @@ do_fork_exec(char *const exec_array[],
712714
#ifdef VFORK_USABLE
713715
if (child_sigmask) {
714716
/* These are checked by our caller; verify them in debug builds. */
715-
assert(!call_setsid);
716717
assert(!call_setuid);
717718
assert(!call_setgid);
718719
assert(!call_setgroups);
@@ -997,7 +998,7 @@ subprocess_fork_exec(PyObject* self, PyObject *args)
997998
/* Use vfork() only if it's safe. See the comment above child_exec(). */
998999
sigset_t old_sigs;
9991000
if (preexec_fn == Py_None &&
1000-
!call_setuid && !call_setgid && !call_setgroups && !call_setsid) {
1001+
!call_setuid && !call_setgid && !call_setgroups) {
10011002
/* Block all signals to ensure that no signal handlers are run in the
10021003
* child process while it shares memory with us. Note that signals
10031004
* used internally by C libraries won't be blocked by

0 commit comments

Comments
 (0)