Bug#452858: apt: apt-get takes all CPU with /dev/null redirected to stdin
Package: apt
Version: 0.7.7
Severity: important
When /dev/null is redirected to stdin, apt-get uses all CPU during calls
to dpkg. This is due to the use of pselect() on stdin, which always
returns EOF in that case.
This bug mostly breaks sbuild (or rather render packages installation
very very very very slow), as it redirects /dev/null to stdin.
The patch below fixes the problem.
diff -Nru apt-0.7.9/apt-pkg/deb/dpkgpm.cc apt-0.7.9/apt-pkg/deb/dpkgpm.cc
--- apt-0.7.9/apt-pkg/deb/dpkgpm.cc 2007-10-31 15:30:26 +0000
+++ apt-0.7.9/apt-pkg/deb/dpkgpm.cc 2007-11-25 16:58:01 +0000
@@ -344,7 +344,10 @@
{
char input_buf[256] = {0,};
int len = read(0, input_buf, sizeof(input_buf));
- write(master, input_buf, len);
+ if (len)
+ write(master, input_buf, len);
+ else
+ stdin_is_dev_null = true;
}
/*}}}*/
// DPkgPM::DoTerminalPty - Read the terminal pty and write log /*{{{*/
@@ -639,6 +642,8 @@
}
}
+ stdin_is_dev_null = false;
+
// create log
OpenLog();
@@ -868,7 +873,8 @@
// wait for input or output here
FD_ZERO(&rfds);
- FD_SET(0, &rfds);
+ if (!stdin_is_dev_null)
+ FD_SET(0, &rfds);
FD_SET(_dpkgin, &rfds);
if(master >= 0)
FD_SET(master, &rfds);
diff -Nru apt-0.7.9/apt-pkg/deb/dpkgpm.h apt-0.7.9/apt-pkg/deb/dpkgpm.h
--- apt-0.7.9/apt-pkg/deb/dpkgpm.h 2007-10-06 21:16:27 +0000
+++ apt-0.7.9/apt-pkg/deb/dpkgpm.h 2007-11-25 16:51:41 +0000
@@ -23,6 +23,8 @@
{
private:
+ bool stdin_is_dev_null;
+
// the buffer we use for the dpkg status-fd reading
char dpkgbuf[1024];
int dpkgbuf_pos;
-- System Information:
Debian Release: lenny/sid
Architecture: kfreebsd-i386 (i686)
Kernel: kFreeBSD 6.2-1-686
Locale: LANG=fr_FR.UTF-8, LC_CTYPE=fr_FR.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages apt depends on:
ii debian-archive-keyring 2007.07.31 GnuPG archive keys of the Debian a
ii libc0.1 2.7-1 GNU C Library: Shared libraries
ii libgcc1 1:4.2.2-3 GCC support library
ii libstdc++6 4.2.2-3 The GNU Standard C++ Library v3
apt recommends no packages.
-- no debconf information
Reply to: