Merge "Improve toolbox SIGPIPE behavior."
This commit is contained in:
commit
6ce5625d58
2 changed files with 15 additions and 6 deletions
|
|
@ -1,6 +1,8 @@
|
||||||
|
#include <signal.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
int main(int, char **);
|
int main(int, char **);
|
||||||
|
|
||||||
|
|
@ -31,11 +33,24 @@ static struct
|
||||||
{ 0, 0 },
|
{ 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 main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
char *name = argv[0];
|
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] == '@')) {
|
if((argc > 1) && (argv[1][0] == '@')) {
|
||||||
name = argv[1] + 1;
|
name = argv[1] + 1;
|
||||||
argc--;
|
argc--;
|
||||||
|
|
|
||||||
|
|
@ -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 int numcmp(long long a, long long b);
|
||||||
static void usage(char *cmd);
|
static void usage(char *cmd);
|
||||||
|
|
||||||
static void exit_top(int signal) {
|
|
||||||
exit(EXIT_FAILURE);
|
|
||||||
}
|
|
||||||
|
|
||||||
int top_main(int argc, char *argv[]) {
|
int top_main(int argc, char *argv[]) {
|
||||||
num_used_procs = num_free_procs = 0;
|
num_used_procs = num_free_procs = 0;
|
||||||
|
|
||||||
signal(SIGPIPE, exit_top);
|
|
||||||
|
|
||||||
max_procs = 0;
|
max_procs = 0;
|
||||||
delay = 3;
|
delay = 3;
|
||||||
iterations = -1;
|
iterations = -1;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue