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