dpkg-1.9.20, glibc-2.2.5, start-stop-daemon and nice()
Bugs: #104561 and #114997
Hi,
This mail was already sent some days ago, but, apparently no one
payed attention.
I recently upgraded a Debian unstable (sid) system (Linux 2.4.17, arch i386)
to glibc-2.2.5 and dpkg-1.9.20, and, since, i wasn't able to use
start-stop-daemon --nicelevel -19 ...
If search in documentation and start-stop-daemon source code,
and i found the problem. I have also check the Debian Bug Database
and found that the problem was already reported. So i don't make another
bug report.
Some explanation:
Extract from the Linux nice() manpage:
Note that the routine is documented in SUSv2 to return the new nice value, while the Linux
syscall and (g)libc (earlier than glibc 2.2.4) routines return 0 on success. The new nice
value can be found using getpriority(2). Note that an implementation in which nice returns
the new nice value can legitimately return -1. To reliably detect an error, set errno to 0
before the call, and check its value when nice returns -1.
Extract from FreeBSD nice() page:
This interface is obsoleted by setpriority(2).
(they don't explain what nice() return !!)
So here is a little patch that correct the problem on all systems (i hope),
using getpriority()/setpriority() if available.
Feel free to use it, asis or modified.
Regards.
--
Yann Droneaud <ydroneaud@meuh.eu.org> +33 6 88 40 82 43
<ydroneaud@tuxfamily.org> <yann.droneaud@iupmime.univ-lemans.fr>
1024D/BEA43321 5D91 B5B0 5137 B8FE 6882 FE19 CAA0 6F05 BEA4 3321
http://www.meuh.eu.org/ http://www-iupmime.univ-lemans.fr/
===File ~/patch-dpkg-meuh-nice==============================
diff -ur dpkg-1.9.20/ChangeLog dpkg-1.9.20meuh/ChangeLog
--- dpkg-1.9.20/ChangeLog Sun Mar 17 10:50:13 2002
+++ dpkg-1.9.20meuh/ChangeLog Wed Apr 3 14:53:18 2002
@@ -1,3 +1,12 @@
+Wed Apr 3 14:44:28 CEST 2002 Yann Droneaud <ydroneaud@meuh.eu.org>
+
+ * configure.in: added checks for <sys/resource.h>, setpriority() and getpriority()
+ * utils/start-stop-daemon.c (main): call do_nice() instead of nice()
+ (do_nice): new function, use getpriority()/setpriority() if available.
+ Never return the new nice level, return only an error flag.
+ errno is modified only in case of error.
+ Close #104561 and #114997.
+
Sun Mar 17 02:55:24 CST 2002 Adam Heath <doogie@debian.org>
* version-nr, debian/changelog: Updated for 1.9.20 release.
diff -ur dpkg-1.9.20/configure.in dpkg-1.9.20meuh/configure.in
--- dpkg-1.9.20/configure.in Fri Feb 1 19:18:38 2002
+++ dpkg-1.9.20meuh/configure.in Wed Apr 3 14:53:08 2002
@@ -121,8 +121,10 @@
AC_CHECK_TYPE(ptrdiff_t,int)
AC_CHECK_FUNCS(unsetenv alphasort scandir strerror strsignal strtoul)
AC_CHECK_FUNCS(vsnprintf lchown snprintf)
+AC_CHECK_FUNCS(getpriority setpriority)
AC_CHECK_HEADERS(sys/cdefs.h syslog.h stddef.h)
AC_CHECK_HEADERS(error.h)
+AC_CHECK_HEADERS(sys/resource.h)
AC_SYS_SIGLIST_DECLARED
AC_CHECK_LIB(ihash, ihash_create, SSD_LIBS="-lihash $SSD_LIBS")
diff -ur dpkg-1.9.20/utils/start-stop-daemon.c dpkg-1.9.20meuh/utils/start-stop-daemon.c
--- dpkg-1.9.20/utils/start-stop-daemon.c Mon May 14 00:01:28 2001
+++ dpkg-1.9.20meuh/utils/start-stop-daemon.c Wed Apr 3 14:53:36 2002
@@ -22,7 +22,7 @@
#include "config.h"
-#if defined(linux)
+#if defined(linux) || defined(__linux__)
# define OSLinux
#elif defined(__GNU__)
# define OSHURD
@@ -78,8 +78,12 @@
#ifdef HAVE_ERROR_H
# include <error.h>
#endif
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
+
#ifdef HURD_IHASH_H
- #include <hurd/ihash.h>
+# include <hurd/ihash.h>
#endif
static int testmode = 0;
@@ -140,6 +144,8 @@
static void do_pidfile(const char *name);
static void do_stop(int signal_nr, int quietmode,
int *n_killed, int *n_notkilled, int retry_nr);
+static int do_nice(int increment);
+
#if defined(OSLinux)
static int pid_is_exec(pid_t pid, const struct stat *esb);
#endif
@@ -1034,6 +1040,37 @@
}
}
+/* return 0 if no error, -1 otherwise */
+static int
+do_nice(int increment)
+{
+ int save;
+ int current;
+
+ save = errno;
+ errno = 0;
+
+#if defined(HAVE_GETPRIORITY) && defined(HAVE_SETPRIORITY)
+ /* could return -1 as a valid priority */
+ current = getpriority (PRIO_PROCESS, 0);
+#else
+ /* nice() return new nice level on some systems,
+ it return 0 if success and -1 in case of error, on other systems */
+ current = nice(increment);
+#endif
+
+ if (current == -1 && errno != 0)
+ return -1;
+
+ errno = save;
+
+#if defined(HAVE_GETPRIORITY) && defined(HAVE_SETPRIORITY)
+ /* setpriority return 0 if successful, -1 in case of error */
+ return setpriority (PRIO_PROCESS, 0, current + increment);
+#else
+ return 0;
+#endif
+}
int main(int argc, char **argv) NONRETURNING;
int
@@ -1150,8 +1187,8 @@
dup(fd); /* stdout */
dup(fd); /* stderr */
}
- if (nicelevel) {
- if (nice(nicelevel))
+ if (nicelevel != 0) {
+ if (do_nice(nicelevel) == -1)
fatal("Unable to alter nice level by %i: %s", nicelevel,
strerror(errno));
}
============================================================
--
To UNSUBSCRIBE, email to debian-dpkg-request@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Reply to: