Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-94518: Port 23-argument _posixsubprocess.fork_exec to Argument Clinic #94519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 26 commits into from
Apr 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
2e438d9
Convert fork_exec to pre-inlined-argparser Argument Clinic
arhadthedev Jul 2, 2022
514a377
Make flag parameters boolean
arhadthedev Jul 2, 2022
f6ffbb7
Regenerate clinic 3.10 files using clinic 3.12
arhadthedev Jul 2, 2022
bed7d60
Fix forced arg format
arhadthedev Jul 2, 2022
603be00
Fixed a non-existent name left after renaming
arhadthedev Jul 3, 2022
a0646e6
Revert named arguments in multiprocessing/util.py
arhadthedev Jul 3, 2022
86edd0e
Add a NEWS entry
arhadthedev Jul 3, 2022
fe48164
Move uninitialized variables closer to their initialization
arhadthedev Jul 5, 2022
90bb494
Mark do_fork_exec as C11 _Noreturn and remove `return 0` hack
arhadthedev Jul 5, 2022
d0a586c
Address the review on undefined gid/uid
arhadthedev Jul 5, 2022
df6bb72
Fix an unitialized PID
arhadthedev Jul 6, 2022
c927533
Remove confusing out-of-place variable definitions
arhadthedev Jul 7, 2022
9cb1268
Fix fluke (?) "pid may be used uninitialized in this function"
arhadthedev Jul 7, 2022
18e8821
Fix a minor grammar error
arhadthedev Jul 7, 2022
c822f10
Address Gregory's review
arhadthedev Jul 26, 2022
0c6725e
Merge branch 'main' into burn-posixsubprocess-with-ac
arhadthedev Jan 15, 2023
2535f5e
Update a clinic file
arhadthedev Jan 15, 2023
6822d10
Remove a redundant initialization already covered in all `if` branche…
arhadthedev Jan 15, 2023
e09851f
Bring groups -> extra_groups from the main
arhadthedev Jan 26, 2023
a75cc40
Merge branch 'main' into burn-posixsubprocess-with-ac
arhadthedev Jan 26, 2023
d070f06
Merge branch 'main' into burn-posixsubprocess-with-ac
arhadthedev Mar 22, 2023
7251169
Fix reading from uninitialized `pid`
arhadthedev Apr 12, 2023
4ec550d
Merge branch 'main' into burn-posixsubprocess-with-ac
arhadthedev Apr 15, 2023
c7e1a5e
Minimize the diff
arhadthedev Apr 15, 2023
cda283a
Merge branch 'main' into burn-posixsubprocess-with-ac
arhadthedev Apr 23, 2023
2356ec5
Merge branch 'main' into burn-posixsubprocess-with-ac
gpshead Apr 24, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Bring groups -> extra_groups from the main
  • Loading branch information
arhadthedev committed Jan 26, 2023
commit e09851fe6de37de342194e4cfe24e16f786410e9
60 changes: 30 additions & 30 deletions 60 Modules/_posixsubprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ child_exec(char *const exec_array[],
int close_fds, int restore_signals,
int call_setsid, pid_t pgid_to_set,
gid_t gid,
Py_ssize_t groups_size, const gid_t *groups,
Py_ssize_t extra_group_size, const gid_t *extra_groups,
uid_t uid, int child_umask,
const void *child_sigmask,
PyObject *py_fds_to_keep,
Expand Down Expand Up @@ -641,8 +641,8 @@ child_exec(char *const exec_array[],
#endif

#ifdef HAVE_SETGROUPS
if (groups_size > 0)
POSIX_CALL(setgroups(groups_size, groups));
if (extra_group_size > 0)
POSIX_CALL(setgroups(extra_group_size, extra_groups));
#endif /* HAVE_SETGROUPS */

#ifdef HAVE_SETREGID
Expand Down Expand Up @@ -747,7 +747,7 @@ do_fork_exec(char *const exec_array[],
int close_fds, int restore_signals,
int call_setsid, pid_t pgid_to_set,
gid_t gid,
Py_ssize_t groups_size, const gid_t *groups,
Py_ssize_t extra_group_size, const gid_t *extra_groups,
uid_t uid, int child_umask,
const void *child_sigmask,
PyObject *py_fds_to_keep,
Expand All @@ -762,7 +762,7 @@ do_fork_exec(char *const exec_array[],
/* These are checked by our caller; verify them in debug builds. */
assert(uid == (uid_t)-1);
assert(gid == (gid_t)-1);
assert(groups_size < 0);
assert(extra_group_size < 0);
assert(preexec_fn == Py_None);

pid = vfork();
Expand Down Expand Up @@ -799,7 +799,7 @@ do_fork_exec(char *const exec_array[],
p2cread, p2cwrite, c2pread, c2pwrite,
errread, errwrite, errpipe_read, errpipe_write,
close_fds, restore_signals, call_setsid, pgid_to_set,
gid, groups_size, groups,
gid, extra_group_size, extra_groups,
uid, child_umask, child_sigmask,
py_fds_to_keep, preexec_fn, preexec_fn_args_tuple);
_exit(255);
Expand All @@ -826,7 +826,7 @@ _posixsubprocess.fork_exec as subprocess_fork_exec
call_setsid: bool
pgid_to_set: pid_t
gid as gid_object: object
groups_list: object
extra_groups as extra_groups_packed: object
uid as uid_object: object
child_umask: int
preexec_fn: object
Expand Down Expand Up @@ -865,19 +865,19 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
int errwrite, int errpipe_read, int errpipe_write,
int restore_signals, int call_setsid,
pid_t pgid_to_set, PyObject *gid_object,
PyObject *groups_list, PyObject *uid_object,
int child_umask, PyObject *preexec_fn,
int allow_vfork)
/*[clinic end generated code: output=7c8ff5a6dc92af1b input=c59d1152ecdffcf9]*/
PyObject *extra_groups_packed,
PyObject *uid_object, int child_umask,
PyObject *preexec_fn, int allow_vfork)
/*[clinic end generated code: output=7ee4f6ee5cf22b5b input=51757287ef266ffa]*/
{
PyObject *converted_args = NULL, *fast_args = NULL;
PyObject *preexec_fn_args_tuple = NULL;
gid_t *groups = NULL;
gid_t *extra_groups = NULL;
PyObject *cwd_obj2 = NULL;
const char *cwd = NULL;
int need_to_reenable_gc = 0;
char *const *argv = NULL, *const *envp = NULL;
Py_ssize_t num_groups = 0;
Py_ssize_t extra_group_size = 0;
int need_after_fork = 0;
int saved_errno = 0;

Expand Down Expand Up @@ -951,41 +951,41 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
cwd = PyBytes_AsString(cwd_obj2);
}

if (groups_list != Py_None) {
if (extra_groups_packed != Py_None) {
#ifdef HAVE_SETGROUPS
if (!PyList_Check(groups_list)) {
if (!PyList_Check(extra_groups_packed)) {
PyErr_SetString(PyExc_TypeError,
"setgroups argument must be a list");
goto cleanup;
}
num_groups = PySequence_Size(groups_list);
extra_group_size = PySequence_Size(extra_groups_packed);

if (num_groups < 0)
if (extra_group_size < 0)
goto cleanup;

if (num_groups > MAX_GROUPS) {
PyErr_SetString(PyExc_ValueError, "too many groups");
if (extra_group_size > MAX_GROUPS) {
PyErr_SetString(PyExc_ValueError, "too many extra_groups");
goto cleanup;
}

/* Deliberately keep groups == NULL for num_groups == 0 */
if (num_groups > 0) {
groups = PyMem_RawMalloc(num_groups * sizeof(gid_t));
if (groups == NULL) {
/* Deliberately keep extra_groups == NULL for extra_group_size == 0 */
if (extra_group_size > 0) {
extra_groups = PyMem_RawMalloc(extra_group_size * sizeof(gid_t));
if (extra_groups == NULL) {
PyErr_SetString(PyExc_MemoryError,
"failed to allocate memory for group list");
goto cleanup;
}
}

for (Py_ssize_t i = 0; i < num_groups; i++) {
for (Py_ssize_t i = 0; i < extra_group_size; i++) {
PyObject *elem;
elem = PySequence_GetItem(groups_list, i);
elem = PySequence_GetItem(extra_groups_packed, i);
if (!elem)
goto cleanup;
if (!PyLong_Check(elem)) {
PyErr_SetString(PyExc_TypeError,
"groups must be integers");
"extra_groups must be integers");
Py_DECREF(elem);
goto cleanup;
} else {
Expand All @@ -995,7 +995,7 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
PyErr_SetString(PyExc_ValueError, "invalid group id");
goto cleanup;
}
groups[i] = gid;
extra_groups[i] = gid;
}
Py_DECREF(elem);
}
Expand Down Expand Up @@ -1047,7 +1047,7 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
/* Use vfork() only if it's safe. See the comment above child_exec(). */
sigset_t old_sigs;
if (preexec_fn == Py_None && allow_vfork &&
uid == (uid_t)-1 && gid == (gid_t)-1 && num_groups < 0) {
uid == (uid_t)-1 && gid == (gid_t)-1 && extra_group_size < 0) {
/* Block all signals to ensure that no signal handlers are run in the
* child process while it shares memory with us. Note that signals
* used internally by C libraries won't be blocked by
Expand All @@ -1070,7 +1070,7 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
p2cread, p2cwrite, c2pread, c2pwrite,
errread, errwrite, errpipe_read, errpipe_write,
close_fds, restore_signals, call_setsid, pgid_to_set,
gid, num_groups, groups,
gid, extra_group_size, extra_groups,
uid, child_umask, old_sigmask,
py_fds_to_keep, preexec_fn, preexec_fn_args_tuple);

Expand Down Expand Up @@ -1110,7 +1110,7 @@ subprocess_fork_exec_impl(PyObject *module, PyObject *process_args,
}

Py_XDECREF(preexec_fn_args_tuple);
PyMem_RawFree(groups);
PyMem_RawFree(extra_groups);
Py_XDECREF(cwd_obj2);
if (envp)
_Py_FreeCharPArray(envp);
Expand Down
16 changes: 8 additions & 8 deletions 16 Modules/clinic/_posixsubprocess.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Morty Proxy This is a proxified and sanitized view of the page, visit original site.