this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge pull request #1559 from everything411/shellspawn-zombie

Correctly handle the shellspawn zombie

authored by

CuriousTommy and committed by
GitHub
a458d15d d2108447

+14 -6
+14 -6
src/shellspawn/shellspawn.c
··· 39 39 #define DBG 0 40 40 41 41 int g_serverSocket = -1; 42 + struct sigaction sigchld_oldaction; 42 43 43 44 void setupSocket(void); 44 45 void listenForConnections(void); 45 46 void spawnShell(int fd); 46 47 void setupSigchild(void); 48 + void restoreSigchild(void); 47 49 void reapAll(void); 48 50 49 51 int main(int argc, const char** argv) 50 52 { 51 - // in order to read the exit status of the process, 52 - // we have to allow it to become a zombie, which is prevented 53 - // when we set the SIGCHLD signal to SA_NOCLDWAIT 54 - //setupSigchild(); 53 + // shellspawn (daemon) --fork()--> shellspawn (child) --fork()--> exec /bin/bash 54 + // in order to read the exit status of the shell process, 55 + // we have to allow it to become a zombie, therefore we need to 56 + // restore the sigaction of SIGCHLD of the child shellspawn 57 + setupSigchild(); 55 58 setupSocket(); 56 59 listenForConnections(); 57 60 ··· 106 109 107 110 if (fork() == 0) 108 111 { 112 + restoreSigchild(); 109 113 fcntl(sock, F_SETFD, FD_CLOEXEC); 110 114 spawnShell(sock); 111 115 exit(EXIT_SUCCESS); ··· 113 117 else 114 118 { 115 119 close(sock); 116 - reapAll(); 117 120 } 118 121 } 119 122 } ··· 433 436 .sa_handler = SIG_DFL, 434 437 .sa_flags = SA_NOCLDWAIT 435 438 }; 436 - sigaction(SIGCHLD, &sigchld_action, NULL); 439 + sigaction(SIGCHLD, &sigchld_action, &sigchld_oldaction); 440 + } 441 + 442 + void restoreSigchild(void) 443 + { 444 + sigaction(SIGCHLD, &sigchld_oldaction, NULL); 437 445 } 438 446 439 447 void reapAll(void)