1// SPDX-License-Identifier: GPL-2.0-or-later 2/* 3 * Copyright (c) International Business Machines Corp., 2001 4 * 5 * 1) kill() fails with errno set to EINVAL if given an invalid signal. 6 * 2) kill() fails with errno set to ESRCH if given a non-existent pid. 7 * 3) kill() fails with errno set to ESRCH if the given pid is INT_MIN. 8 * 9 * HISTORY 10 * 07/2001 Ported by Wayne Boyer 11 */ 12 13#include <sys/types.h> 14#include <signal.h> 15#include <unistd.h> 16#include "tst_test.h" 17 18static pid_t real_pid, fake_pid, int_min_pid; 19 20static struct tcase { 21 int test_sig; 22 int exp_errno; 23 pid_t *pid; 24} tcases[] = { 25 {2000, EINVAL, &real_pid}, 26 {SIGKILL, ESRCH, &fake_pid}, 27 {SIGKILL, ESRCH, &int_min_pid} 28}; 29 30static void verify_kill(unsigned int n) 31{ 32 struct tcase *tc = &tcases[n]; 33 34 TEST(kill(*tc->pid, tc->test_sig)); 35 if (TST_RET != -1) { 36 tst_res(TFAIL, "kill should fail but not, return %ld", TST_RET); 37 return; 38 } 39 40 if (tc->exp_errno == TST_ERR) 41 tst_res(TPASS | TTERRNO, "kill failed as expected"); 42 else 43 tst_res(TFAIL | TTERRNO, "kill expected %s but got", 44 tst_strerrno(tc->exp_errno)); 45} 46 47static void setup(void) 48{ 49 real_pid = getpid(); 50 fake_pid = tst_get_unused_pid(); 51 int_min_pid = INT_MIN; 52} 53 54static struct tst_test test = { 55 .test = verify_kill, 56 .tcnt = ARRAY_SIZE(tcases), 57 .setup = setup, 58}; 59