1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * Copyright (c) 2012-2016 Cyril Hrubis <chrubis@suse.cz> 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/* 8f08c3bdfSopenharmony_ci * Testcase to check creat(2) sets ETXTBSY correctly. 9f08c3bdfSopenharmony_ci */ 10f08c3bdfSopenharmony_ci 11f08c3bdfSopenharmony_ci#include <sys/types.h> 12f08c3bdfSopenharmony_ci#include <sys/stat.h> 13f08c3bdfSopenharmony_ci#include <sys/wait.h> 14f08c3bdfSopenharmony_ci#include <stdio.h> 15f08c3bdfSopenharmony_ci#include <stdlib.h> 16f08c3bdfSopenharmony_ci#include <errno.h> 17f08c3bdfSopenharmony_ci#include <fcntl.h> 18f08c3bdfSopenharmony_ci#include "tst_test.h" 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_ci#define TEST_APP "creat07_child" 21f08c3bdfSopenharmony_ci 22f08c3bdfSopenharmony_cistatic void verify_creat(void) 23f08c3bdfSopenharmony_ci{ 24f08c3bdfSopenharmony_ci pid_t pid; 25f08c3bdfSopenharmony_ci 26f08c3bdfSopenharmony_ci pid = SAFE_FORK(); 27f08c3bdfSopenharmony_ci if (pid == 0) { 28f08c3bdfSopenharmony_ci SAFE_EXECL(TEST_APP, TEST_APP, NULL); 29f08c3bdfSopenharmony_ci exit(1); 30f08c3bdfSopenharmony_ci } 31f08c3bdfSopenharmony_ci 32f08c3bdfSopenharmony_ci TST_CHECKPOINT_WAIT(0); 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci TEST(creat(TEST_APP, O_WRONLY)); 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci if (TST_RET != -1) { 37f08c3bdfSopenharmony_ci tst_res(TFAIL, "creat() succeeded unexpectedly"); 38f08c3bdfSopenharmony_ci return; 39f08c3bdfSopenharmony_ci } 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci if (TST_ERR == ETXTBSY) 42f08c3bdfSopenharmony_ci tst_res(TPASS, "creat() received EXTBSY"); 43f08c3bdfSopenharmony_ci else 44f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "creat() failed unexpectedly"); 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_ci SAFE_KILL(pid, SIGKILL); 47f08c3bdfSopenharmony_ci SAFE_WAITPID(pid, NULL, 0); 48f08c3bdfSopenharmony_ci} 49f08c3bdfSopenharmony_ci 50f08c3bdfSopenharmony_cistatic struct tst_test test = { 51f08c3bdfSopenharmony_ci .test_all = verify_creat, 52f08c3bdfSopenharmony_ci .needs_checkpoints = 1, 53f08c3bdfSopenharmony_ci .forks_child = 1, 54f08c3bdfSopenharmony_ci .resource_files = (const char *const []) { 55f08c3bdfSopenharmony_ci TEST_APP, 56f08c3bdfSopenharmony_ci NULL 57f08c3bdfSopenharmony_ci } 58f08c3bdfSopenharmony_ci}; 59