diff options
| -rw-r--r-- | trace-listen.c | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/trace-listen.c b/trace-listen.c index 3516258..e12431c 100644 --- a/trace-listen.c +++ b/trace-listen.c | |||
| @@ -372,19 +372,12 @@ static void process_client(const char *node, const char *port, int fd) | |||
| 372 | 372 | ||
| 373 | static int do_fork(int cfd) | 373 | static int do_fork(int cfd) |
| 374 | { | 374 | { |
| 375 | int status; | ||
| 376 | pid_t pid; | 375 | pid_t pid; |
| 377 | int ret; | ||
| 378 | 376 | ||
| 379 | /* in debug mode, we do not fork off children */ | 377 | /* in debug mode, we do not fork off children */ |
| 380 | if (debug) | 378 | if (debug) |
| 381 | return 0; | 379 | return 0; |
| 382 | 380 | ||
| 383 | /* Clean up any children that has started before */ | ||
| 384 | do { | ||
| 385 | ret = waitpid(0, &status, WNOHANG); | ||
| 386 | } while (ret > 0); | ||
| 387 | |||
| 388 | pid = fork(); | 381 | pid = fork(); |
| 389 | if (pid < 0) { | 382 | if (pid < 0) { |
| 390 | warning("failed to create child"); | 383 | warning("failed to create child"); |
| @@ -443,6 +436,17 @@ static void do_connection(int cfd, struct sockaddr_storage *peer_addr, | |||
| 443 | exit(0); | 436 | exit(0); |
| 444 | } | 437 | } |
| 445 | 438 | ||
| 439 | static void clean_up(int sig) | ||
| 440 | { | ||
| 441 | int status; | ||
| 442 | int ret; | ||
| 443 | |||
| 444 | /* Clean up any children that has started before */ | ||
| 445 | do { | ||
| 446 | ret = waitpid(0, &status, WNOHANG); | ||
| 447 | } while (ret > 0); | ||
| 448 | } | ||
| 449 | |||
| 446 | static void do_listen(char *port) | 450 | static void do_listen(char *port) |
| 447 | { | 451 | { |
| 448 | struct addrinfo hints; | 452 | struct addrinfo hints; |
| @@ -451,6 +455,9 @@ static void do_listen(char *port) | |||
| 451 | struct sockaddr_storage peer_addr; | 455 | struct sockaddr_storage peer_addr; |
| 452 | socklen_t peer_addr_len; | 456 | socklen_t peer_addr_len; |
| 453 | 457 | ||
| 458 | if (!debug) | ||
| 459 | signal(SIGCHLD, clean_up); | ||
| 460 | |||
| 454 | memset(&hints, 0, sizeof(hints)); | 461 | memset(&hints, 0, sizeof(hints)); |
| 455 | hints.ai_family = AF_UNSPEC; | 462 | hints.ai_family = AF_UNSPEC; |
| 456 | hints.ai_socktype = SOCK_STREAM; | 463 | hints.ai_socktype = SOCK_STREAM; |
