1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later 2*49cdfc7eSAndroid Build Coastguard Worker /* 3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) International Business Machines Corp., 2001 4*49cdfc7eSAndroid Build Coastguard Worker * Author: Wayne Boyer 5*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) Linux Test Project, 2002-2022 6*49cdfc7eSAndroid Build Coastguard Worker */ 7*49cdfc7eSAndroid Build Coastguard Worker 8*49cdfc7eSAndroid Build Coastguard Worker /*\ 9*49cdfc7eSAndroid Build Coastguard Worker * [Description] 10*49cdfc7eSAndroid Build Coastguard Worker * 11*49cdfc7eSAndroid Build Coastguard Worker * Verify that SIGALRM signal scheduled by alarm() in the parent process 12*49cdfc7eSAndroid Build Coastguard Worker * is not delivered to the child process. 13*49cdfc7eSAndroid Build Coastguard Worker */ 14*49cdfc7eSAndroid Build Coastguard Worker 15*49cdfc7eSAndroid Build Coastguard Worker #include <stdlib.h> 16*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h" 17*49cdfc7eSAndroid Build Coastguard Worker 18*49cdfc7eSAndroid Build Coastguard Worker static volatile int alarm_cnt; 19*49cdfc7eSAndroid Build Coastguard Worker verify_alarm(void)20*49cdfc7eSAndroid Build Coastguard Workerstatic void verify_alarm(void) 21*49cdfc7eSAndroid Build Coastguard Worker { 22*49cdfc7eSAndroid Build Coastguard Worker pid_t pid; 23*49cdfc7eSAndroid Build Coastguard Worker 24*49cdfc7eSAndroid Build Coastguard Worker alarm_cnt = 0; 25*49cdfc7eSAndroid Build Coastguard Worker 26*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_PASS_SILENT(alarm(1)); 27*49cdfc7eSAndroid Build Coastguard Worker pid = SAFE_FORK(); 28*49cdfc7eSAndroid Build Coastguard Worker 29*49cdfc7eSAndroid Build Coastguard Worker sleep(3); 30*49cdfc7eSAndroid Build Coastguard Worker 31*49cdfc7eSAndroid Build Coastguard Worker if (pid == 0) { 32*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_EQ_LU(alarm_cnt, 0); 33*49cdfc7eSAndroid Build Coastguard Worker exit(0); 34*49cdfc7eSAndroid Build Coastguard Worker } 35*49cdfc7eSAndroid Build Coastguard Worker 36*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_EQ_LU(alarm_cnt, 1); 37*49cdfc7eSAndroid Build Coastguard Worker } 38*49cdfc7eSAndroid Build Coastguard Worker sighandler(int sig LTP_ATTRIBUTE_UNUSED)39*49cdfc7eSAndroid Build Coastguard Workerstatic void sighandler(int sig LTP_ATTRIBUTE_UNUSED) 40*49cdfc7eSAndroid Build Coastguard Worker { 41*49cdfc7eSAndroid Build Coastguard Worker alarm_cnt++; 42*49cdfc7eSAndroid Build Coastguard Worker } 43*49cdfc7eSAndroid Build Coastguard Worker setup(void)44*49cdfc7eSAndroid Build Coastguard Workerstatic void setup(void) 45*49cdfc7eSAndroid Build Coastguard Worker { 46*49cdfc7eSAndroid Build Coastguard Worker SAFE_SIGNAL(SIGALRM, sighandler); 47*49cdfc7eSAndroid Build Coastguard Worker } 48*49cdfc7eSAndroid Build Coastguard Worker 49*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = { 50*49cdfc7eSAndroid Build Coastguard Worker .test_all = verify_alarm, 51*49cdfc7eSAndroid Build Coastguard Worker .setup = setup, 52*49cdfc7eSAndroid Build Coastguard Worker .forks_child = 1, 53*49cdfc7eSAndroid Build Coastguard Worker }; 54