Просмотр исходного кода

* apt-pkg/deb/dpkgpm.cc:
- add Dpkg::UseIoNice boolean option to run dpkg with ionice -c3
(off by default)

Michael Vogt лет назад: 17
Родитель
Сommit
cebe0287c3
2 измененных файлов с 32 добавлено и 1 удалено
  1. 29 1
      apt-pkg/deb/dpkgpm.cc
  2. 3 0
      debian/changelog

+ 29 - 1
apt-pkg/deb/dpkgpm.cc

@@ -74,6 +74,31 @@ namespace
   };
   };
 }
 }
 
 
+/* helper function to ionice the given PID 
+
+ there is no C header for ionice yet - just the syscall interface
+ so we use the binary from util-linux
+*/
+static bool
+ionice(int PID)
+{
+   if (!FileExists("/usr/bin/ionice"))
+      return false;
+   pid_t Process = ExecFork();      
+   if (Process == 0)
+   {
+      char buf[32];
+      snprintf(buf, sizeof(buf), "-p%d", PID);
+      const char *Args[4];
+      Args[0] = "/usr/bin/ionice";
+      Args[1] = "-c3";
+      Args[2] = buf;
+      Args[3] = 0;
+      execv(Args[0], (char **)Args);
+   }
+   return ExecWait(Process, "ionice");
+}
+
 // DPkgPM::pkgDPkgPM - Constructor					/*{{{*/
 // DPkgPM::pkgDPkgPM - Constructor					/*{{{*/
 // ---------------------------------------------------------------------
 // ---------------------------------------------------------------------
 /* */
 /* */
@@ -850,7 +875,6 @@ bool pkgDPkgPM::Go(int OutStatusFd)
 	       _exit(100);
 	       _exit(100);
 	 }
 	 }
 
 
-
 	 /* No Job Control Stop Env is a magic dpkg var that prevents it
 	 /* No Job Control Stop Env is a magic dpkg var that prevents it
 	    from using sigstop */
 	    from using sigstop */
 	 putenv((char *)"DPKG_NO_TSTP=yes");
 	 putenv((char *)"DPKG_NO_TSTP=yes");
@@ -859,6 +883,10 @@ bool pkgDPkgPM::Go(int OutStatusFd)
 	 _exit(100);
 	 _exit(100);
       }      
       }      
 
 
+      // apply ionice
+      if (_config->FindB("DPkg::UseIoNice", false) == true)
+	 ionice(Child);
+
       // clear the Keep-Fd again
       // clear the Keep-Fd again
       _config->Clear("APT::Keep-Fds",fd[1]);
       _config->Clear("APT::Keep-Fds",fd[1]);
 
 

+ 3 - 0
debian/changelog

@@ -13,6 +13,9 @@ apt (0.7.21) UNRELEASED; urgency=low
   * apt-pkg/acquire.cc:
   * apt-pkg/acquire.cc:
     - make the max pipeline depth of the acquire queue configurable
     - make the max pipeline depth of the acquire queue configurable
       via Acquire::Max-Pipeline-Depth
       via Acquire::Max-Pipeline-Depth
+  * apt-pkg/deb/dpkgpm.cc:
+    - add Dpkg::UseIoNice boolean option to run dpkg with ionice -c3
+      (off by default)
 
 
  -- Michael Vogt <michael.vogt@ubuntu.com>  Thu, 28 May 2009 17:51:42 +0200
  -- Michael Vogt <michael.vogt@ubuntu.com>  Thu, 28 May 2009 17:51:42 +0200