]> git.ipfire.org Git - thirdparty/glibc.git/blob - posix/tst-spawn4-compat.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / posix / tst-spawn4-compat.c
1 /* Check if posix_spawn does handle correctly ENOEXEC files.
2 Copyright (C) 2018-2020 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19 #include <spawn.h>
20 #include <errno.h>
21 #include <unistd.h>
22 #include <sys/stat.h>
23 #include <sys/wait.h>
24
25 #include <support/xunistd.h>
26 #include <support/check.h>
27 #include <support/temp_file.h>
28
29 #include <shlib-compat.h>
30 #if TEST_COMPAT (libc, GLIBC_2_0, GLIBC_2_15)
31
32 compat_symbol_reference (libc, posix_spawn, posix_spawn, GLIBC_2_2);
33 compat_symbol_reference (libc, posix_spawnp, posix_spawnp, GLIBC_2_2);
34
35 static int
36 do_test (void)
37 {
38 char *scriptname;
39 int fd = create_temp_file ("tst-spawn4.", &scriptname);
40 TEST_VERIFY_EXIT (fd >= 0);
41
42 const char script[] = "exit 65";
43 xwrite (fd, script, sizeof (script) - 1);
44 xclose (fd);
45
46 TEST_VERIFY_EXIT (chmod (scriptname, 0x775) == 0);
47
48 pid_t pid;
49 int status;
50
51 /* For compat symbol it verifies that trying to issued a shell script
52 without a shebang is correctly executed. */
53 status = posix_spawn (&pid, scriptname, NULL, NULL, (char *[]) { 0 },
54 (char *[]) { 0 });
55 TEST_VERIFY_EXIT (status == 0);
56
57 TEST_VERIFY_EXIT (waitpid (pid, &status, 0) == pid);
58 TEST_VERIFY_EXIT (WIFEXITED (status) == 1 && WEXITSTATUS (status) == 65);
59
60 status = posix_spawnp (&pid, scriptname, NULL, NULL, (char *[]) { 0 },
61 (char *[]) { 0 });
62 TEST_VERIFY_EXIT (status == 0);
63
64 TEST_VERIFY_EXIT (waitpid (pid, &status, 0) == pid);
65 TEST_VERIFY_EXIT (WIFEXITED (status) == 1 && WEXITSTATUS (status) == 65);
66
67 return 0;
68 }
69 #else
70 static int
71 do_test (void)
72 {
73 return 77;
74 }
75 #endif
76
77 #include <support/test-driver.c>