1 /* Further tests for spawn in case of invalid binary paths.
2 Copyright (C) 2016-2024 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
28 #include <support/check.h>
29 #include <tst-spawn.h>
34 /* Check if posix_spawn correctly returns an error and an invalid pid
35 by trying to spawn an invalid binary. */
37 const char *program
= "/path/to/invalid/binary";
38 char * const args
[] = { 0 };
41 int ret
= POSIX_SPAWN (&pid
, program
, 0, 0, args
, environ
);
45 FAIL_EXIT1 ("posix_spawn: %m");
48 /* POSIX states the value returned on pid variable in case of an error
49 is not specified. GLIBC will update the value iff the child
50 execution is successful. */
52 FAIL_EXIT1 ("posix_spawn returned pid != -1 (%i)", (int) pid
);
54 /* Check if no child is actually created. */
55 TEST_COMPARE (WAITID (P_ALL
, 0, NULL
, WEXITED
), -1);
56 TEST_COMPARE (errno
, ECHILD
);
58 /* Same as before, but with posix_spawnp. */
59 char *args2
[] = { (char*) program
, 0 };
61 ret
= POSIX_SPAWNP (&pid
, args2
[0], 0, 0, args2
, environ
);
65 FAIL_EXIT1 ("posix_spawnp: %m");
69 FAIL_EXIT1 ("posix_spawnp returned pid != -1 (%i)", (int) pid
);
71 TEST_COMPARE (WAITID (P_ALL
, 0, NULL
, WEXITED
), -1);
72 TEST_COMPARE (errno
, ECHILD
);
77 #include <support/test-driver.c>