GNU Binutils with patches for OS216
Revision | 14897d65b5a279684289bf6b99136de60c31f1c0 (tree) |
---|---|
Time | 2018-06-15 01:47:03 |
Author | Pedro Alves <palves@redh...> |
Commiter | Pedro Alves |
Avoid gdb.base/fork-running-state.exp lingering processes
Currently, the gdb.base/fork-running-state.exp testcase leaves a few
processes lingering until a 3 minutes alarm kills them:
Those processes used to kill themselves, but that was changed by
commit f50d8a2eaea0 ("Fix gdb.base/fork-running-state.exp race").
This commit restores the self-killing, but only in the cases gdb won't
try killing the processes, thus avoiding the old race.
(The restored code in fork_parent isn't exactly the same as it was.
In this version, we're exiting immediately when 'wait' returns
success, while in the old version we'd loop again and end up in the
perror call. The output from that perror call is not expected by the
"kill inferior" tests, and would result in a test FAIL.)
gdb/testsuite/ChangeLog:
2018-06-14 Pedro Alves <palves@redhat.com>
* gdb.base/fork-running-state.c: Include <errno.h>.
(exit_if_relative_exits): New.
(fork_child): If 'exit_if_relative_exits' is true, exit if the parent
exits.
(fork_parent): If 'exit_if_relative_exits' is true, exit if the
child exits.
@@ -1,3 +1,12 @@ | ||
1 | +2018-06-14 Pedro Alves <palves@redhat.com> | |
2 | + | |
3 | + * gdb.base/fork-running-state.c: Include <errno.h>. | |
4 | + (exit_if_relative_exits): New. | |
5 | + (fork_child): If 'exit_if_relative_exits' is true, exit if the parent | |
6 | + exits. | |
7 | + (fork_parent): If 'exit_if_relative_exits' is true, exit if the | |
8 | + child exits. | |
9 | + | |
1 | 10 | 2018-06-14 Tom de Vries <tdevries@suse.de> |
2 | 11 | |
3 | 12 | PR cli/22573 |
@@ -19,9 +19,15 @@ | ||
19 | 19 | #include <stdio.h> |
20 | 20 | #include <sys/types.h> |
21 | 21 | #include <sys/wait.h> |
22 | +#include <errno.h> | |
22 | 23 | |
23 | 24 | int save_parent; |
24 | 25 | |
26 | +/* Variable set by GDB. If true, then a fork child (or parent) exits | |
27 | + if its parent (or child) exits. Otherwise the process waits | |
28 | + forever until either GDB or the alarm kills it. */ | |
29 | +volatile int exit_if_relative_exits = 0; | |
30 | + | |
25 | 31 | /* The fork child. Just runs forever. */ |
26 | 32 | |
27 | 33 | static int |
@@ -31,7 +37,20 @@ fork_child (void) | ||
31 | 37 | alarm (180); |
32 | 38 | |
33 | 39 | while (1) |
34 | - pause (); | |
40 | + { | |
41 | + if (exit_if_relative_exits) | |
42 | + { | |
43 | + sleep (1); | |
44 | + | |
45 | + /* Exit if GDB kills the parent. */ | |
46 | + if (getppid () != save_parent) | |
47 | + break; | |
48 | + if (kill (getppid (), 0) != 0) | |
49 | + break; | |
50 | + } | |
51 | + else | |
52 | + pause (); | |
53 | + } | |
35 | 54 | |
36 | 55 | return 0; |
37 | 56 | } |
@@ -45,7 +64,23 @@ fork_parent (void) | ||
45 | 64 | alarm (180); |
46 | 65 | |
47 | 66 | while (1) |
48 | - pause (); | |
67 | + { | |
68 | + if (exit_if_relative_exits) | |
69 | + { | |
70 | + int res = wait (NULL); | |
71 | + if (res == -1 && errno == EINTR) | |
72 | + continue; | |
73 | + else if (res == -1) | |
74 | + { | |
75 | + perror ("wait"); | |
76 | + return 1; | |
77 | + } | |
78 | + else | |
79 | + return 0; | |
80 | + } | |
81 | + else | |
82 | + pause (); | |
83 | + } | |
49 | 84 | |
50 | 85 | return 0; |
51 | 86 | } |
@@ -70,6 +70,13 @@ proc do_test { detach_on_fork follow_fork non_stop schedule_multiple } { | ||
70 | 70 | gdb_test_no_output "set schedule-multiple $schedule_multiple" |
71 | 71 | } |
72 | 72 | |
73 | + # If we're detaching from the parent (or child), then tell it to | |
74 | + # exit itself when its child (or parent) exits. If we stay | |
75 | + # attached, we take care of killing it. | |
76 | + if {$detach_on_fork == "on"} { | |
77 | + gdb_test "print exit_if_relative_exits = 1" " = 1" | |
78 | + } | |
79 | + | |
73 | 80 | set test "continue &" |
74 | 81 | gdb_test_multiple $test $test { |
75 | 82 | -re "$gdb_prompt " { |