1 /* General tests for execpve.
2 Copyright (C) 2016-2018 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 <http://www.gnu.org/licenses/>. */
27 /* Nonzero if the program gets called via `exec'. */
31 #define CMDLINE_OPTIONS \
32 { "restart", no_argument, &restart, 1 },
34 /* Prototype for our test function. */
35 extern void do_prepare (int argc
, char *argv
[]);
36 extern int do_test (int argc
, char *argv
[]);
38 #include "../test-skeleton.c"
40 #define EXECVPE_KEY "EXECVPE_ENV"
41 #define EXECVPE_VALUE "execvpe_test"
47 /* First check if only one variable is passed on execvpe. */
49 for (char **e
= environ
; *e
!= NULL
; ++e
)
50 if (++env_count
== INT_MAX
)
52 printf ("Environment variable number overflow");
57 printf ("Wrong number of environment variables");
61 /* Check if the combinarion os "EXECVPE_ENV=execvpe_test" */
62 const char *env
= getenv (EXECVPE_KEY
);
65 printf ("Test environment variable not found");
69 if (strncmp (env
, EXECVPE_VALUE
, sizeof (EXECVPE_VALUE
)))
71 printf ("Test environment variable with wrong value");
80 do_test (int argc
, char *argv
[])
86 - one or four parameters left if called initially
87 + path for ld.so optional
88 + "--library-path" optional
89 + the library path optional
90 + the application name
92 if --enable-hardcoded-path-in-tests is used, just
93 + the application name
100 printf ("Wrong number of arguments (%d) in restart\n", argc
);
104 return handle_restart ();
107 if (argc
!= 2 && argc
!= 5)
109 printf ("Wrong number of arguments (%d)\n", argc
);
113 /* We want to test the `execvpe' function. To do this we restart the
114 program with an additional parameter. */
118 /* This is the child. Construct the command line. */
120 /* We cast here to char* because the test itself does not modify neither
121 the argument nor the environment list. */
122 char *envs
[] = { (char*)(EXECVPE_KEY
"=" EXECVPE_VALUE
), NULL
};
125 char *args
[] = { argv
[1], argv
[2], argv
[3], argv
[4],
126 (char *) "--direct", (char *) "--restart", NULL
};
127 execvpe (args
[0], args
, envs
);
131 char *args
[] = { argv
[0],
132 (char *) "--direct", (char *) "--restart", NULL
};
133 execvpe (args
[0], args
, envs
);
136 puts ("Cannot exec");
139 else if (pid
== (pid_t
) -1)
141 puts ("Cannot fork");
145 /* Wait for the child. */
146 if (waitpid (pid
, &status
, 0) != pid
)
148 puts ("Wrong child");
152 if (WTERMSIG (status
) != 0)
154 puts ("Child terminated incorrectly");
157 status
= WEXITSTATUS (status
);