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