1 /*
2 * Check status=detached filtering when a non-leader thread invokes execve.
3 *
4 * Copyright (c) 2019 Paul Chaignon <paul.chaignon@gmail.com>
5 * Copyright (c) 2022 Dmitry V. Levin <ldv@strace.io>
6 * All rights reserved.
7 *
8 * SPDX-License-Identifier: GPL-2.0-or-later
9 */
10
11 #include "tests.h"
12 #include "scno.h"
13
14 #include <errno.h>
15 #include <pthread.h>
16 #include <stdio.h>
17 #include <time.h>
18 #include <unistd.h>
19
20 static void *
21 thread(void *arg)
22 {
23 struct timespec ts = { .tv_nsec = 100000000 };
24 nanosleep(&ts, 0);
25
26 char *argv[] = {((char **) arg)[0], (char *) "0", NULL};
27 pid_t pid = getpid();
28 pid_t tid = syscall(__NR_gettid);
29
30 printf("%-5d execve(\"%s\", [\"%s\", \"0\"], NULL <pid changed to %u ...>\n"
31 "%-5d +++ superseded by execve in pid %u +++\n"
32 "%-5d +++ exited with 0 +++\n",
33 tid, argv[0], argv[0], pid, pid, tid, pid);
34
35 execve(argv[0], argv, NULL);
36 perror_msg_and_fail("execve");
37 }
38
39 int
40 main(int ac, char **av)
41 {
42 setvbuf(stdout, NULL, _IONBF, 0);
43
44 if (ac > 1)
45 return 0;
46
47 pthread_t t;
48 errno = pthread_create(&t, NULL, thread, av);
49 if (errno)
50 perror_msg_and_fail("pthread_create");
51
52 struct timespec ts = { .tv_sec = 123 };
53 nanosleep(&ts, 0);
54
55 return 1;
56 }