[Aptitude-devel] Bug#555632: aptitude does not run in background

Daniel Hartwig mandyke at gmail.com
Mon May 14 07:22:59 UTC 2012

reassign 555632 libapt-pkg4.10,libapt-pkg4.12
affects 555632 = aptitude apt-utils
retitle 555632 background tasks stop on SIGTTIN, SIGTTOU

> Running something like
> aptitude --assume-yes do-something >aptitude.log 2>&1 &
> will hang after downloading packages.
> Just bringing aptitude in the foreground without providing any input
> suffices for aptitude to continue.

apt-get also suffers from this.

If you desire a non-interactive install then you should redirect stdin
from /dev/null:

# apt-get install -y foo < /dev/null > apt.log 2>&1 &

Without this redirect, the program receives either SIGTTIN or SIGTTOU
depending on whether or not the keyboard is used after running.  See
below for debugging info.

DPkgPM (libapt-pkg) eagerly tries to forward all input to the dpkg
sub-process.  This is the cause of the problem.

I'll leave it up to the more experienced apt developers to decide if
this is really a bug, too hard to fix, or just standard behaviour.  It
would be ideal if the potential SIGTTIN could be avoided until the
dpkg process actually tries to read stdin, rather than eagerly
forwarding all input -- the process would only stop if dpkg was
actually seeking input.

Here is a session identifying the cause, the program receives SIGTTIN
when calling read(2) on stdin at #2:

# apt-get install -y tf > apt.log 2>&1 &
[1] 11870

[1]+  Stopped                 apt-get install -y tf > apt.log 2>&1
# gdb apt-get
GNU gdb (GDB) 7.4.1-debian
Reading symbols from /usr/bin/apt-get...done.
(gdb) attach 11870
Attaching to program: /usr/bin/apt-get, process 11870
0xb777a424 in __kernel_vsyscall ()
(gdb) bt
#0  0xb777a424 in __kernel_vsyscall ()
#1  0xb73c30f3 in __read_nocancel ()
    at ../sysdeps/unix/syscall-template.S:82
#2  0xb76ee773 in pkgDPkgPM::DoStdin (this=0x83cab78, master=13)
    at deb/dpkgpm.cc:426
#3  0xb76f3b51 in pkgDPkgPM::Go (this=0x83cab78, OutStatusFd=-1)
    at deb/dpkgpm.cc:1362
#4  0xb768601c in pkgPackageManager::DoInstallPostFork (this=0x83cab78,
    statusFd=-1) at packagemanager.cc:1008
(gdb) n
Single stepping until exit from function __kernel_vsyscall,
which has no line number information.

pkgDPkgPM::DoStdin (this=0x83cab78, master=13) at deb/dpkgpm.cc:427
427	   if (len)
(gdb) p len
$1 = 1
(gdb) p input_buf
$2 = "\n", '\000' <repeats 254 times>
(gdb) c
[Inferior 1 (process 11870) exited normally]

Above is caused by typing some input (in this case, just RETURN) after
starting the program.

In another session, when the keyboard was kept completely idle (so
stdin has nothing to read), the program receives SIGTTOU instead:

(gdb) bt
#0  0xb787a424 in __kernel_vsyscall ()
#1  0xb74c9abf in *__GI_tcsetattr (fd=-1219121164, optional_actions=2,
    termios_p=0xbff5d804) at ../sysdeps/unix/sysv/linux/tcsetattr.c:88
#2  0xb77f3c58 in pkgDPkgPM::Go (this=0x9676b78, OutStatusFd=-1)
    at deb/dpkgpm.cc:1376
#3  0xb778601c in pkgPackageManager::DoInstallPostFork (this=0x9676b78,
    statusFd=-1) at packagemanager.cc:1008

This time, #2 is this line:

 1374:      if(master >= 0)
 1375:      {
*1376:         tcsetattr(0, TCSAFLUSH, &tt);
 1377:         close(master);
 1378:      }

More information about the Aptitude-devel mailing list