From man dpkg
(1.16.16 (i386) on a Debian (7) based Linux Distro):
--status-fd n
Send machine-readable package status and progress information to file descriptor n
I read this as: "forward machine readable code, such as with generated through printf
to a file descriptor". I (think) to know the file descriptors stdin
(0), stdout
(1), and stderr
(2).
Trying to look up some examples I found next to nothing but bug reports, with file descriptors partly consisting of two digits (possibly more…). This extended my knowledge about file descriptors, which lead to more questions. Thus:
Question: How is dpkg
option --status-fd
used?
An actual example and a some notes of what happens would help me a lot in understanding
Best Answer
The option
--status-fd
tellsdpkg
to report the progress in a way that other programs can parse, for example to present nice progress reports to the user in a GUI.The argument to
--status-fd
is a file descriptor, i.e. number that designates an open file. Simplifying things a bit:open
system call returns the file descriptor.read(0, addr, 10)
means “read 10 bytes from descriptor 0 and put them at memory addressaddr
”.Redirection opens a file on a particular descriptor. For example, in a shell script or on the command line,
mycommand <somefile
connects file descriptor number 0 (standard input) sosomefile
(which is opened for reading) instead of whatever it was before (the terminal, if the command is executed in a terminal). You can prepend a descriptor number to the redirection operator:mycommand 3<somefile
connects file descriptor number 3 tosomefile
(most commands won't do anything with that file descriptor).When dpkg is installing, upgrading or removing packages, it executes various other commands in the packages' pre/post install/removal scripts. Some of these commands may read input or display messages, so dpkg keeps the standard descriptors connected to whatever they were connected to when it was invoked.
Since the standard file descriptors are already taken,
dpkg
allows the caller to specify a different one for the status reports. You could put the status reports in a file, for example:In another terminal, run
tail -n +1 -f /tmp/dpkg.status
and watch the status messages coming.Often the front-end that calls
dpkg
and wants status reports will open a pipe (a unidirectional communication channel) before it runsdpkg
, and pass the file descriptor to write end of the pipe as the argument of--status-fd
. The front-end then reads from the read end of the pipe and gets status messages as they are produced, without risking them getting mixed up with anything else.