diff options
author | Michael Stapelberg <michael@stapelberg.de> | 2009-06-21 14:15:14 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2009-06-21 14:15:14 +0200 |
commit | 098f7bac23e6e63e1ef0bfc12e7581ffd93ea89c (patch) | |
tree | 49c47096c962789951f00b63cb200ef534649c1d | |
parent | 1dfe4aeff38b2ab988cb3038311e49bb58aff306 (diff) |
Bugfix: Correctly handle SIGPIPE to avoid unnecessary zombie processes1.2
Negative return value of printf() is not used when write() returns
a negative value, instead, SIGPIPE is sent.
-rw-r--r-- | i3status.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -54,6 +54,7 @@ #include <glob.h> #include <dirent.h> #include <getopt.h> +#include <signal.h> #include "queue.h" @@ -693,6 +694,16 @@ static int load_configuration(const char *configfile) { return result; } +/* + * Exit upon SIGPIPE because when we have nowhere to write to, gathering + * system information is pointless. + * + */ +void sigpipe(int signum) { + fprintf(stderr, "Received SIGPIPE, exiting\n"); + exit(1); +} + int main(int argc, char *argv[]) { char part[512], pathbuf[512]; @@ -706,6 +717,11 @@ int main(int argc, char *argv[]) { {0, 0, 0, 0} }; + struct sigaction action; + memset(&action, 0, sizeof(struct sigaction)); + action.sa_handler = sigpipe; + sigaction(SIGPIPE, &action, NULL); + SIMPLEQ_INIT(&batteries); while ((o = getopt_long(argc, argv, "c:h", long_options, &option_index)) != -1) |