GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — bpo-35537: Add setsid parameter to os.posix_spawn() and os.posix_spawnp(). by nanjekyejoannah · Pull Request #11608 · python/cpython

bpo-35537: Add setsid parameter to os.posix_spawn() and os.posix_spawnp(). #11608

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.

Sign up for GitHub

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
vstinner merged 1 commit into python:master from nanjekyejoannah:setsid
Feb 1, 2019

Uh oh!

There was an error while loading. Please reload this page.

Merged

bpo-35537: Add setsid parameter to os.posix_spawn() and os.posix_spawnp(). #11608

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
1 commit
Select commit
6a93484
Add setsid parameter to os.posix_spawn() and os.posix_spawnp()
nanjekyejoannah Jan 31, 2019
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

12 changes: 10 additions & 2 deletions 12 Doc/library/os.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3386,7 +3386,7 @@ written in Python, such as a mail server's external command delivery program.


.. function:: posix_spawn(path, argv, env, *, file_actions=None, \
setpgroup=None, resetids=False, setsigmask=(), \
setpgroup=None, resetids=False, setsid=False, setsigmask=(), \
setsigdef=(), scheduler=None)

Wraps the :c:func:`posix_spawn` C library API for use from Python.
Expand Down Expand Up @@ -3444,6 +3444,11 @@ written in Python, such as a mail server's external command delivery program.
setting of the effective UID and GID. This argument corresponds to the C
library :c:data:`POSIX_SPAWN_RESETIDS` flag.

If the *setsid* argument is ``True``, it will create a new session ID
for `posix_spawn`. *setsid* requires :c:data:`POSIX_SPAWN_SETSID`
or :c:data:`POSIX_SPAWN_SETSID_NP` flag. Otherwise, :exc:`NotImplementedError`
is raised.

Comment thread
vstinner marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

The *setsigmask* argument will set the signal mask to the signal set
specified. If the parameter is not used, then the child inherits the
parent's signal mask. This argument corresponds to the C library
Expand All @@ -3462,9 +3467,10 @@ written in Python, such as a mail server's external command delivery program.

.. versionadded:: 3.7

.. availability:: Unix.

.. function:: posix_spawnp(path, argv, env, *, file_actions=None, \
setpgroup=None, resetids=False, setsigmask=(), \
setpgroup=None, resetids=False, setsid=False, setsigmask=(), \
setsigdef=(), scheduler=None)

Wraps the :c:func:`posix_spawnp` C library API for use from Python.
Expand All @@ -3475,6 +3481,8 @@ written in Python, such as a mail server's external command delivery program.

.. versionadded:: 3.8

.. availability:: See :func:`posix_spawn` documentation.


.. function:: register_at_fork(*, before=None, after_in_parent=None, \
after_in_child=None)
Expand Down
16 changes: 16 additions & 0 deletions 16 Lib/test/test_posix.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -1622,6 +1622,22 @@ def test_setsigmask_wrong_type(self):
os.environ, setsigmask=[signal.NSIG,
signal.NSIG+1])

def test_start_new_session(self):
# For code coverage of calling setsid(). We don't care if we get an
# EPERM error from it depending on the test execution environment, that
# still indicates that it was called.
code = "import os; print(os.getpgid(os.getpid()))"
try:
self.spawn_func(sys.executable,
[sys.executable, "-c", code],
os.environ, setsid=True)
except NotImplementedError as exc:
self.skipTest("setsid is not supported: %s" % exc)
else:
parent_pgid = os.getpgid(os.getpid())
child_pgid = int(output)
self.assertNotEqual(parent_pgid, child_pgid)

@unittest.skipUnless(hasattr(signal, 'pthread_sigmask'),
'need signal.pthread_sigmask()')
def test_setsigdef(self):
Expand Down
1 change: 1 addition & 0 deletions 1 Misc/NEWS.d/next/Library/2019-01-18-13-44-13.bpo-35537.R1lbTl.rst
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
:func:`os.posix_spawn` and :func:`os.posix_spawnp` now have a *setsid* parameter.
44 changes: 26 additions & 18 deletions 44 Modules/clinic/posixmodule.c.h
Show comments
View file
Open in desktop

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

Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

44 changes: 31 additions & 13 deletions 44 Modules/posixmodule.c
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -5166,10 +5166,11 @@ convert_sched_param(PyObject *param, struct sched_param *res);
#endif

static int
parse_posix_spawn_flags(PyObject *setpgroup, int resetids, PyObject *setsigmask,
parse_posix_spawn_flags(PyObject *setpgroup, int resetids, int setsid, PyObject *setsigmask,
PyObject *setsigdef, PyObject *scheduler,
posix_spawnattr_t *attrp)
{
const char *func_name = "posix_spawnp";
long all_flags = 0;

errno = posix_spawnattr_init(attrp);
Expand All @@ -5195,6 +5196,17 @@ parse_posix_spawn_flags(PyObject *setpgroup, int resetids, PyObject *setsigmask,
all_flags |= POSIX_SPAWN_RESETIDS;
}

if (setsid) {
#ifdef POSIX_SPAWN_SETSID
all_flags |= POSIX_SPAWN_SETSID;
#elif defined(POSIX_SPAWN_SETSID_NP)
all_flags |= POSIX_SPAWN_SETSID_NP;
#else
argument_unavailable_error(func_name, "setsid");
return -1;
#endif
Comment thread
nanjekyejoannah marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

}

if (setsigmask) {
sigset_t set;
if (!_Py_Sigset_Converter(setsigmask, &set)) {
Expand Down Expand Up @@ -5385,7 +5397,7 @@ parse_file_actions(PyObject *file_actions,
static PyObject *
py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *argv,
PyObject *env, PyObject *file_actions,
PyObject *setpgroup, int resetids, PyObject *setsigmask,
PyObject *setpgroup, int resetids, int setsid, PyObject *setsigmask,
PyObject *setsigdef, PyObject *scheduler)
{
EXECV_CHAR **argvlist = NULL;
Expand All @@ -5400,7 +5412,7 @@ py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *a
pid_t pid;
int err_code;

/* posix_spawn has three arguments: (path, argv, env), where
/* posix_spawn and posix_spawnp have three arguments: (path, argv, env), where
argv is a list or tuple of strings and env is a dictionary
like posix.environ. */

Expand Down Expand Up @@ -5455,7 +5467,7 @@ py_posix_spawn(int use_posix_spawnp, PyObject *module, path_t *path, PyObject *a
file_actionsp = &file_actions_buf;
}

if (parse_posix_spawn_flags(setpgroup, resetids, setsigmask,
if (parse_posix_spawn_flags(setpgroup, resetids, setsid, setsigmask,
setsigdef, scheduler, &attr)) {
goto exit;
}
Expand Down Expand Up @@ -5519,7 +5531,9 @@ os.posix_spawn
setpgroup: object = NULL
The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.
resetids: bool(accept={int}) = False
If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.
If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.
setsid: bool(accept={int}) = False
If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.
setsigmask: object(c_default='NULL') = ()
The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.
setsigdef: object(c_default='NULL') = ()
Expand All @@ -5533,12 +5547,13 @@ Execute the program specified by path in a new process.
static PyObject *
os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
PyObject *env, PyObject *file_actions,
PyObject *setpgroup, int resetids, PyObject *setsigmask,
PyObject *setsigdef, PyObject *scheduler)
/*[clinic end generated code: output=45dfa4c515d09f2c input=2891c2f1d457e39b]*/
PyObject *setpgroup, int resetids, int setsid,
PyObject *setsigmask, PyObject *setsigdef,
PyObject *scheduler)
/*[clinic end generated code: output=14a1098c566bc675 input=8c6305619a00ad04]*/
{
return py_posix_spawn(0, module, path, argv, env, file_actions,
setpgroup, resetids, setsigmask, setsigdef,
setpgroup, resetids, setsid, setsigmask, setsigdef,
Comment thread
nanjekyejoannah marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

scheduler);
}
#endif /* HAVE_POSIX_SPAWN */
Expand All @@ -5563,6 +5578,8 @@ os.posix_spawnp
The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.
resetids: bool(accept={int}) = False
If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.
setsid: bool(accept={int}) = False
If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.
setsigmask: object(c_default='NULL') = ()
The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.
setsigdef: object(c_default='NULL') = ()
Expand All @@ -5576,12 +5593,13 @@ Execute the program specified by path in a new process.
static PyObject *
os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
PyObject *env, PyObject *file_actions,
PyObject *setpgroup, int resetids, PyObject *setsigmask,
PyObject *setsigdef, PyObject *scheduler)
/*[clinic end generated code: output=7955dc0edc82b8c3 input=b7576eb25b1ed9eb]*/
PyObject *setpgroup, int resetids, int setsid,
PyObject *setsigmask, PyObject *setsigdef,
PyObject *scheduler)
/*[clinic end generated code: output=7b9aaefe3031238d input=c1911043a22028da]*/
{
return py_posix_spawn(1, module, path, argv, env, file_actions,
setpgroup, resetids, setsigmask, setsigdef,
setpgroup, resetids, setsid, setsigmask, setsigdef,
scheduler);
}
#endif /* HAVE_POSIX_SPAWNP */
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.