diff options
author | Elliott Hughes <enh@google.com> | 2015-04-25 19:59:02 +0000 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2015-04-25 19:59:02 +0000 |
commit | 5773993df470c902030b29330d7418e22c72c4de (patch) | |
tree | 5ca3930d674337e426fce94d0aee731e73f0e3c8 | |
parent | bdabdd9279e406534b42913f4dc618397622404d (diff) | |
parent | 893981c9774de525a5e481fb717613feb35fa4cf (diff) | |
download | system_core-5773993df470c902030b29330d7418e22c72c4de.zip system_core-5773993df470c902030b29330d7418e22c72c4de.tar.gz system_core-5773993df470c902030b29330d7418e22c72c4de.tar.bz2 |
am 893981c9: am cd58f488: am 6ce5625d: Merge "Improve toolbox SIGPIPE behavior."
* commit '893981c9774de525a5e481fb717613feb35fa4cf':
Improve toolbox SIGPIPE behavior.
-rw-r--r-- | toolbox/toolbox.c | 15 | ||||
-rw-r--r-- | toolbox/top.c | 6 |
2 files changed, 15 insertions, 6 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--; diff --git a/toolbox/top.c b/toolbox/top.c index b1a275c..1e99d4c 100644 --- a/toolbox/top.c +++ b/toolbox/top.c @@ -109,15 +109,9 @@ static int proc_thr_cmp(const void *a, const void *b); static int numcmp(long long a, long long b); static void usage(char *cmd); -static void exit_top(int signal) { - exit(EXIT_FAILURE); -} - int top_main(int argc, char *argv[]) { num_used_procs = num_free_procs = 0; - signal(SIGPIPE, exit_top); - max_procs = 0; delay = 3; iterations = -1; |