1/* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include <errno.h> 17#include <signal.h> 18 19#include "test.h" 20 21/** 22 * @tc.name : sigignore_0100 23 * @tc.desc : sets the disposition of sig to SIG_IGN 24 * @tc.level : Level 0 25 */ 26void sigignore_0100(void) 27{ 28 int sig = SIGALRM; 29 struct sigaction old_act = {0}; 30 errno = 0; 31 int result = sigaction(sig, NULL, &old_act); 32 if (result != 0 || errno != 0) { 33 t_error("%s failed: result = %d\n", __func__, result); 34 t_error("%s failed: errno = %d\n", __func__, errno); 35 } 36 37 errno = 0; 38 result = sigignore(sig); 39 if (result != 0 || errno != 0) { 40 t_error("%s failed: result = %d\n", __func__, result); 41 t_error("%s failed: errno = %d\n", __func__, errno); 42 } 43 44 struct sigaction sa; 45 errno = 0; 46 result = sigaction(SIGALRM, NULL, &sa); 47 if (result != 0 || errno != 0) { 48 t_error("%s failed: result = %d\n", __func__, result); 49 t_error("%s failed: errno = %d\n", __func__, errno); 50 } 51 52 if (SIG_IGN != sa.sa_handler) { 53 t_error("%s failed: sa.sa_handler\n", __func__); 54 } 55} 56 57/** 58 * @tc.name : sigignore_0200 59 * @tc.desc : sets the disposition of the SIGKILL sig to SIG_IGN 60 * @tc.level : Level 1 61 */ 62void sigignore_0200(void) 63{ 64 errno = 0; 65 int result = sigignore(SIGKILL); 66 if (result != -1 || errno != EINVAL) { 67 t_error("%s failed: result = %d\n", __func__, result); 68 t_error("%s failed: errno = %d\n", __func__, errno); 69 } 70} 71 72/** 73 * @tc.name : sigignore_0300 74 * @tc.desc : sets the disposition of the SIGSTOP sig to SIG_IGN 75 * @tc.level : Level 1 76 */ 77void sigignore_0300(void) 78{ 79 errno = 0; 80 int result = sigignore(SIGSTOP); 81 if (result != -1 || errno != EINVAL) { 82 t_error("%s failed: result = %d\n", __func__, result); 83 t_error("%s failed: errno = %d\n", __func__, errno); 84 } 85} 86 87/** 88 * @tc.name : sigignore_0400 89 * @tc.desc : sets the disposition of an invalid sig to SIG_IGN 90 * @tc.level : Level 2 91 */ 92void sigignore_0400(void) 93{ 94 int sig = 99999; 95 96 errno = 0; 97 int result = sigignore(sig); 98 if (result == 0 || errno != EINVAL) { 99 t_error("%s failed: result = %d\n", __func__, result); 100 t_error("%s failed: errno = %d\n", __func__, errno); 101 } 102} 103 104int main(int argc, char *argv[]) 105{ 106 sigignore_0100(); 107 sigignore_0200(); 108 sigignore_0300(); 109 sigignore_0400(); 110 111 return t_status; 112} 113