inet/resolv: Try search domains first for unqualified names
[uclibc-ng.git] / test / nptl / tst-exec2.c
blob061e3fc7c66f7eef0ea463c0ede77ace3b859403
1 /* Thread with running thread calls exec.
2 Copyright (C) 2002 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 <http://www.gnu.org/licenses/>. */
20 #include <errno.h>
21 #include <paths.h>
22 #include <pthread.h>
23 #include <signal.h>
24 #include <stdbool.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <sys/wait.h>
31 static void *
32 tf (void *arg)
34 pthread_t th = (pthread_t) arg;
36 if (pthread_join (th, NULL) == 0)
38 puts ("thread in parent joined!?");
39 exit (1);
42 puts ("join in thread in parent returned!?");
43 exit (1);
47 static int
48 do_test (void)
50 int fd[2];
51 if (pipe (fd) != 0)
53 puts ("pipe failed");
54 exit (1);
57 /* Not interested in knowing when the pipe is closed. */
58 if (sigignore (SIGPIPE) != 0)
60 puts ("sigignore failed");
61 exit (1);
64 pid_t pid = fork ();
65 if (pid == -1)
67 puts ("fork failed");
68 exit (1);
71 if (pid == 0)
73 /* Use the fd for stdout. This is kind of ugly because it
74 substitutes the fd of stdout but we know what we are doing
75 here... */
76 if (dup2 (fd[1], STDOUT_FILENO) != STDOUT_FILENO)
78 puts ("dup2 failed");
79 exit (1);
82 close (fd[0]);
84 pthread_t th;
85 if (pthread_create (&th, NULL, tf, (void *) pthread_self ()) != 0)
87 puts ("create failed");
88 exit (1);
91 execl (_PATH_BSHELL, _PATH_BSHELL, "-c", "echo $$", NULL);
93 puts ("execl failed");
94 exit (1);
97 close (fd[1]);
99 char buf[200];
100 ssize_t n;
101 bool seen_pid = false;
102 while (TEMP_FAILURE_RETRY ((n = read (fd[0], buf, sizeof (buf)))) > 0)
104 /* We only expect to read the PID. */
105 char *endp;
106 long int rpid = strtol (buf, &endp, 10);
108 if (*endp != '\n')
110 printf ("didn't parse whole line: \"%s\"\n", buf);
111 exit (1);
113 if (endp == buf)
115 puts ("read empty line");
116 exit (1);
119 if (rpid != pid)
121 printf ("found \"%s\", expected PID %ld\n", buf, (long int) pid);
122 exit (1);
125 if (seen_pid)
127 puts ("found more than one PID line");
128 exit (1);
130 seen_pid = true;
133 close (fd[0]);
135 int status;
136 int err = waitpid (pid, &status, 0);
137 if (err != pid)
139 puts ("waitpid failed");
140 exit (1);
143 if (!seen_pid)
145 puts ("didn't get PID");
146 exit (1);
149 return 0;
152 #define TEST_FUNCTION do_test ()
153 #include "../test-skeleton.c"