1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * 07/2001 John George 5f08c3bdfSopenharmony_ci * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz> 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci/* 9f08c3bdfSopenharmony_ci * Check that when a child kills itself by SIGALRM the waiting parent is 10f08c3bdfSopenharmony_ci * correctly notified. 11f08c3bdfSopenharmony_ci * 12f08c3bdfSopenharmony_ci * Fork a child that raises(SIGALRM), the parent checks that SIGALRM was 13f08c3bdfSopenharmony_ci * returned. 14f08c3bdfSopenharmony_ci */ 15f08c3bdfSopenharmony_ci#include <stdlib.h> 16f08c3bdfSopenharmony_ci#include <sys/wait.h> 17f08c3bdfSopenharmony_ci#include "tst_test.h" 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_cistatic void run(void) 20f08c3bdfSopenharmony_ci{ 21f08c3bdfSopenharmony_ci pid_t pid; 22f08c3bdfSopenharmony_ci int status; 23f08c3bdfSopenharmony_ci 24f08c3bdfSopenharmony_ci pid = SAFE_FORK(); 25f08c3bdfSopenharmony_ci if (!pid) { 26f08c3bdfSopenharmony_ci raise(SIGALRM); 27f08c3bdfSopenharmony_ci exit(0); 28f08c3bdfSopenharmony_ci } 29f08c3bdfSopenharmony_ci 30f08c3bdfSopenharmony_ci TST_EXP_PID_SILENT(waitpid(pid, &status, 0)); 31f08c3bdfSopenharmony_ci if (!TST_PASS) 32f08c3bdfSopenharmony_ci return; 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci if (TST_RET != pid) { 35f08c3bdfSopenharmony_ci tst_res(TFAIL, "waitpid() returned wrong pid %li, expected %i", 36f08c3bdfSopenharmony_ci TST_RET, pid); 37f08c3bdfSopenharmony_ci } else { 38f08c3bdfSopenharmony_ci tst_res(TPASS, "waitpid() returned correct pid %i", pid); 39f08c3bdfSopenharmony_ci } 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_ci if (!WIFSIGNALED(status)) { 42f08c3bdfSopenharmony_ci tst_res(TFAIL, "WIFSIGNALED() not set in status (%s)", 43f08c3bdfSopenharmony_ci tst_strstatus(status)); 44f08c3bdfSopenharmony_ci return; 45f08c3bdfSopenharmony_ci } 46f08c3bdfSopenharmony_ci 47f08c3bdfSopenharmony_ci tst_res(TPASS, "WIFSIGNALED() set in status"); 48f08c3bdfSopenharmony_ci 49f08c3bdfSopenharmony_ci if (WTERMSIG(status) != SIGALRM) { 50f08c3bdfSopenharmony_ci tst_res(TFAIL, "WTERMSIG() != SIGALRM but %s", 51f08c3bdfSopenharmony_ci tst_strsig(WTERMSIG(status))); 52f08c3bdfSopenharmony_ci return; 53f08c3bdfSopenharmony_ci } 54f08c3bdfSopenharmony_ci 55f08c3bdfSopenharmony_ci tst_res(TPASS, "WTERMSIG() == SIGALRM"); 56f08c3bdfSopenharmony_ci} 57f08c3bdfSopenharmony_ci 58f08c3bdfSopenharmony_cistatic struct tst_test test = { 59f08c3bdfSopenharmony_ci .forks_child = 1, 60f08c3bdfSopenharmony_ci .test_all = run, 61f08c3bdfSopenharmony_ci}; 62