1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
--- ppp-2.4.5/pppd/main.c
+++ ppp-2.4.5/pppd/main.c
@@ -249,6 +249,7 @@
static void forget_child __P((int pid, int status));
static int reap_kids __P((void));
static void childwait_end __P((void *));
+static void wait_children __P((void));
#ifdef USE_TDB
static void update_db_entry __P((void));
@@ -580,25 +581,11 @@
if (!persist)
break;
}
+
+ wait_children();
}
- /* Wait for scripts to finish */
- reap_kids();
- if (n_children > 0) {
- if (child_wait > 0)
- TIMEOUT(childwait_end, NULL, child_wait);
- if (debug) {
- struct subprocess *chp;
- dbglog("Waiting for %d child processes...", n_children);
- for (chp = children; chp != NULL; chp = chp->next)
- dbglog(" script %s, pid %d", chp->prog, chp->pid);
- }
- while (n_children > 0 && !childwait_done) {
- handle_events();
- if (kill_link && !childwait_done)
- childwait_end(NULL);
- }
- }
+ wait_children();
die(status);
return 0;
@@ -1794,6 +1781,36 @@
}
/*
+ * wait_children - wait for scripts to finish.
+ * if child_wait is 0, wait indefinitely.
+ * else, kill'em all at the end of timeout
+ */
+static void
+wait_children()
+{
+ /* Wait for scripts to finish */
+ reap_kids();
+ if (n_children > 0) {
+ childwait_done = 0;
+ if (child_wait > 0)
+ TIMEOUT(childwait_end, NULL, child_wait);
+ if (debug) {
+ struct subprocess *chp;
+ dbglog("Waiting for %d child processes...", n_children);
+ for (chp = children; chp != NULL; chp = chp->next)
+ dbglog(" script %s, pid %d", chp->prog, chp->pid);
+ }
+ while (n_children > 0 && !childwait_done) {
+ handle_events();
+ if (asked_to_quit && !childwait_done)
+ childwait_end(NULL);
+ }
+ if (child_wait > 0)
+ UNTIMEOUT(childwait_end, NULL);
+ }
+}
+
+/*
* childwait_end - we got fed up waiting for the child processes to
* exit, send them all a SIGTERM.
*/
|