1 /* This testcase is part of GDB, the GNU debugger.
3 Copyright 2020-2022 Free Software Foundation, Inc.
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.
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.
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/>. */
24 #include "../lib/my-syscalls.h"
26 #if (!defined(LEADER_DOES_EXEC) && !defined(OTHER_DOES_EXEC) \
27 || defined(LEADER_DOES_EXEC) && defined(OTHER_DOES_EXEC))
28 # error "Exactly one of LEADER_DOES_EXEC and OTHER_DOES_EXEC must be defined."
33 static pthread_barrier_t barrier
;
38 char *execd_path
= (char *) malloc (strlen (argv0
) + sizeof ("-execd"));
39 sprintf (execd_path
, "%s-execd", argv0
);
40 char *argv
[] = { execd_path
, NULL
};
42 printf ("Exec-ing %s\n", execd_path
);
44 extern char **environ
;
45 my_execve (execd_path
, argv
, environ
);
47 printf ("Exec failed :(\n");
52 thread_func (void *arg
)
54 pthread_barrier_wait (&barrier
);
55 #ifdef OTHER_DOES_EXEC
56 printf ("Other going in exec.\n");
60 /* Just make sure the thread does not exit when the leader does the exec. */
61 pthread_barrier_wait (&barrier
);
67 main (int argc
, char *argv
[])
71 int ret
= pthread_barrier_init (&barrier
, NULL
, 2);
76 ret
= pthread_create (&thread
, NULL
, thread_func
, argv
[0]);
80 pthread_barrier_wait (&barrier
);
82 #ifdef LEADER_DOES_EXEC
83 printf ("Leader going in exec.\n");
87 pthread_join (thread
, NULL
);