summaryrefslogtreecommitdiffstats
path: root/toolbox/toolbox.c
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2015-04-25 19:26:23 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2015-04-25 19:26:23 +0000
commitcd58f488c263f5a1db9f7491d2aa062240765a6c (patch)
tree9395a48a48100f8f895a924bf8021fa6f55de4d6 /toolbox/toolbox.c
parent5281a2a8e9df51cc7c5c17400dbeae6983818a38 (diff)
parent6ce5625d58c2376b719802a0ae0b56bcd3afcdc8 (diff)
downloadsystem_core-cd58f488c263f5a1db9f7491d2aa062240765a6c.zip
system_core-cd58f488c263f5a1db9f7491d2aa062240765a6c.tar.gz
system_core-cd58f488c263f5a1db9f7491d2aa062240765a6c.tar.bz2
am 6ce5625d: Merge "Improve toolbox SIGPIPE behavior."
* commit '6ce5625d58c2376b719802a0ae0b56bcd3afcdc8': Improve toolbox SIGPIPE behavior.
Diffstat (limited to 'toolbox/toolbox.c')
-rw-r--r--toolbox/toolbox.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/toolbox/toolbox.c b/toolbox/toolbox.c
index 0eac390..915da44 100644
--- a/toolbox/toolbox.c
+++ b/toolbox/toolbox.c
@@ -1,6 +1,8 @@
+#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
int main(int, char **);
@@ -31,11 +33,24 @@ static struct
{ 0, 0 },
};
+static void SIGPIPE_handler(int signal) {
+ // Those desktop Linux tools that catch SIGPIPE seem to agree that it's
+ // a successful way to exit, not a failure. (Which makes sense --- we were
+ // told to stop by a reader, rather than failing to continue ourselves.)
+ _exit(0);
+}
+
int main(int argc, char **argv)
{
int i;
char *name = argv[0];
+ // Let's assume that none of this code handles broken pipes. At least ls,
+ // ps, and top were broken (though I'd previously added this fix locally
+ // to top). We exit rather than use SIG_IGN because tools like top will
+ // just keep on writing to nowhere forever if we don't stop them.
+ signal(SIGPIPE, SIGPIPE_handler);
+
if((argc > 1) && (argv[1][0] == '@')) {
name = argv[1] + 1;
argc--;