plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or modify it |
| 5 | * under the terms of version 2 of the GNU General Public License as |
| 6 | * published by the Free Software Foundation. |
| 7 | * |
| 8 | * This program is distributed in the hope that it would be useful, but |
| 9 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 11 | * |
| 12 | * Further, this software is distributed without any warranty that it is |
| 13 | * free of the rightful claim of any third person regarding infringement |
| 14 | * or the like. Any license provided herein, whether implied or |
| 15 | * otherwise, applies only to this software file. Patent licenses, if |
| 16 | * any, provided herein do not apply to combinations of this program with |
| 17 | * other software, or any other product whatsoever. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 20 | * with this program; if not, write the Free Software Foundation, Inc., |
| 21 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 22 | * |
| 23 | * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy, |
| 24 | * Mountain View, CA 94043, or: |
| 25 | * |
| 26 | * http://www.sgi.com |
| 27 | * |
| 28 | * For further information regarding this notice, see: |
| 29 | * |
| 30 | * http://oss.sgi.com/projects/GenInfo/NoticeExplan/ |
| 31 | * |
| 32 | */ |
vapier | 7481306 | 2009-08-28 13:58:53 +0000 | [diff] [blame] | 33 | /* $Id: signal01.c,v 1.11 2009/08/28 13:58:53 vapier Exp $ */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | /*********************************************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 35 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 36 | * OS Test - Silicon Graphics, Inc. Eagan, Minnesota |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 37 | * |
nstraz | fa31d55 | 2002-05-14 16:50:06 +0000 | [diff] [blame] | 38 | * TEST IDENTIFIER : signal01 Boundary value and other invalid value checking |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 39 | * of signal setup and signal sending. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 40 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 41 | * PARENT DOCUMENT : sgntds01 Signal System Call |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 42 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 43 | * AUTHOR : Dave Baumgartner |
| 44 | * : Rewrote 12/92 by Richard Logan |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 45 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 46 | * CO-PILOT : Barrie Kletscher |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 47 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | * DATE STARTED : 10/17/85 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 49 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | * TEST ITEMS |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 51 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 52 | * 1. SIGKILL can not be set to be caught, errno:EINVAL (POSIX). |
| 53 | * 2. SIGKILL can not be caught. |
| 54 | * 3. SIGKILL can not be set to be ignored, errno:EINVAL (POSIX). |
| 55 | * 4. SIGKILL can not be ignored. |
| 56 | * 5. SIGKILL can not be reset to default, errno:EINVAL (POSIX. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 57 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | * ENVIRONMENTAL NEEDS |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 59 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | * NONE |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 61 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | * SPECIAL PROCEDURAL REQUIREMENTS |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 63 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | * None |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 65 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | * INTERCASE DEPENDENCIES |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 67 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 68 | * 2 depends on 1 and 4 on 3. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 69 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | * DETAILED DESCRIPTION |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 71 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 72 | * main() |
| 73 | * Call catch_test to test setup and catching of SIGKILL. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 74 | * |
| 75 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | * Call ignore_test to test setup and ignoring of SIGKILL. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 77 | * |
| 78 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | * Call sigdfl_test to test setting SIGKILL to default. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 80 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | * * END OF MAIN * |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 82 | * |
| 83 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | * catch_test() |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 85 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 86 | * fork a child |
| 87 | * if this is the parent |
| 88 | * sleep to let child start. |
| 89 | * send sig to child. |
| 90 | * wait for the child to terminate. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 91 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | * if the termination status of the child equals the signal sent to it |
| 93 | * Test item 1 PASSED the child was killed. |
| 94 | * else if status equals the exit value of SIG_CAUGHT |
| 95 | * Test item 2 FAILED sig was caught. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 96 | * else |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 97 | * Test item 2 FAILED because the child was not killed |
| 98 | * but sig was not caught either. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 99 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 100 | * else this the child |
| 101 | * set exit_val to SIG_NOT_CAUGHT. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 102 | * set to catch sig, where the interrupt routine just sets |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | * exit_val to SIG_CAUGHT. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 104 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 105 | * If the return value and errno, after trying to set to catch sig, |
| 106 | * do not indicate that an error has occurred. |
| 107 | * Test item 1 FAILED bad return, return value:X, errno:X. |
| 108 | * else |
| 109 | * Test item 1 PASSED sig was not set to be caught. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 110 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | * pause until the parent sends a signal. |
| 112 | * The child should be killed by the signal but if not exit |
| 113 | * with exit_val. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 114 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 115 | * * End of catch_test. * |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 116 | * |
| 117 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 118 | * ignore_test() |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 119 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 120 | * fork a child |
| 121 | * if this is the parent |
| 122 | * sleep to let child start. |
| 123 | * send SIGKILL to child. |
| 124 | * wait for the child to terminate. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 125 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | * if the termination status of the child equals SIGKILL |
| 127 | * Test item 4 PASSED the child was killed. |
| 128 | * else if the status equals the exit value of SIG_IGNORED |
| 129 | * Test item 4 FAILED SIGKILL was ignored. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 130 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | * else this the child |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 132 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | * If the return value and errno, after trying to set to ignore SIGKILL, |
| 134 | * do not indicate that an error has occurred. |
| 135 | * Test item 3 FAILED bad return, return value:X, errno:X. |
| 136 | * else |
| 137 | * Test item 3 PASSED SIGKILL was not set to be ignored. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 138 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | * pause until the parent sends SIGKILL. |
| 140 | * The child should be killed by the signal but if not exit |
| 141 | * with SIG_IGNORED. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 142 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 143 | * * End of ignore_test. * |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 144 | * |
| 145 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 146 | * sigdfl_test() |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 147 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 148 | * If the return value and errno, after trying to set to SIGKILL to default, |
| 149 | * do not indicate that an error has occurred. |
| 150 | * Test item 5 FAILED bad return, return value:X, errno:X. |
| 151 | * else |
| 152 | * Test item 5 PASSED SIGKILL was not set to default. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 153 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 154 | * * End of sigdfl_test. * |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 155 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 156 | * BUGS/NOTES |
| 157 | * Since the system call under test is executed in the child, no |
| 158 | * timings on this system call will be reported. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 159 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 160 | ***********************************************************************************/ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 161 | #include <signal.h> |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 162 | #include <errno.h> |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 163 | #include <unistd.h> |
| 164 | #include <fcntl.h> |
| 165 | #include <string.h> |
| 166 | #include <stdlib.h> |
| 167 | #include <sys/wait.h> |
| 168 | |
| 169 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 170 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 171 | void setup(void); |
| 172 | void cleanup(void); |
| 173 | void do_test(int test_case, int tst_cnt); |
| 174 | void do_child(int test_case); |
| 175 | void sigdfl_test(void); |
| 176 | struct tblock; |
| 177 | void update_timings(struct tblock atblock); |
Mike Frysinger | e61ddba | 2014-04-09 23:24:32 -0400 | [diff] [blame] | 178 | void p_timeout_handler(int sig); |
| 179 | void c_timeout_handler(int sig); |
| 180 | void catchsig(int sig); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 181 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 182 | #if defined(linux) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 183 | #define SIG_PF sig_t /* This might need to be sighandler_t on some systems */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 184 | #endif |
| 185 | |
| 186 | #define SIG_CAUGHT 1 |
| 187 | #define SIG_NOT_CAUGHT 0 |
| 188 | #define SIG_IGNORED 5 |
| 189 | #define TIMED_OUT 99 |
| 190 | |
| 191 | #define TIMEOUT 20 |
| 192 | |
| 193 | #define GO_FLAG 1 |
| 194 | #define ERROR_FLAG 2 |
| 195 | #define PASS_FLAG 3 |
| 196 | #define FAIL_FLAG 4 |
| 197 | |
| 198 | #define IGNORE_TEST 1 |
| 199 | #define CATCH_TEST 2 |
| 200 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 201 | #define MAXMESG 150 /* The Maximum message that can be created. */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 202 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 203 | int exit_val; /* Global variable, used to tell whether the */ |
| 204 | /* child exited instead of being killed. */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 205 | |
| 206 | struct ipc_t { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 207 | int status; |
| 208 | char mesg[MAXMESG]; |
| 209 | struct tblock timings; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 210 | } Ipc_info; |
| 211 | |
nstraz | fa31d55 | 2002-05-14 16:50:06 +0000 | [diff] [blame] | 212 | char *TCID = "signal01"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 213 | int TST_TOTAL = 5; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 214 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 215 | int Pid; /* Return value from fork. */ |
| 216 | static int fd1[2]; /* ipc fd, shared between do_test and do_child */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 217 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 218 | typedef void (*sighandler_t) (int); |
plars | 74948ad | 2002-11-14 16:16:14 +0000 | [diff] [blame] | 219 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 220 | sighandler_t Tret; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 221 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 222 | #ifdef UCLINUX |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 223 | static char *argv0; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 224 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 225 | void do_child_uclinux(void); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 226 | static int test_case_uclinux; |
| 227 | #endif |
| 228 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 229 | /*********************************************************************** |
| 230 | * M A I N |
| 231 | ***********************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 232 | int main(int argc, char *argv[]) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 233 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 234 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 235 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 236 | |
| 237 | /*************************************************************** |
| 238 | * parse standard options |
| 239 | ***************************************************************/ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 240 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 241 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 242 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 243 | #ifdef UCLINUX |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 244 | argv0 = argv[0]; |
| 245 | maybe_run_child(&do_child_uclinux, "dd", &test_case_uclinux, &fd1[1]); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 246 | #endif |
| 247 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 248 | /*************************************************************** |
| 249 | * perform global setup for test |
| 250 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 251 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 252 | |
| 253 | /*************************************************************** |
| 254 | * check looping state if -c option given |
| 255 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 256 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 257 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 258 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 259 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 260 | errno = -4; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 261 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 262 | /* |
| 263 | * Call catch_test to test setup and catching of SIGKILL. |
| 264 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 265 | do_test(CATCH_TEST, tst_count); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 266 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 267 | /* |
| 268 | * Call ignore_test to test setup and ignoring of SIGKILL. |
| 269 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 270 | do_test(IGNORE_TEST, tst_count); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 271 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 272 | /* |
| 273 | * Call sigdfl_test to test setting SIGKILL to default. |
| 274 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 275 | sigdfl_test(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 276 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 277 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 278 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 279 | cleanup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 280 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 281 | tst_exit(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 282 | } /*End of main */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 283 | |
| 284 | /*********************************************************************** |
| 285 | * |
| 286 | ***********************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 287 | void do_test(int test_case, int tst_cnt) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 288 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 289 | int term_stat; /* Termination status of the child returned to */ |
| 290 | /* the parent. */ |
| 291 | int rd_sz; /* size of read */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 292 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 293 | tst_count = tst_cnt; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 294 | |
| 295 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 296 | * Create a pipe of ipc |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 297 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 298 | if (pipe(fd1) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 299 | tst_resm(TBROK | TERRNO, "pipe() failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 300 | return; |
| 301 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 302 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 303 | /* |
| 304 | * Cause the read to return 0 once EOF is encountered and the |
| 305 | * read to return -1 if pipe is empty. |
| 306 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 307 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 308 | if (fcntl(fd1[0], F_SETFL, O_NONBLOCK) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 309 | tst_resm(TBROK | TERRNO, |
| 310 | "fcntl(fd1[0], F_SETFL, O_NONBLOCK) failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 311 | close(fd1[0]); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 312 | close(fd1[1]); |
| 313 | return; |
| 314 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 315 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 316 | if ((Pid = FORK_OR_VFORK()) > 0) { /* parent */ |
| 317 | |
| 318 | signal(SIGALRM, p_timeout_handler); |
| 319 | |
| 320 | alarm(TIMEOUT); |
| 321 | |
| 322 | close(fd1[1]); /* close write side */ |
| 323 | |
| 324 | /* |
| 325 | * Deal with child's messages. |
| 326 | * Only the GO_FLAG status will allow parent to |
| 327 | * go on. All pipe io will be in the ipc_t structure sizes |
| 328 | * to avoid reading part of next message. |
| 329 | */ |
| 330 | while (1) { |
| 331 | |
| 332 | while ((rd_sz = |
| 333 | read(fd1[0], (char *)&Ipc_info, |
| 334 | sizeof(Ipc_info))) != 0) { |
| 335 | if (rd_sz > 0) |
| 336 | break; /* read something */ |
| 337 | } |
| 338 | |
| 339 | if (rd_sz == 0) { /* if EOF encountered */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 340 | tst_resm(TBROK, |
| 341 | "child's pipe is closed before 'go' message received"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 342 | close(fd1[0]); |
| 343 | return; |
| 344 | } |
| 345 | |
| 346 | else if (Ipc_info.status == GO_FLAG) { |
| 347 | break; /* go on */ |
| 348 | } else if (Ipc_info.status == ERROR_FLAG) { |
| 349 | tst_resm(TBROK, "From child: %s", |
| 350 | Ipc_info.mesg); |
| 351 | tst_resm(TBROK, "From child: %s", |
| 352 | Ipc_info.mesg); |
| 353 | close(fd1[0]); |
| 354 | return; |
| 355 | } else if (Ipc_info.status == PASS_FLAG) { |
| 356 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 357 | tst_resm(TPASS, "From child: %s", |
| 358 | Ipc_info.mesg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 359 | update_timings(Ipc_info.timings); |
| 360 | } else if (Ipc_info.status == FAIL_FLAG) { |
| 361 | tst_resm(TFAIL, "From child: %s", |
| 362 | Ipc_info.mesg); |
| 363 | update_timings(Ipc_info.timings); |
| 364 | } else { |
| 365 | tst_resm(TINFO, |
| 366 | "Unknown message from child: %s", |
vapier | 7481306 | 2009-08-28 13:58:53 +0000 | [diff] [blame] | 367 | Ipc_info.mesg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 368 | } |
| 369 | } |
| 370 | |
| 371 | /* |
| 372 | * Send the signal SIGKILL to the child. |
| 373 | */ |
| 374 | if (kill(Pid, SIGKILL) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 375 | tst_resm(TBROK | TERRNO, "kill(%d) failed", Pid); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 376 | close(fd1[0]); |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * Wait for the child to terminate and check the termination status. |
| 382 | */ |
| 383 | if (wait(&term_stat) == -1) { |
| 384 | /* |
| 385 | * The wait system call failed. |
| 386 | */ |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 387 | tst_resm(TBROK | TERRNO, "wait() failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 388 | close(fd1[0]); |
| 389 | return; |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 390 | } else { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 391 | if ((term_stat & 0377) == SIGKILL) { |
| 392 | /* |
| 393 | * The child was killed by the signal sent, |
| 394 | * which is correct. |
| 395 | */ |
| 396 | tst_resm(TPASS, |
| 397 | "The child was killed by SIGKILL."); |
| 398 | } else if ((term_stat >> 8) == TIMED_OUT) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 399 | tst_resm(TBROK, |
| 400 | "child exited with a timed out exit status"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 401 | } else { |
| 402 | if ((term_stat >> 8) == SIG_IGNORED |
| 403 | && test_case == IGNORE_TEST) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 404 | tst_resm(TFAIL, |
| 405 | "SIGKILL was ignored by child after sent by parent."); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 406 | } else if ((term_stat >> 8) == SIG_CAUGHT |
| 407 | && test_case == CATCH_TEST) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 408 | tst_resm(TFAIL, |
| 409 | "SIGKILL was caught by child after sent by parent."); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 410 | } else { |
vapier | 7481306 | 2009-08-28 13:58:53 +0000 | [diff] [blame] | 411 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 412 | "Child's termination status is unexpected. Status: %d (%#o).", |
| 413 | term_stat, term_stat); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 414 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 415 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 416 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 417 | close(fd1[0]); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 418 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 419 | } else if (Pid == 0) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 420 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 421 | * This is the child. |
| 422 | * Set up to ignore/catch SIGKILL and check the return values. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 423 | */ |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 424 | #ifdef UCLINUX |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 425 | if (self_exec(argv0, "dd", test_case, fd1[1]) < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 426 | tst_resm(TBROK | TERRNO, "self_exec() failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 427 | close(fd1[0]); |
| 428 | close(fd1[1]); |
| 429 | return; |
| 430 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 431 | #else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 432 | do_child(test_case); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 433 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 434 | |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 435 | } else { |
| 436 | tst_resm(TBROK | TERRNO, "fork() failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 437 | close(fd1[0]); |
| 438 | close(fd1[1]); |
| 439 | return; |
| 440 | } |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 441 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 442 | |
| 443 | /*********************************************************************** |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 444 | * do_child() |
| 445 | ***********************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 446 | void do_child(int test_case) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 447 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 448 | char string[30]; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 449 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 450 | errno = 0; |
| 451 | if (test_case == IGNORE_TEST) { |
| 452 | exit_val = SIG_IGNORED; |
| 453 | strcpy(string, "signal(SIGKILL, SIG_IGN)"); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 454 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 455 | Tret = signal(SIGKILL, SIG_IGN); |
| 456 | TEST_ERRNO = errno; |
| 457 | } else { |
| 458 | exit_val = SIG_NOT_CAUGHT; |
| 459 | strcpy(string, "signal(SIGKILL, catchsig)"); |
| 460 | Tret = signal(SIGKILL, catchsig); |
| 461 | TEST_ERRNO = errno; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 462 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 463 | Ipc_info.timings = tblock; |
| 464 | |
| 465 | if (Tret == SIG_ERR) { |
| 466 | if (TEST_ERRNO == EINVAL) { |
| 467 | sprintf(Ipc_info.mesg, |
| 468 | "%s ret:%p SIG_ERR (%ld) as expected", string, |
| 469 | Tret, (long)SIG_ERR); |
| 470 | Ipc_info.status = PASS_FLAG; |
| 471 | } else { |
| 472 | sprintf(Ipc_info.mesg, |
vapier | 7481306 | 2009-08-28 13:58:53 +0000 | [diff] [blame] | 473 | "%s ret:%p, errno:%d expected ret:%ld, errno:%d", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 474 | string, Tret, TEST_ERRNO, (long)SIG_ERR, |
| 475 | EINVAL); |
| 476 | Ipc_info.status = FAIL_FLAG; |
| 477 | } |
| 478 | |
| 479 | write(fd1[1], (char *)&Ipc_info, sizeof(Ipc_info)); |
| 480 | } else { |
| 481 | /* |
| 482 | * The child was not allowed to set the signal to |
| 483 | * be ignored and errno was correct. |
| 484 | */ |
| 485 | sprintf(Ipc_info.mesg, |
vapier | 7481306 | 2009-08-28 13:58:53 +0000 | [diff] [blame] | 486 | "%s ret:%p, errno:%d expected ret:%ld, errno:%d", |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 487 | string, Tret, TEST_ERRNO, (long)SIG_ERR, EINVAL); |
| 488 | Ipc_info.status = FAIL_FLAG; |
| 489 | write(fd1[1], (char *)&Ipc_info, sizeof(Ipc_info)); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 490 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 491 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 492 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 493 | * tell parent we are ready - setup by child is done |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 494 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 495 | Ipc_info.status = GO_FLAG; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 496 | write(fd1[1], (char *)&Ipc_info, sizeof(Ipc_info)); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 497 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 498 | /* |
| 499 | * Set the alarm to wake up from the pause below if |
| 500 | * the parents signal is ignored. |
| 501 | */ |
| 502 | signal(SIGALRM, p_timeout_handler); |
| 503 | alarm(TIMEOUT); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 504 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 505 | /* |
| 506 | * Pause until the parent sends a signal or until alarm is received. |
| 507 | */ |
| 508 | pause(); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 509 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 510 | exit(exit_val); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 511 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 512 | |
| 513 | #ifdef UCLINUX |
| 514 | /*********************************************************************** |
| 515 | * do_child_uclinux(): call do_child with the global used to store test_case |
| 516 | ***********************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 517 | void do_child_uclinux(void) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 518 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 519 | do_child(test_case_uclinux); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 520 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 521 | #endif |
| 522 | |
| 523 | /*********************************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 524 | * sigdfl_test - test for attempt to set SIGKILL to default |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 525 | ***********************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 526 | void sigdfl_test(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 527 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 528 | /* |
| 529 | * Try to set SIGKILL to default and check the return values. |
| 530 | */ |
| 531 | errno = -4; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 532 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 533 | Tret = signal(SIGKILL, SIG_DFL); |
| 534 | TEST_ERRNO = errno; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 535 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 536 | if (Tret == SIG_ERR) { |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 537 | if (TEST_ERRNO != EINVAL) { |
| 538 | tst_resm(TFAIL | TTERRNO, |
| 539 | "signal(SIGKILL,SIG_DFL) expected ret:-1, errno:EINVAL, got ret:%p", |
| 540 | Tret); |
| 541 | } else { |
| 542 | tst_resm(TPASS, |
| 543 | "signal(SIGKILL,SIG_DFL) ret:%p, errno EINVAL as expected", |
| 544 | Tret); |
| 545 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 546 | } else { |
vapier | 7481306 | 2009-08-28 13:58:53 +0000 | [diff] [blame] | 547 | tst_resm(TFAIL, |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 548 | "signal(SIGKILL,SIG_DFL) ret:%p, errno:%d expected ret:-1, errno:%d", |
| 549 | Tret, TEST_ERRNO, EINVAL); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 550 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 551 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 552 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 553 | |
| 554 | /*************************************************************** |
| 555 | * setup() - performs all ONE TIME setup for this test. |
| 556 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 557 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 558 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 559 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 560 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 561 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 562 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 563 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 564 | /* make and change to a temporary directory */ |
| 565 | tst_tmpdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 566 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 567 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 568 | |
| 569 | /*************************************************************** |
| 570 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 571 | * completion or premature exit. |
| 572 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 573 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 574 | { |
| 575 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 576 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 577 | * remove the temporary directory and exit with |
| 578 | * return code appropriate for results |
| 579 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 580 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 581 | tst_rmdir(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 582 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 583 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 584 | |
| 585 | /*********************************************************************** |
| 586 | * Signal handler routine that used by the parent to handler |
| 587 | * a time out situation. It will attempt to kill the child and |
| 588 | * call cleanup. |
| 589 | ***********************************************************************/ |
Mike Frysinger | e61ddba | 2014-04-09 23:24:32 -0400 | [diff] [blame] | 590 | void p_timeout_handler(int sig) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 591 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 592 | kill(Pid, SIGKILL); |
| 593 | cleanup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 594 | } |
| 595 | |
| 596 | /*********************************************************************** |
| 597 | * Signal handler routine that used by the child to handle |
| 598 | * a time out situation. It will set a global varaible and return |
| 599 | * if called. |
| 600 | ***********************************************************************/ |
Mike Frysinger | e61ddba | 2014-04-09 23:24:32 -0400 | [diff] [blame] | 601 | void c_timeout_handler(int sig) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 602 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 603 | exit_val = TIMED_OUT; |
| 604 | return; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | /*********************************************************************** |
| 608 | * This signal handling routine will set a global variable and return |
| 609 | * if called. |
| 610 | ***********************************************************************/ |
Mike Frysinger | e61ddba | 2014-04-09 23:24:32 -0400 | [diff] [blame] | 611 | void catchsig(int sig) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 612 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 613 | exit_val = SIG_CAUGHT; |
| 614 | return; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | /*********************************************************************** |
| 618 | * Update timing information |
| 619 | ***********************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 620 | void update_timings(struct tblock atblock) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 621 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 622 | tblock.tb_max += atblock.tb_max; |
| 623 | tblock.tb_min += atblock.tb_min; |
| 624 | tblock.tb_total += atblock.tb_total; |
| 625 | tblock.tb_count += atblock.tb_count; |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 626 | } |