1 /* Verify that the parent pid is unchanged by __clone_internal.
2 Copyright (C) 2021-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library 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 GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
24 #include <sys/types.h>
26 #include <clone_internal.h>
27 #include <support/xunistd.h>
29 #ifndef TEST_CLONE_FLAGS
30 #define TEST_CLONE_FLAGS 0
40 sival
.sival_int
= getpid ();
41 printf ("pid = %d\n", sival
.sival_int
);
42 if (sigqueue (getppid (), sig
, sival
) != 0)
51 int mypid
= getpid ();
57 if (sigprocmask (SIG_BLOCK
, &ss
, NULL
) != 0)
59 printf ("sigprocmask failed: %m\n");
64 # define STACK_SIZE 256 * 1024
66 # define STACK_SIZE 128 * 1024
68 char st
[STACK_SIZE
] __attribute__ ((aligned
));
69 struct clone_args clone_args
=
71 .flags
= TEST_CLONE_FLAGS
& ~CSIGNAL
,
72 .exit_signal
= TEST_CLONE_FLAGS
& CSIGNAL
,
73 .stack
= (uintptr_t) st
,
74 .stack_size
= sizeof (st
),
76 pid_t p
= __clone_internal (&clone_args
, f
, 0);
79 printf("clone failed: %m\n");
82 printf ("new thread: %d\n", (int) p
);
86 if (sigwaitinfo (&ss
, &si
) < 0)
88 printf("sigwaitinfo failed: %m\n");
92 while (si
.si_signo
!= sig
|| si
.si_code
!= SI_QUEUE
);
95 xwaitpid (p
, &e
, __WCLONE
);
99 printf ("died from signal %s\n", strsignal (WTERMSIG (e
)));
101 puts ("did not terminate correctly");
104 if (WEXITSTATUS (e
) != 0)
106 printf ("exit code %d\n", WEXITSTATUS (e
));
110 if (si
.si_int
!= (int) p
)
112 printf ("expected PID %d, got si_int %d\n", (int) p
, si
.si_int
);
119 printf ("expected PID %d, got si_pid %d\n", (int) p
, (int) si
.si_pid
);
124 if (getpid () != mypid
)
126 puts ("my PID changed");
133 #include <support/test-driver.c>