1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2018 Linux Test Project
4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (C) 2015 Cyril Hrubis <[email protected]>
5*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
6*49cdfc7eSAndroid Build Coastguard Worker * AUTHOR : William Roske
7*49cdfc7eSAndroid Build Coastguard Worker * CO-PILOT : Dave Fenner
8*49cdfc7eSAndroid Build Coastguard Worker */
9*49cdfc7eSAndroid Build Coastguard Worker
10*49cdfc7eSAndroid Build Coastguard Worker #include <errno.h>
11*49cdfc7eSAndroid Build Coastguard Worker #include <string.h>
12*49cdfc7eSAndroid Build Coastguard Worker #include <signal.h>
13*49cdfc7eSAndroid Build Coastguard Worker #include <stdio.h>
14*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h>
15*49cdfc7eSAndroid Build Coastguard Worker #include <sys/types.h>
16*49cdfc7eSAndroid Build Coastguard Worker #include <sys/wait.h>
17*49cdfc7eSAndroid Build Coastguard Worker
18*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
19*49cdfc7eSAndroid Build Coastguard Worker
verify_execve(void)20*49cdfc7eSAndroid Build Coastguard Worker static void verify_execve(void)
21*49cdfc7eSAndroid Build Coastguard Worker {
22*49cdfc7eSAndroid Build Coastguard Worker pid_t pid;
23*49cdfc7eSAndroid Build Coastguard Worker char *const args[] = {"execve01_child", "canary", NULL};
24*49cdfc7eSAndroid Build Coastguard Worker char path[512];
25*49cdfc7eSAndroid Build Coastguard Worker
26*49cdfc7eSAndroid Build Coastguard Worker char ipc_env_var[1024];
27*49cdfc7eSAndroid Build Coastguard Worker sprintf(ipc_env_var, IPC_ENV_VAR "=%s", getenv(IPC_ENV_VAR));
28*49cdfc7eSAndroid Build Coastguard Worker
29*49cdfc7eSAndroid Build Coastguard Worker char *const envp[] = { "LTP_TEST_ENV_VAR=test", ipc_env_var, NULL };
30*49cdfc7eSAndroid Build Coastguard Worker
31*49cdfc7eSAndroid Build Coastguard Worker if (tst_get_path("execve01_child", path, sizeof(path)))
32*49cdfc7eSAndroid Build Coastguard Worker tst_brk(TCONF, "Couldn't find execve01_child in $PATH");
33*49cdfc7eSAndroid Build Coastguard Worker
34*49cdfc7eSAndroid Build Coastguard Worker pid = SAFE_FORK();
35*49cdfc7eSAndroid Build Coastguard Worker if (pid == 0) {
36*49cdfc7eSAndroid Build Coastguard Worker execve(path, args, envp);
37*49cdfc7eSAndroid Build Coastguard Worker tst_brk(TFAIL | TERRNO, "Failed to execute execve01_child");
38*49cdfc7eSAndroid Build Coastguard Worker }
39*49cdfc7eSAndroid Build Coastguard Worker }
40*49cdfc7eSAndroid Build Coastguard Worker
41*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
42*49cdfc7eSAndroid Build Coastguard Worker .forks_child = 1,
43*49cdfc7eSAndroid Build Coastguard Worker .child_needs_reinit = 1,
44*49cdfc7eSAndroid Build Coastguard Worker .test_all = verify_execve,
45*49cdfc7eSAndroid Build Coastguard Worker };
46