diff options
author | Rom Lemarchand <romlem@google.com> | 2013-01-09 21:31:25 -0800 |
---|---|---|
committer | Rom Lemarchand <romlem@google.com> | 2013-01-14 11:11:58 -0800 |
commit | b58a82295529e775fbb900ecfb2d9104b2dafdc1 (patch) | |
tree | b1eda8cc7f4ba541ed6bc539609a245ae0f592e9 /logwrapper/include | |
parent | 1b325d196857d29fe5f022f2c574d3625e0adc08 (diff) | |
download | system_core-b58a82295529e775fbb900ecfb2d9104b2dafdc1.zip system_core-b58a82295529e775fbb900ecfb2d9104b2dafdc1.tar.gz system_core-b58a82295529e775fbb900ecfb2d9104b2dafdc1.tar.bz2 |
logwrapper: prevent logwrap from hanging when child dies
Sometimes the read on the PTY can wait indefinitely if the child
dies. By using a poll statement that monitors both the output
of the child and its state we prevent this from happening.
Change-Id: I51d5556c66f039bca673145ca72db262977e1689
Diffstat (limited to 'logwrapper/include')
-rw-r--r-- | logwrapper/include/logwrap/logwrap.h | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/logwrapper/include/logwrap/logwrap.h b/logwrapper/include/logwrap/logwrap.h index a58f238..722dda2 100644 --- a/logwrapper/include/logwrap/logwrap.h +++ b/logwrapper/include/logwrap/logwrap.h @@ -20,7 +20,29 @@ __BEGIN_DECLS -int logwrap(int argc, char* argv[], int *chld_sts); +/* + * Run a command while logging its stdout and stderr + * + * WARNING: while this function is running it will clear all SIGCHLD handlers + * if you rely on SIGCHLD in the caller there is a chance zombies will be + * created if you're not calling waitpid after calling this. This function will + * log a warning when it clears SIGCHLD for processes other than the child it + * created. + * + * Arguments: + * argc: the number of elements in argv + * argv: an array of strings containing the command to be executed and its + * arguments as separate strings. argv does not need to be + * NULL-terminated + * status: the equivalent child status as populated by wait(status). This + * value is only valid when logwrap successfully completes + * + * Return value: + * 0 when logwrap successfully run the child process and captured its status + * -1 when an internal error occurred + * + */ +int logwrap(int argc, char* argv[], int *status); __END_DECLS |