plainbox:vendor:glibc: Add constants F_{GET,SET}PIPE_SZ

python-glibc-patch: d5ac34c64966b1d6ac19ea842a4c10343e3de481

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:vendor:extcmd: don't assume PIPE_BUF is the true pipe size

This patch fixes an incorrect assumption that each pipe is capable of
holding exactly PIPE_BUF bytes. In reality pipe capacity can be changed
at any time and the default size is somewhat larger.

Unpriviledged processed on Linux cannot use more than
/proc/sys/fs/max-pipe-size but that's not a hard limit so we just read
the current size of the pipe each time.

The logic inside extcmd assumes that after a process has exited it
cannot really write more than the size of the pipe so after we've read
that much all (any) other data going into the pipe must be coming from
other processes that got access to the pipe and ignores it (closing the
pipe).  With this patch, that logic is operational again. At the same
time we no longer "lose" the data written beyond PIPE_SIZE as we always
read the current (maximum) capacity.

NOTE: An especially malicious process can fork off a child that
manipulates the pipe size but we don't care about mailcious that much
here as this cannot be perfect (a malicious process can do much more
harm than trick us not to read some data from the pipe).

Fixes: https://bugs.launchpad.net/plainbox/+bug/1402675

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:vendor:extcmd: don't block SIG{INT,QUIT,CHLD} in test processes

This patch corrects a bad assumption that the mask of blocked signals is
reset across exec. It's not, thus to let the test process be killable
with SIGINT or SIGQUIT (and more importantly, to let that process manage
its own SIGCHLD) we must remove the mask that was applied in the parent.

In practical terms we can now CTRL-C or CTRL-\ to interrupt / quit the
started test process.

Fixes: https://bugs.launchpad.net/plainbox/+bug/1402680
plainbox:vendor:extcmd: defer on_{,abnormal_}end() until I/O stops

This patch fixes race condition inside extcmd, where a process can exit
but we can still see I/O on the pipe _after_ we saw the SIGCHLD signal.

This can happen if the pipe is leaked to a third process or if the
particular ordering of events (theorethical) happens to be that we
fierst read the signalfd() descriptor and only after we read the
(perhaps last words of) dta from the pipe.

Fixes: https://bugs.launchpad.net/plainbox/+bug/1402710

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:vendor:extcmd: change algorithm for reading trailing pipe data

This patch fixes a potential bug where plainbox won't see the trailing
data from a pipe if a given scheduling constraint happens to put the
death of the process _before_ the notification that we have some more
data pending.

The new algorithm lets each pipe to finish naturally but enables the
special mode force_last, where we read from a pipe at most once before
closing it unconditionally, if we already saw the deadth of the process.
It has the same guarantees as the old algorithm but it will (unlike
before) also work if we see the death before being notified about the
last data.

I don't know if this is realistic but I'm much happier with this
prevented non the less. It doesn't seem to happen anymore now that we've
fixed pipe size bugs that made it happen all the time.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
plainbox:vendor:extcmd: sanity checking if we haven't seen a process exit

This patch adds small bug detection code that can trigger if we somehow
don't see the process exit but we're already shutting down. In case that
ever happens we'll have a separate bug message.

Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
"automatic merge of lp:~zkrynicki/checkbox/extcmd-fixes/ by tarmac [r=sylvain-pineau][bug=1402675,1402680,1402710][author=zkrynicki]"