powerpc64le: use common fmaf128 implementation
[glibc.git] / nptl / tst-exec2.c
blobf57903da1e7c052866dc1a5332d125cb25992644
1 /* Thread with running thread calls exec.
2 Copyright (C) 2002-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
20 #include <errno.h>
21 #include <paths.h>
22 #include <pthread.h>
23 #include <signal.h>
24 #include <spawn.h>
25 #include <stdbool.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <unistd.h>
29 #include <sys/wait.h>
30 #include <support/xsignal.h>
33 static void *
34 tf (void *arg)
36 pthread_t th = (pthread_t) arg;
38 if (pthread_join (th, NULL) == 0)
40 puts ("thread in parent joined!?");
41 exit (1);
44 puts ("join in thread in parent returned!?");
45 exit (1);
49 static int
50 do_test (void)
52 int fd[2];
53 if (pipe (fd) != 0)
55 puts ("pipe failed");
56 exit (1);
59 /* Not interested in knowing when the pipe is closed. */
60 xsignal (SIGPIPE, SIG_IGN);
62 pid_t pid = fork ();
63 if (pid == -1)
65 puts ("fork failed");
66 exit (1);
69 if (pid == 0)
71 /* Use the fd for stdout. This is kind of ugly because it
72 substitutes the fd of stdout but we know what we are doing
73 here... */
74 if (dup2 (fd[1], STDOUT_FILENO) != STDOUT_FILENO)
76 puts ("dup2 failed");
77 exit (1);
80 close (fd[0]);
82 pthread_t th;
83 if (pthread_create (&th, NULL, tf, (void *) pthread_self ()) != 0)
85 puts ("create failed");
86 exit (1);
89 execl (_PATH_BSHELL, _PATH_BSHELL, "-c", "echo $$", NULL);
91 puts ("execl failed");
92 exit (1);
95 close (fd[1]);
97 char buf[200];
98 ssize_t n;
99 bool seen_pid = false;
100 while (TEMP_FAILURE_RETRY ((n = read (fd[0], buf, sizeof (buf)))) > 0)
102 /* We only expect to read the PID. */
103 char *endp;
104 long int rpid = strtol (buf, &endp, 10);
106 if (*endp != '\n')
108 printf ("didn't parse whole line: \"%s\"\n", buf);
109 exit (1);
111 if (endp == buf)
113 puts ("read empty line");
114 exit (1);
117 if (rpid != pid)
119 printf ("found \"%s\", expected PID %ld\n", buf, (long int) pid);
120 exit (1);
123 if (seen_pid)
125 puts ("found more than one PID line");
126 exit (1);
128 seen_pid = true;
131 close (fd[0]);
133 int status;
134 int err = waitpid (pid, &status, 0);
135 if (err != pid)
137 puts ("waitpid failed");
138 exit (1);
141 if (!seen_pid)
143 puts ("didn't get PID");
144 exit (1);
147 return 0;
150 #define TEST_FUNCTION do_test ()
151 #include "../test-skeleton.c"