1 /* Simple exec test, only a thread in the parent.
2 Copyright (C) 2002-2023 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/>. */
29 #include <support/xsignal.h>
35 pthread_t th
= (pthread_t
) arg
;
37 if (pthread_join (th
, NULL
) == 0)
39 puts ("thread in parent joined!?");
43 puts ("join in thread in parent returned!?");
58 /* Not interested in knowing when the pipe is closed. */
59 xsignal (SIGPIPE
, SIG_IGN
);
61 posix_spawn_file_actions_t a
;
62 if (posix_spawn_file_actions_init (&a
) != 0)
64 puts ("spawn_file_actions_init failed");
68 if (posix_spawn_file_actions_adddup2 (&a
, fd
[1], STDOUT_FILENO
) != 0)
70 puts ("spawn_file_actions_adddup2 failed");
74 if (posix_spawn_file_actions_addclose (&a
, fd
[0]) != 0)
76 puts ("spawn_file_actions_addclose");
81 if (pthread_create (&th
, NULL
, tf
, (void *) pthread_self ()) != 0)
83 puts ("create failed");
88 char *argv
[] = { (char *) _PATH_BSHELL
, (char *) "-c", (char *) "echo $$",
90 if (posix_spawn (&pid
, _PATH_BSHELL
, &a
, NULL
, argv
, NULL
) != 0)
92 puts ("spawn failed");
100 bool seen_pid
= false;
101 while (TEMP_FAILURE_RETRY ((n
= read (fd
[0], buf
, sizeof (buf
)))) > 0)
103 /* We only expect to read the PID. */
105 long int rpid
= strtol (buf
, &endp
, 10);
109 printf ("didn't parse whole line: \"%s\"\n", buf
);
114 puts ("read empty line");
120 printf ("found \"%s\", expected PID %ld\n", buf
, (long int) pid
);
126 puts ("found more than one PID line");
136 int err
= waitpid (pid
, &status
, 0);
139 puts ("waitpid failed");
145 puts ("didn't get PID");
149 puts ("read correct PID");
154 #define TEST_FUNCTION do_test ()
155 #include "../test-skeleton.c"