1 /* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2021-2024 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18 #include <unistd.h> 19 20 #include <string.h> 21 #include <limits.h> 22 #include <stdio.h> 23 24 static volatile int unblock_parent = 0; 25 26 static void 27 break_parent (void) 28 { 29 } 30 31 int 32 main (int argc, char **argv) 33 { 34 alarm (30); 35 36 if (vfork () != 0) 37 { 38 /* We want to guarantee that GDB processes the child exit event before 39 the parent's breakpoint hit event. Make the parent wait on this 40 variable that is eventually set by the test. */ 41 while (!unblock_parent) 42 usleep (1000); 43 44 break_parent (); 45 } 46 else 47 { 48 #if defined TEST_EXEC 49 char prog[PATH_MAX]; 50 int len; 51 52 strcpy (prog, argv[0]); 53 len = strlen (prog); 54 for (; len > 0; --len) 55 { 56 if (prog[len - 1] == '/') 57 break; 58 } 59 strcpy (&prog[len], "vforked-prog"); 60 execlp (prog, prog, (char *) 0); 61 perror ("exec failed"); 62 _exit (1); 63 #elif defined TEST_EXIT 64 _exit (0); 65 #else 66 #error Define TEST_EXEC or TEST_EXIT 67 #endif 68 } 69 70 return 0; 71 } 72