@@ -156,11 +156,14 @@ private static Child getChildByID(int childID) {
156156
157157 private static void dispatchEvent (Child c , Event event ) {
158158 boolean crash = false ;
159+ boolean terminated = false ;
160+
159161 if (event instanceof ChildEnd ) {
160162 c .exitValue = ((ChildEnd ) event ).exit_status ;
161163 Logger .debug ("Child #" + c .id + " exited ( exitValue=" + c .exitValue + " )" );
162164 if (c .receiver != null )
163165 c .receiver .onEnd (c .exitValue );
166+ terminated = true ;
164167 crash = c .exitValue > 126 && c .exitValue != 130 && c .exitValue != 137 && c .exitValue < 150 ;
165168 if (crash ) {
166169 c .signal = c .exitValue - 128 ;
@@ -170,6 +173,7 @@ private static void dispatchEvent(Child c, Event event) {
170173 Logger .debug ("Child #" + c .id + " died ( signal=" + c .signal + " )" );
171174 if (c .receiver != null )
172175 c .receiver .onDeath (c .signal );
176+ terminated = true ;
173177 crash = c .signal != 2 && c .signal != 9 ;
174178 } else if (event instanceof StderrNewline ) {
175179 if (c .receiver != null )
@@ -178,6 +182,14 @@ private static void dispatchEvent(Child c, Event event) {
178182 c .receiver .onEvent (event );
179183 }
180184
185+ if (terminated ) {
186+ synchronized (children ) {
187+ c .running = false ;
188+ children .remove (c );
189+ children .notifyAll ();
190+ }
191+ }
192+
181193 if (crash ) {
182194 CrashReporter .notifyChildCrashed (c .id , c .signal );
183195 }
@@ -192,14 +204,6 @@ private static void dispatchEvent(Child c, Event event) {
192204 */
193205 public static void onEvent (final int childID , final Event event ) {
194206 Child c ;
195- boolean end , died ;
196-
197- died = false ;
198-
199- end = event instanceof ChildEnd ;
200- if (!end ) {
201- died = event instanceof ChildDied ;
202- }
203207
204208 if (!(event instanceof Newline )) {
205209 Logger .debug ("received an event: " + event );
@@ -225,14 +229,6 @@ public void run() {
225229 dispatchEvent (fc , event );
226230 }
227231 });
228-
229- if (end || died ) {
230- synchronized (children ) {
231- c .running = false ;
232- children .remove (c );
233- children .notifyAll ();
234- }
235- }
236232 }
237233
238234 public static class ChildDiedException extends Exception {
0 commit comments