From 13dea84f03192994a1809f76db41c506ec82e916 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 5 Jun 2012 05:33:46 +0200 Subject: Fix silly error in waiting. --- honeypot.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'honeypot.c') diff --git a/honeypot.c b/honeypot.c index 9d120b0..987f421 100644 --- a/honeypot.c +++ b/honeypot.c @@ -128,8 +128,8 @@ void SIGCHLD_handler(int sig) { int status; pid_t pid; - - while ((pid = wait(-1, &status, WNOHANG)) > 0) + + while ((pid = waitpid(-1, &status, WNOHANG)) > 0) printf("Process %d has exited with code %d.\n", pid, WEXITSTATUS(status)); } @@ -647,14 +647,16 @@ int main(int argc, char *argv[]) (connection_fd = accept(listen_fd, (struct sockaddr *)&connection_addr, &connection_addr_len)) >= 0) { child = fork(); if (child < 0) { - close(connection_fd); perror("fork"); + close(connection_fd); continue; } if (!child) { char ipaddr[INET6_ADDRSTRLEN]; struct in6_addr *v6; - + prctl(PR_SET_PDEATHSIG, SIGHUP); + if (getppid() == 1) + kill(getpid(), SIGHUP); prctl(PR_SET_NAME, "honeypot serve"); close(listen_fd); memset(ipaddr, 0, sizeof(ipaddr)); -- cgit v1.2.3-59-g8ed1b