Mercurial > dropbear
comparison svr-chansession.c @ 341:2eb5a8514905
Make flow of execution clearer for getting process exit status
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 07 Jul 2006 09:18:05 +0000 |
parents | d6b8815a9b5e |
children | 01e4180895ba |
comparison
equal
deleted
inserted
replaced
340:454a34b2dfd1 | 341:2eb5a8514905 |
---|---|
86 struct sigaction sa_chld; | 86 struct sigaction sa_chld; |
87 struct exitinfo *exit = NULL; | 87 struct exitinfo *exit = NULL; |
88 | 88 |
89 TRACE(("enter sigchld handler")) | 89 TRACE(("enter sigchld handler")) |
90 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { | 90 while ((pid = waitpid(-1, &status, WNOHANG)) > 0) { |
91 | |
92 exit = NULL; | |
91 /* find the corresponding chansess */ | 93 /* find the corresponding chansess */ |
92 for (i = 0; i < svr_ses.childpidsize; i++) { | 94 for (i = 0; i < svr_ses.childpidsize; i++) { |
93 if (svr_ses.childpids[i].pid == pid) { | 95 if (svr_ses.childpids[i].pid == pid) { |
94 | 96 |
95 exit = &svr_ses.childpids[i].chansess->exit; | 97 exit = &svr_ses.childpids[i].chansess->exit; |
97 } | 99 } |
98 } | 100 } |
99 | 101 |
100 /* If the pid wasn't matched, then we might have hit the race mentioned | 102 /* If the pid wasn't matched, then we might have hit the race mentioned |
101 * above. So we just store the info for the parent to deal with */ | 103 * above. So we just store the info for the parent to deal with */ |
102 if (i == svr_ses.childpidsize) { | 104 if (!exit) { |
103 exit = &svr_ses.lastexit; | 105 exit = &svr_ses.lastexit; |
104 } | 106 } |
105 | 107 |
106 exit->exitpid = pid; | 108 exit->exitpid = pid; |
107 if (WIFEXITED(status)) { | 109 if (WIFEXITED(status)) { |
116 #endif | 118 #endif |
117 } else { | 119 } else { |
118 /* we use this to determine how pid exited */ | 120 /* we use this to determine how pid exited */ |
119 exit->exitsignal = -1; | 121 exit->exitsignal = -1; |
120 } | 122 } |
121 exit = NULL; | |
122 } | 123 } |
123 | 124 |
124 | 125 |
125 sa_chld.sa_handler = sesssigchild_handler; | 126 sa_chld.sa_handler = sesssigchild_handler; |
126 sa_chld.sa_flags = SA_NOCLDSTOP; | 127 sa_chld.sa_flags = SA_NOCLDSTOP; |