Skip to content

bpo-31904: Add posix module support for VxWorks RTOS #12118

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 23 commits into from
May 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
cce75ba
support posix module on VxWorks
pxinwr Mar 1, 2019
f548045
update clinic for Modules/clinic/posixmodule.c.h
pxinwr Mar 1, 2019
b41b4d0
Run autoreconf
pxinwr Mar 1, 2019
3462991
add news file
pxinwr Mar 1, 2019
8de1134
bpo-31904: Add posix module support for VxWorks RTOS #12118
yuesun1 Mar 6, 2019
7354c9f
add the period mark in the os.rst
pxinwr Mar 8, 2019
8668612
revert aclocal.m4
pxinwr Mar 8, 2019
6f8e048
tune the lines in os.rst
pxinwr Mar 8, 2019
961f435
Merge remote-tracking branch 'upstream/master' into fix-issue-31904-os
pxinwr Mar 18, 2019
86091ad
update Modules/clinic/posixmodule.c.h
pxinwr Mar 18, 2019
5ea0755
Fix os.rst for spawnv() and spawnve() in OS module
yuesun1 Mar 19, 2019
30e9049
Merge remote-tracking branch 'upstream/master' into fix-issue-31904-os
pxinwr May 17, 2019
cf1a844
improve the test_urandom_failure and skip the ExecTests test cases in…
yuesun1 Mar 14, 2019
728165f
Add news file
yuesun1 Mar 14, 2019
36e955f
update clinic for Modules/clinic/posixmodule.c.h
pxinwr May 17, 2019
3716550
skip URandomFDTests in test_os.py for VxWorks
pxinwr May 17, 2019
c14d326
call PyErr_CheckSignals() on EINTR to respect the PEP 475 for waitpid
pxinwr May 17, 2019
a508f47
rephrase VxWorks' behaviour for spawn-like methods
pxinwr May 17, 2019
201212d
improve Doc/library/os.rst for VxWorks special behaviour
pxinwr May 17, 2019
da73b91
remove the separate NEWS entry for test part
pxinwr May 20, 2019
b380c49
add comments for calling rtpSpawn()
pxinwr May 21, 2019
7ada2ad
fix the typo in Doc/library/os.rst
pxinwr May 21, 2019
eb063a8
refine the skip message for ExecTests
pxinwr May 21, 2019
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
4 changes: 4 additions & 0 deletions Doc/library/os.rst
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Notes on the availability of these functions:
objects, and result in an object of the same type, if a path or file name is
returned.

* On VxWorks, os.fork, os.execv and os.spawn*p* are not supported.

.. note::

Expand Down Expand Up @@ -3578,6 +3579,9 @@ written in Python, such as a mail server's external command delivery program.
process. On Windows, the process id will actually be the process handle, so can
be used with the :func:`waitpid` function.

Note on VxWorks, this function doesn't return ``-signal`` when the new process is
killed. Instead it raises OSError exception.

The "l" and "v" variants of the :func:`spawn\* <spawnl>` functions differ in how
command-line arguments are passed. The "l" variants are perhaps the easiest
to work with if the number of parameters is fixed when the code is written; the
Expand Down
5 changes: 4 additions & 1 deletion Lib/test/test_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -1407,6 +1407,8 @@ def test_getrandom_value(self):

@unittest.skipIf(OS_URANDOM_DONT_USE_FD ,
"os.random() does not use a file descriptor")
@unittest.skipIf(sys.platform == "vxworks",
"VxWorks can't set RLIMIT_NOFILE to 1")
class URandomFDTests(unittest.TestCase):
@unittest.skipUnless(resource, "test requires the resource module")
def test_urandom_failure(self):
Expand Down Expand Up @@ -1517,7 +1519,8 @@ def mock_execve(name, *args):
os.execve = orig_execve
os.defpath = orig_defpath


@unittest.skipUnless(hasattr(os, 'execv'),
"need os.execv()")
class ExecTests(unittest.TestCase):
@unittest.skipIf(USING_LINUXTHREADS,
"avoid triggering a linuxthreads bug: see issue #4970")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add posix module support for VxWorks.
10 changes: 5 additions & 5 deletions Modules/clinic/posixmodule.c.h

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

72 changes: 65 additions & 7 deletions Modules/posixmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,13 @@ corresponding Unix manual entries for more information on calls.");
#define fsync _commit
#else
/* Unix functions that the configure script doesn't check for */
#ifndef __VXWORKS__
#define HAVE_EXECV 1
#define HAVE_FORK 1
#if defined(__USLC__) && defined(__SCO_VERSION__) /* SCO UDK Compiler */
#define HAVE_FORK1 1
#endif
#endif
#define HAVE_GETEGID 1
#define HAVE_GETEUID 1
#define HAVE_GETGID 1
Expand Down Expand Up @@ -227,6 +229,18 @@ extern char *ctermid_r(char *);

#endif /* !_MSC_VER */

#if defined(__VXWORKS__)
#include <vxCpuLib.h>
#include <rtpLib.h>
#include <wait.h>
#include <taskLib.h>
#ifndef _P_WAIT
#define _P_WAIT 0
#define _P_NOWAIT 1
#define _P_NOWAITO 1
#endif
#endif /* __VXWORKS__ */

#ifdef HAVE_POSIX_SPAWN
#include <spawn.h>
#endif
Expand Down Expand Up @@ -1353,7 +1367,7 @@ win32_get_reparse_tag(HANDLE reparse_point_handle, ULONG *reparse_tag)
*/
#include <crt_externs.h>
static char **environ;
#elif !defined(_MSC_VER) && ( !defined(__WATCOMC__) || defined(__QNX__) )
#elif !defined(_MSC_VER) && (!defined(__WATCOMC__) || defined(__QNX__) || defined(__VXWORKS__))
extern char **environ;
#endif /* !_MSC_VER */

Expand Down Expand Up @@ -4870,7 +4884,7 @@ os__exit_impl(PyObject *module, int status)
#define EXECV_CHAR char
#endif

#if defined(HAVE_EXECV) || defined(HAVE_SPAWNV)
#if defined(HAVE_EXECV) || defined(HAVE_SPAWNV) || defined(HAVE_RTPSPAWN)
static void
free_string_array(EXECV_CHAR **array, Py_ssize_t count)
{
Expand Down Expand Up @@ -4908,7 +4922,7 @@ fsconvert_strdup(PyObject *o, EXECV_CHAR **out)
}
#endif

#if defined(HAVE_EXECV) || defined (HAVE_FEXECVE)
#if defined(HAVE_EXECV) || defined (HAVE_FEXECVE) || defined(HAVE_RTPSPAWN)
static EXECV_CHAR**
parse_envlist(PyObject* env, Py_ssize_t *envc_ptr)
{
Expand Down Expand Up @@ -5632,8 +5646,41 @@ os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
}
#endif /* HAVE_POSIX_SPAWNP */


#if defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV)
#ifdef HAVE_RTPSPAWN
static intptr_t
_rtp_spawn(int mode, const char *rtpFileName, const char *argv[],
const char *envp[])
{
RTP_ID rtpid;
int status;
pid_t res;
int async_err = 0;

/* Set priority=100 and uStackSize=16 MiB (0x1000000) for new processes.
uStackSize=0 cannot be used, the default stack size is too small for
Python. */
if (envp) {
rtpid = rtpSpawn(rtpFileName, argv, envp,
100, 0x1000000, 0, VX_FP_TASK);
}
else {
rtpid = rtpSpawn(rtpFileName, argv, (const char **)environ,
100, 0x1000000, 0, VX_FP_TASK);
}
if ((rtpid != RTP_ID_ERROR) && (mode == _P_WAIT)) {
do {
res = waitpid((pid_t)rtpid, &status, 0);
} while (res < 0 && errno == EINTR && !(async_err = PyErr_CheckSignals()));

if (res < 0)
return RTP_ID_ERROR;
return ((intptr_t)status);
}
return ((intptr_t)rtpid);
}
#endif

#if defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)
/*[clinic input]
os.spawnv

Expand Down Expand Up @@ -5703,13 +5750,17 @@ os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv)
}
argvlist[argc] = NULL;

#if !defined(HAVE_RTPSPAWN)
if (mode == _OLD_P_OVERLAY)
mode = _P_OVERLAY;
#endif

Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
#ifdef HAVE_WSPAWNV
spawnval = _wspawnv(mode, path->wide, argvlist);
#elif defined(HAVE_RTPSPAWN)
spawnval = _rtp_spawn(mode, path->narrow, (const char **)argvlist, NULL);
#else
spawnval = _spawnv(mode, path->narrow, argvlist);
#endif
Expand Down Expand Up @@ -5808,13 +5859,18 @@ os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
if (envlist == NULL)
goto fail_1;

#if !defined(HAVE_RTPSPAWN)
if (mode == _OLD_P_OVERLAY)
mode = _P_OVERLAY;
#endif

Py_BEGIN_ALLOW_THREADS
_Py_BEGIN_SUPPRESS_IPH
#ifdef HAVE_WSPAWNV
spawnval = _wspawnve(mode, path->wide, argvlist, envlist);
#elif defined(HAVE_RTPSPAWN)
spawnval = _rtp_spawn(mode, path->narrow, (const char **)argvlist,
(const char **)envlist);
#else
spawnval = _spawnve(mode, path->narrow, argvlist, envlist);
#endif
Expand Down Expand Up @@ -13844,11 +13900,13 @@ all_ins(PyObject *m)
if (PyModule_AddIntConstant(m, "POSIX_SPAWN_DUP2", POSIX_SPAWN_DUP2)) return -1;
#endif

#ifdef HAVE_SPAWNV
#if defined(HAVE_SPAWNV) || defined (HAVE_RTPSPAWN)
if (PyModule_AddIntConstant(m, "P_WAIT", _P_WAIT)) return -1;
if (PyModule_AddIntConstant(m, "P_NOWAIT", _P_NOWAIT)) return -1;
if (PyModule_AddIntConstant(m, "P_OVERLAY", _OLD_P_OVERLAY)) return -1;
if (PyModule_AddIntConstant(m, "P_NOWAITO", _P_NOWAITO)) return -1;
#endif
#ifdef HAVE_SPAWNV
if (PyModule_AddIntConstant(m, "P_OVERLAY", _OLD_P_OVERLAY)) return -1;
if (PyModule_AddIntConstant(m, "P_DETACH", _P_DETACH)) return -1;
#endif

Expand Down
2 changes: 1 addition & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -11484,7 +11484,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy strsignal symlinkat sync \
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \
wcscoll wcsftime wcsxfrm wmemcmp writev _getpty
wcscoll wcsftime wcsxfrm wmemcmp writev _getpty rtpSpawn
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3541,7 +3541,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \
sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy strsignal symlinkat sync \
sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \
wcscoll wcsftime wcsxfrm wmemcmp writev _getpty)
wcscoll wcsftime wcsxfrm wmemcmp writev _getpty rtpSpawn)

# Force lchmod off for Linux. Linux disallows changing the mode of symbolic
# links. Some libc implementations have a stub lchmod implementation that always
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -835,6 +835,9 @@
/* Define to 1 if you have the `round' function. */
#undef HAVE_ROUND

/* Define to 1 if you have the `rtpSpawn' function. */
#undef HAVE_RTPSPAWN

/* Define to 1 if you have the `sched_get_priority_max' function. */
#undef HAVE_SCHED_GET_PRIORITY_MAX

Expand Down