1 /* Simple exec test, only a thread in the parent.
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, write to the Free
18 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
36 pthread_t th
= (pthread_t
) arg
;
38 if (pthread_join (th
, NULL
) == 0)
40 puts ("thread in parent joined!?");
44 puts ("join in thread in parent returned!?");
59 /* Not interested in knowing when the pipe is closed. */
60 if (sigignore (SIGPIPE
) != 0)
62 puts ("sigignore failed");
66 posix_spawn_file_actions_t a
;
67 if (posix_spawn_file_actions_init (&a
) != 0)
69 puts ("spawn_file_actions_init failed");
73 if (posix_spawn_file_actions_adddup2 (&a
, fd
[1], STDOUT_FILENO
) != 0)
75 puts ("spawn_file_actions_adddup2 failed");
79 if (posix_spawn_file_actions_addclose (&a
, fd
[0]) != 0)
81 puts ("spawn_file_actions_addclose");
86 if (pthread_create (&th
, NULL
, tf
, (void *) pthread_self ()) != 0)
88 puts ("create failed");
93 char *argv
[] = { (char *) _PATH_BSHELL
, (char *) "-c", (char *) "echo $$",
95 if (posix_spawn (&pid
, _PATH_BSHELL
, &a
, NULL
, argv
, NULL
) != 0)
97 puts ("spawn failed");
105 bool seen_pid
= false;
106 while (TEMP_FAILURE_RETRY ((n
= read (fd
[0], buf
, sizeof (buf
)))) > 0)
108 /* We only expect to read the PID. */
110 long int rpid
= strtol (buf
, &endp
, 10);
114 printf ("didn't parse whole line: \"%s\"\n", buf
);
119 puts ("read empty line");
125 printf ("found \"%s\", expected PID %ld\n", buf
, (long int) pid
);
131 puts ("found more than one PID line");
141 int err
= waitpid (pid
, &status
, 0);
144 puts ("waitpid failed");
150 puts ("didn't get PID");
154 puts ("read correct PID");
159 #define TEST_FUNCTION do_test ()
160 #include "../test-skeleton.c"