aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSteven Rostedt <srostedt@redhat.com>2010-03-29 16:36:26 -0400
committerSteven Rostedt <rostedt@goodmis.org>2010-03-29 16:36:26 -0400
commit3d85518bf58a7052ff18e2c33547ceefac5c1939 (patch)
treefa5a27417d13bc0574258d61108c1d85cdcfefa8
parent3bb179570aaa834cd629e2a9e5811a2600c35bc9 (diff)
trace-cmd: Have listen clean up children with signals
Clean up the children that are created by a client with signals instead of leaving them around as zombies until another connection is made. This is a much cleaner solution. Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
-rw-r--r--trace-listen.c21
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
373static int do_fork(int cfd) 373static 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
439static 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
446static void do_listen(char *port) 450static 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;