1 /* Copyright (C) 2017-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
23 #include <support/check.h>
25 /* Try executing "/bin/sh -c true", using FD opened on /bin/sh. */
33 static const char *const argv
[] = {
34 "/bin/sh", "-c", "true", NULL
36 fexecve (fd
, (char *const *) argv
, environ
);
40 FAIL_RET ("fork failed: %m");
44 termpid
= TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0));
46 FAIL_RET ("waitpid failed: %m");
48 FAIL_RET ("waitpid returned %ld != %ld",
49 (long int) termpid
, (long int) pid
);
50 if (!WIFEXITED (status
))
51 FAIL_RET ("child hasn't exited normally");
53 /* If fexecve is unimplemented mark this test as UNSUPPORTED. */
54 if (WEXITSTATUS (status
) == ENOSYS
)
55 FAIL_UNSUPPORTED ("fexecve is unimplemented");
57 if (WEXITSTATUS (status
) != 0)
59 errno
= WEXITSTATUS (status
);
60 FAIL_RET ("fexecve failed: %m");
71 fd
= open ("/bin/sh", O_RDONLY
);
73 FAIL_UNSUPPORTED ("/bin/sh cannot be opened: %m");
74 ret
= try_fexecve (fd
);
78 fd
= open ("/bin/sh", O_RDONLY
| O_PATH
);
80 FAIL_UNSUPPORTED ("/bin/sh cannot be opened (O_PATH): %m");
81 ret
|= try_fexecve (fd
);
88 #include <support/test-driver.c>