]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Patch #439995 (slightly modified from the uploaded version):
authorThomas Wouters <thomas@python.org>
Wed, 11 Jul 2001 14:01:08 +0000 (14:01 +0000)
committerThomas Wouters <thomas@python.org>
Wed, 11 Jul 2001 14:01:08 +0000 (14:01 +0000)
Work around Linux's nonstandard nice() systemcall, which does not return the
new priority.

This closes SF bug #439990.

Modules/posixmodule.c
config.h.in
configure
configure.in

index 646385efff3ca341db7ab3c506f67b7ec3730b92..1fbf1b88c7b6b236973f3c15a69c427b403bc0d5 100644 (file)
@@ -1078,8 +1078,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);
 }
index a3c9e3f47660a6784f5bc7338c799dcfe23d2267..67ee9962af565dc17df95bf195726c7e7342dac1 100644 (file)
 /* Define if you have the getpid function.  */
 #undef HAVE_GETPID
 
+/* Define if you have the getpriority function.  */
+#undef HAVE_GETPRIORITY
+
 /* Define if you have the getpwent function.  */
 #undef HAVE_GETPWENT
 
index affbd22168d780de798ff6e4aa9074d5e4e37048..4f7b8f504f038935509aab7960ba37e865d1c27d 100755 (executable)
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 
-# From configure.in Revision: 1.215.2.1 
+# From configure.in Revision: 1.215.2.2 
 
 # Guess values for system-dependent variables and create Makefiles.
 # Generated automatically using autoconf version 2.13 
@@ -4247,7 +4247,7 @@ for ac_func in alarm chown clock confstr ctermid ctermid_r execv \
  setlocale setregid setreuid setsid setpgid setuid setvbuf \
  sigaction siginterrupt sigrelse strftime strptime symlink sysconf \
  tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
- truncate uname waitpid _getpty
+ truncate uname waitpid _getpty getpriority
 do
 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
 echo "configure:4254: checking for $ac_func" >&5
index 48c4f0eb18191ce60c6451c005714b29c5cb4a0e..48678680a8db2caf6f3e1f49a375b3d6bf0afbc6 100644 (file)
@@ -1008,7 +1008,7 @@ AC_CHECK_FUNCS(alarm chown clock confstr ctermid ctermid_r execv \
  setlocale setregid setreuid setsid setpgid setuid setvbuf \
  sigaction siginterrupt sigrelse strftime strptime symlink sysconf \
  tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \
- truncate uname waitpid _getpty)
+ truncate uname waitpid _getpty getpriority)
 
 # check for openpty and forkpty