summaryrefslogtreecommitdiffstats
path: root/Modules/posixmodule.c
diff options
context:
space:
mode:
authorThomas Wouters <thomas@python.org>2001-07-11 14:45:34 (GMT)
committerThomas Wouters <thomas@python.org>2001-07-11 14:45:34 (GMT)
commitc2c12dc31cfbe1babe3e8f7f6a4f5bc709e684da (patch)
tree66c88574c4ef234b2ec4491ccca367e8f6979890 /Modules/posixmodule.c
parent109d986bfc10e5971e4669906f9e8eea00d5f912 (diff)
downloadcpython-c2c12dc31cfbe1babe3e8f7f6a4f5bc709e684da.zip
cpython-c2c12dc31cfbe1babe3e8f7f6a4f5bc709e684da.tar.gz
cpython-c2c12dc31cfbe1babe3e8f7f6a4f5bc709e684da.tar.bz2
Patch #439995 (slightly modified from the uploaded version):
Work around Linux's nonstandard nice() systemcall, which does not return the new priority. This closes SF bug #439990.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r--Modules/posixmodule.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 3a85798..120c848 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -1121,8 +1121,25 @@ posix_nice(PyObject *self, PyObject *args)
if (!PyArg_ParseTuple(args, "i:nice", &increment))
return NULL;
+
+ /* There are two flavours of 'nice': one that returns the new
+ priority (as required by almost all standards out there) and the
+ Linux one, which returns '0' on success and advices the use of
+ getpriority() to get the new priority.
+
+ If we are of the nice family that returns the new priority, we
+ need to clear errno before the call, and check if errno is filled
+ before calling posix_error() on a returnvalue of -1, because the
+ -1 may be the actual new priority! */
+
+ errno = 0;
value = nice(increment);
- if (value == -1)
+#ifdef HAVE_GETPRIORITY
+ if (value == 0)
+ value = getpriority(PRIO_PROCESS, 0);
+#endif
+ if (value == -1 && errno != 0)
+ /* either nice() or getpriority() returned an error */
return posix_error();
return PyInt_FromLong((long) value);
}