summaryrefslogtreecommitdiff
path: root/apt-pkg
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2009-06-17 10:15:51 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2009-06-17 10:15:51 +0200
commitcebe0287c36408e44196266de45737386eaa28fc (patch)
tree7c31eebe80b82380c3fa80204a665666b12c69e8 /apt-pkg
parent6ce7261259132f11fc93af104754e8cfc540bf13 (diff)
* apt-pkg/deb/dpkgpm.cc:
- add Dpkg::UseIoNice boolean option to run dpkg with ionice -c3 (off by default)
Diffstat (limited to 'apt-pkg')
-rw-r--r--apt-pkg/deb/dpkgpm.cc30
1 files changed, 29 insertions, 1 deletions
diff --git a/apt-pkg/deb/dpkgpm.cc b/apt-pkg/deb/dpkgpm.cc
index 1d45e70e9..462f4a739 100644
--- a/apt-pkg/deb/dpkgpm.cc
+++ b/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 /*{{{*/
// ---------------------------------------------------------------------
/* */
@@ -850,7 +875,6 @@ bool pkgDPkgPM::Go(int OutStatusFd)
_exit(100);
}
-
/* No Job Control Stop Env is a magic dpkg var that prevents it
from using sigstop */
putenv((char *)"DPKG_NO_TSTP=yes");
@@ -859,6 +883,10 @@ bool pkgDPkgPM::Go(int OutStatusFd)
_exit(100);
}
+ // apply ionice
+ if (_config->FindB("DPkg::UseIoNice", false) == true)
+ ionice(Child);
+
// clear the Keep-Fd again
_config->Clear("APT::Keep-Fds",fd[1]);