Skip to content

Commit 73245d0

Browse files
authored
gh-94518: Rename group* to extra_group* to avoid confusion (#101054)
* Rename `group*` to `extra_group*` to avoid confusion * Rename `num_groups` into `extra_group_size` * Rename `groups_list` to `extra_groups_packed`
1 parent b400219 commit 73245d0

File tree

2 files changed

+31
-28
lines changed

2 files changed

+31
-28
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Group-related variables of ``_posixsubprocess`` module are renamed to
2+
stress that supplimentary group affinity is added to a fork, not
3+
replace the inherited ones. Patch by Oleg Iarygin.

Modules/_posixsubprocess.c

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ child_exec(char *const exec_array[],
519519
int close_fds, int restore_signals,
520520
int call_setsid, pid_t pgid_to_set,
521521
gid_t gid,
522-
Py_ssize_t groups_size, const gid_t *groups,
522+
Py_ssize_t extra_group_size, const gid_t *extra_groups,
523523
uid_t uid, int child_umask,
524524
const void *child_sigmask,
525525
PyObject *py_fds_to_keep,
@@ -619,8 +619,8 @@ child_exec(char *const exec_array[],
619619
#endif
620620

621621
#ifdef HAVE_SETGROUPS
622-
if (groups_size > 0)
623-
POSIX_CALL(setgroups(groups_size, groups));
622+
if (extra_group_size > 0)
623+
POSIX_CALL(setgroups(extra_group_size, extra_groups));
624624
#endif /* HAVE_SETGROUPS */
625625

626626
#ifdef HAVE_SETREGID
@@ -725,7 +725,7 @@ do_fork_exec(char *const exec_array[],
725725
int close_fds, int restore_signals,
726726
int call_setsid, pid_t pgid_to_set,
727727
gid_t gid,
728-
Py_ssize_t groups_size, const gid_t *groups,
728+
Py_ssize_t extra_group_size, const gid_t *extra_groups,
729729
uid_t uid, int child_umask,
730730
const void *child_sigmask,
731731
PyObject *py_fds_to_keep,
@@ -740,7 +740,7 @@ do_fork_exec(char *const exec_array[],
740740
/* These are checked by our caller; verify them in debug builds. */
741741
assert(uid == (uid_t)-1);
742742
assert(gid == (gid_t)-1);
743-
assert(groups_size < 0);
743+
assert(extra_group_size < 0);
744744
assert(preexec_fn == Py_None);
745745

746746
pid = vfork();
@@ -777,7 +777,7 @@ do_fork_exec(char *const exec_array[],
777777
p2cread, p2cwrite, c2pread, c2pwrite,
778778
errread, errwrite, errpipe_read, errpipe_write,
779779
close_fds, restore_signals, call_setsid, pgid_to_set,
780-
gid, groups_size, groups,
780+
gid, extra_group_size, extra_groups,
781781
uid, child_umask, child_sigmask,
782782
py_fds_to_keep, preexec_fn, preexec_fn_args_tuple);
783783
_exit(255);
@@ -793,20 +793,20 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
793793
PyObject *env_list, *preexec_fn;
794794
PyObject *process_args, *converted_args = NULL, *fast_args = NULL;
795795
PyObject *preexec_fn_args_tuple = NULL;
796-
PyObject *groups_list;
796+
PyObject *extra_groups_packed;
797797
PyObject *uid_object, *gid_object;
798798
int p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite;
799799
int errpipe_read, errpipe_write, close_fds, restore_signals;
800800
int call_setsid;
801801
pid_t pgid_to_set = -1;
802-
gid_t *groups = NULL;
802+
gid_t *extra_groups = NULL;
803803
int child_umask;
804804
PyObject *cwd_obj, *cwd_obj2 = NULL;
805805
const char *cwd;
806806
pid_t pid = -1;
807807
int need_to_reenable_gc = 0;
808808
char *const *exec_array, *const *argv = NULL, *const *envp = NULL;
809-
Py_ssize_t arg_num, num_groups = 0;
809+
Py_ssize_t arg_num, extra_group_size = 0;
810810
int need_after_fork = 0;
811811
int saved_errno = 0;
812812
int allow_vfork;
@@ -819,7 +819,7 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
819819
&p2cread, &p2cwrite, &c2pread, &c2pwrite,
820820
&errread, &errwrite, &errpipe_read, &errpipe_write,
821821
&restore_signals, &call_setsid, &pgid_to_set,
822-
&gid_object, &groups_list, &uid_object, &child_umask,
822+
&gid_object, &extra_groups_packed, &uid_object, &child_umask,
823823
&preexec_fn, &allow_vfork))
824824
return NULL;
825825

@@ -895,41 +895,41 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
895895
cwd = NULL;
896896
}
897897

898-
if (groups_list != Py_None) {
898+
if (extra_groups_packed != Py_None) {
899899
#ifdef HAVE_SETGROUPS
900-
if (!PyList_Check(groups_list)) {
900+
if (!PyList_Check(extra_groups_packed)) {
901901
PyErr_SetString(PyExc_TypeError,
902902
"setgroups argument must be a list");
903903
goto cleanup;
904904
}
905-
num_groups = PySequence_Size(groups_list);
905+
extra_group_size = PySequence_Size(extra_groups_packed);
906906

907-
if (num_groups < 0)
907+
if (extra_group_size < 0)
908908
goto cleanup;
909909

910-
if (num_groups > MAX_GROUPS) {
911-
PyErr_SetString(PyExc_ValueError, "too many groups");
910+
if (extra_group_size > MAX_GROUPS) {
911+
PyErr_SetString(PyExc_ValueError, "too many extra_groups");
912912
goto cleanup;
913913
}
914914

915-
/* Deliberately keep groups == NULL for num_groups == 0 */
916-
if (num_groups > 0) {
917-
groups = PyMem_RawMalloc(num_groups * sizeof(gid_t));
918-
if (groups == NULL) {
915+
/* Deliberately keep extra_groups == NULL for extra_group_size == 0 */
916+
if (extra_group_size > 0) {
917+
extra_groups = PyMem_RawMalloc(extra_group_size * sizeof(gid_t));
918+
if (extra_groups == NULL) {
919919
PyErr_SetString(PyExc_MemoryError,
920920
"failed to allocate memory for group list");
921921
goto cleanup;
922922
}
923923
}
924924

925-
for (Py_ssize_t i = 0; i < num_groups; i++) {
925+
for (Py_ssize_t i = 0; i < extra_group_size; i++) {
926926
PyObject *elem;
927-
elem = PySequence_GetItem(groups_list, i);
927+
elem = PySequence_GetItem(extra_groups_packed, i);
928928
if (!elem)
929929
goto cleanup;
930930
if (!PyLong_Check(elem)) {
931931
PyErr_SetString(PyExc_TypeError,
932-
"groups must be integers");
932+
"extra_groups must be integers");
933933
Py_DECREF(elem);
934934
goto cleanup;
935935
} else {
@@ -939,7 +939,7 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
939939
PyErr_SetString(PyExc_ValueError, "invalid group id");
940940
goto cleanup;
941941
}
942-
groups[i] = gid;
942+
extra_groups[i] = gid;
943943
}
944944
Py_DECREF(elem);
945945
}
@@ -991,7 +991,7 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
991991
/* Use vfork() only if it's safe. See the comment above child_exec(). */
992992
sigset_t old_sigs;
993993
if (preexec_fn == Py_None && allow_vfork &&
994-
uid == (uid_t)-1 && gid == (gid_t)-1 && num_groups < 0) {
994+
uid == (uid_t)-1 && gid == (gid_t)-1 && extra_group_size < 0) {
995995
/* Block all signals to ensure that no signal handlers are run in the
996996
* child process while it shares memory with us. Note that signals
997997
* used internally by C libraries won't be blocked by
@@ -1014,7 +1014,7 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
10141014
p2cread, p2cwrite, c2pread, c2pwrite,
10151015
errread, errwrite, errpipe_read, errpipe_write,
10161016
close_fds, restore_signals, call_setsid, pgid_to_set,
1017-
gid, num_groups, groups,
1017+
gid, extra_group_size, extra_groups,
10181018
uid, child_umask, old_sigmask,
10191019
py_fds_to_keep, preexec_fn, preexec_fn_args_tuple);
10201020

@@ -1054,7 +1054,7 @@ subprocess_fork_exec(PyObject *module, PyObject *args)
10541054
}
10551055

10561056
Py_XDECREF(preexec_fn_args_tuple);
1057-
PyMem_RawFree(groups);
1057+
PyMem_RawFree(extra_groups);
10581058
Py_XDECREF(cwd_obj2);
10591059
if (envp)
10601060
_Py_FreeCharPArray(envp);
@@ -1079,7 +1079,7 @@ PyDoc_STRVAR(subprocess_fork_exec_doc,
10791079
p2cread, p2cwrite, c2pread, c2pwrite,\n\
10801080
errread, errwrite, errpipe_read, errpipe_write,\n\
10811081
restore_signals, call_setsid, pgid_to_set,\n\
1082-
gid, groups_list, uid,\n\
1082+
gid, extra_groups, uid,\n\
10831083
preexec_fn)\n\
10841084
\n\
10851085
Forks a child process, closes parent file descriptors as appropriate in the\n\

0 commit comments

Comments
 (0)