user [email protected]
usertags 443535 ubuntu-patch jaunty
thanks

On Sat, Sep 22, 2007 at 09:35:25AM +0200, Dominique Dumont wrote:
> I use start-stop-daemon to launch hellanzb which can sometimes be very
> io intensive (with par2 and unrar)
> 
> It would be great if I could launch hellanzb with ionice -c idle
> through start-stop-daemon. Could you add an option --ioniceclass or
> --ionicelevel ?

Chris Coulson <[email protected]> sent a patch for this to
the corresponding Ubuntu bug report
(https://bugs.launchpad.net/ubuntu/+source/dpkg/+bug/306961). I'd rather
not apply this directly in Ubuntu since we'd run the risk of interface
skew, but it would be lovely to have this accepted in Debian (I'd like
it for man-db too). Could you consider it?

Thanks,

-- 
Colin Watson                                       [[email protected]]
diff -Nru dpkg-1.14.22ubuntu1/debian/changelog 
dpkg-1.14.22ubuntu2/debian/changelog
--- dpkg-1.14.22ubuntu1/debian/changelog        2008-11-01 02:01:31.000000000 
+0000
+++ dpkg-1.14.22ubuntu2/debian/changelog        2008-12-10 20:37:45.000000000 
+0000
@@ -1,3 +1,10 @@
+dpkg (1.14.22ubuntu2) jaunty; urgency=low
+
+  * util/start-stop-daemon.c: Add support for setting a process's
+    IO priority.
+
+ -- Chris Coulson <[email protected]>  Wed, 10 Dec 2008 19:23:38 
+0000
+
 dpkg (1.14.22ubuntu1) jaunty; urgency=low
 
   * Resynchronise with Debian. Remaining changes:
diff -Nru dpkg-1.14.22ubuntu1/utils/start-stop-daemon.c 
dpkg-1.14.22ubuntu2/utils/start-stop-daemon.c
--- dpkg-1.14.22ubuntu1/utils/start-stop-daemon.c       2008-08-26 
14:52:08.000000000 +0100
+++ dpkg-1.14.22ubuntu2/utils/start-stop-daemon.c       2008-12-10 
20:36:51.000000000 +0000
@@ -103,6 +103,8 @@
 #include <error.h>
 #endif
 
+#include <sys/syscall.h>
+
 static int testmode = 0;
 static int quietmode = 0;
 static int exitnodo = 1;
@@ -126,8 +128,15 @@
 static char what_stop[1024];
 static const char *progname = "";
 static int nicelevel = 0;
+static int ioprio = 0;
 static int umask_value = -1;
 
+enum {
+        IOPRIO_WHO_PROCESS = 1,
+        IOPRIO_WHO_PGRP,
+        IOPRIO_WHO_USER,
+};
+
 static struct stat exec_stat;
 #if defined(OSHURD)
 static struct proc_stat_list *procset = NULL;
@@ -168,6 +177,7 @@
 #if defined(OSLinux) || defined(OShpux)
 static int pid_is_exec(pid_t pid, const struct stat *esb);
 #endif
+static inline int ioprio_set(int which, int who, int ioprio);
 
 
 static void fatal(const char *format, ...)
@@ -308,6 +318,7 @@
 "  -r|--chroot <directory>       chroot to <directory> before starting\n"
 "  -d|--chdir <directory>        change to <directory> (default is /)\n"
 "  -N|--nicelevel <incr>         add incr to the process's nice level\n"
+"  -I|--ioprio <ioprio>                 Set the process's IO priority\n"
 "  -k|--umask <mask>             change the umask to <mask> before starting\n"
 "  -b|--background               force the process to detach\n"
 "  -m|--make-pidfile             create the pidfile before starting\n"
@@ -520,6 +531,7 @@
                { "exec",         1, NULL, 'x'},
                { "chuid",        1, NULL, 'c'},
                { "nicelevel",    1, NULL, 'N'},
+               { "ioprio",             1, NULL, 'I'},
                { "umask",        1, NULL, 'k'},
                { "background",   0, NULL, 'b'},
                { "make-pidfile", 0, NULL, 'm'},
@@ -534,7 +546,7 @@
 
        for (;;) {
                c = getopt_long(argc, argv,
-                               "HKSVa:n:op:qr:s:tu:vx:c:N:k:bmR:g:d:",
+                               "HKSVa:n:op:qr:s:tu:vx:c:N:I:k:bmR:g:d:",
                                longopts, NULL);
                if (c == -1)
                        break;
@@ -597,6 +609,9 @@
                case 'N':  /* --nice */
                        nicelevel = atoi(optarg);
                        break;
+               case 'I':
+                       ioprio = atoi(optarg);
+                       break;
                case 'k':  /* --umask <mask> */
                        umask_str = optarg;
                        break;
@@ -1221,6 +1236,12 @@
        }
 }
 
+static inline int
+ioprio_set (int which, int who, int ioprio)
+{
+       return syscall(SYS_ioprio_set, which, who, ioprio);
+}
+
 int
 main(int argc, char **argv)
 {
@@ -1334,6 +1355,12 @@
                        fatal("Unable to alter nice level by %i: %s",
                              nicelevel, strerror(errno));
        }
+       if (ioprio) {
+               errno = 0;
+               if ((ioprio_set(IOPRIO_WHO_PROCESS, getpid(), ioprio << 13) == 
-1) && (errno != 0))
+                       fatal("Unable to alter IO priority to %i: %s",
+                                 ioprio, strerror(errno));
+       }
        if (umask_value >= 0)
                umask(umask_value);
        if (mpidfile && pidfile != NULL) {

Reply via email to