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 <errno.h> 11f08c3bdfSopenharmony_ci#include <string.h> 12f08c3bdfSopenharmony_ci#include <signal.h> 13f08c3bdfSopenharmony_ci#include <stdio.h> 14f08c3bdfSopenharmony_ci#include <stdlib.h> 15f08c3bdfSopenharmony_ci#include <sys/types.h> 16f08c3bdfSopenharmony_ci#include <sys/wait.h> 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci#include "tst_test.h" 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_cistatic void verify_execve(void) 21f08c3bdfSopenharmony_ci{ 22f08c3bdfSopenharmony_ci pid_t pid; 23f08c3bdfSopenharmony_ci char *const args[] = {"execve01_child", "canary", NULL}; 24f08c3bdfSopenharmony_ci char path[512]; 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci char ipc_env_var[1024]; 27f08c3bdfSopenharmony_ci sprintf(ipc_env_var, IPC_ENV_VAR "=%s", getenv(IPC_ENV_VAR)); 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ci char *const envp[] = { "LTP_TEST_ENV_VAR=test", ipc_env_var, NULL }; 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci if (tst_get_path("execve01_child", path, sizeof(path))) 32f08c3bdfSopenharmony_ci tst_brk(TCONF, "Couldn't find execve01_child in $PATH"); 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci pid = SAFE_FORK(); 35f08c3bdfSopenharmony_ci if (pid == 0) { 36f08c3bdfSopenharmony_ci execve(path, args, envp); 37f08c3bdfSopenharmony_ci tst_brk(TFAIL | TERRNO, "Failed to execute execve01_child"); 38f08c3bdfSopenharmony_ci } 39f08c3bdfSopenharmony_ci} 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_cistatic struct tst_test test = { 42f08c3bdfSopenharmony_ci .forks_child = 1, 43f08c3bdfSopenharmony_ci .child_needs_reinit = 1, 44f08c3bdfSopenharmony_ci .test_all = verify_execve, 45f08c3bdfSopenharmony_ci}; 46