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
20static void verify_execve(void)
21{
22	pid_t pid;
23	char *const args[] = {"execve01_child", "canary", NULL};
24	char path[512];
25
26	char ipc_env_var[1024];
27	sprintf(ipc_env_var, IPC_ENV_VAR "=%s", getenv(IPC_ENV_VAR));
28
29	char *const envp[] = { "LTP_TEST_ENV_VAR=test", ipc_env_var, NULL };
30
31	if (tst_get_path("execve01_child", path, sizeof(path)))
32		tst_brk(TCONF, "Couldn't find execve01_child in $PATH");
33
34	pid = SAFE_FORK();
35	if (pid == 0) {
36		execve(path, args, envp);
37		tst_brk(TFAIL | TERRNO, "Failed to execute execve01_child");
38	}
39}
40
41static struct tst_test test = {
42	.forks_child = 1,
43	.child_needs_reinit = 1,
44	.test_all = verify_execve,
45};
46