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 | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 33 | /* $Id: sighold02.c,v 1.11 2009/08/28 13:53:04 vapier Exp $ */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 34 | /***************************************************************************** |
| 35 | * OS Test - Silicon Graphics, Inc. Eagan, Minnesota |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 36 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 37 | * TEST IDENTIFIER : sighold02 Holding all signals. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 38 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 39 | * PARENT DOCUMENT : sghtds01 sighold system call (CRAY X-MP and CRAY-1 only) |
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 | * AUTHOR : Bob Clark |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 42 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 43 | * CO-PILOT : Barrie Kletscher |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 44 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 45 | * DATE STARTED : 9/26/86 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 46 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 47 | * TEST ITEMS |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 48 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 49 | * 1. sighold action to turn off the receipt of all signals was done |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 50 | * without error. |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 51 | * 2. After signals were held, and sent, no signals were trapped. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 52 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 53 | * SPECIAL PROCEDURAL REQUIRMENTS |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 54 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 55 | * The program must be linked with tst_res.o and parse_opts.o. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 56 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 57 | * DETAILED DESCRIPTION |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 58 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 59 | * set up pipe for parent/child communications |
| 60 | * fork off a child process |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 61 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 62 | * PARENT: |
| 63 | * set up for unexpected signals |
| 64 | * wait for child to send ready message over pipe |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 65 | * issue a result for sighold |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 66 | * send all catchable signals to child |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | * write to pipe, tell child all signals sent |
| 68 | * read pipe to get result from child |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 69 | * wait for child to terminate |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 70 | * |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 71 | * CHILD: |
| 72 | * set up to catch all signals |
| 73 | * hold signals with sighold() |
| 74 | * send parent sighold results via pipe |
| 75 | * wait for signals to arrive while reading pipe |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 76 | * write to pipe telling parent which signals were received if any. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 77 | * |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 78 | ***************************************************************************/ |
| 79 | |
| 80 | #include <errno.h> |
| 81 | #include <signal.h> |
| 82 | #include <string.h> |
| 83 | #include <fcntl.h> |
| 84 | #include <stdlib.h> |
| 85 | #include <sys/types.h> |
| 86 | #include <sys/wait.h> |
| 87 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | |
robbiew | 90e8baf | 2003-09-25 15:44:20 +0000 | [diff] [blame] | 89 | /* Needed for NPTL */ |
robbiew | eeea7f0 | 2003-04-29 16:44:41 +0000 | [diff] [blame] | 90 | #define SIGCANCEL 32 |
| 91 | #define SIGTIMER 33 |
robbiew | eeea7f0 | 2003-04-29 16:44:41 +0000 | [diff] [blame] | 92 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 93 | #ifdef _CRAYT3E |
| 94 | #define CRAYT3E 1 |
| 95 | #else |
| 96 | #define CRAYT3E 0 |
| 97 | #endif |
| 98 | |
| 99 | #ifdef sgi |
| 100 | #define SGI 1 |
| 101 | #else |
| 102 | #define SGI 0 |
| 103 | #endif |
| 104 | |
| 105 | #ifdef __linux__ |
| 106 | /* glibc2.2 definition needs -D_XOPEN_SOURCE, which breaks other things. */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 107 | extern int sighold(int __sig); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 108 | #endif |
| 109 | |
| 110 | /* ensure NUMSIGS is defined */ |
| 111 | #ifndef NUMSIGS |
| 112 | #define NUMSIGS NSIG |
| 113 | #endif |
| 114 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 115 | #define CHILD_EXIT(VAL) ((VAL >> 8) & 0377) /* exit value of child process */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | |
| 117 | #define MAXMESG 150 /* the size of the message string */ |
| 118 | |
| 119 | #define TIMEOUT 2 /* time used in the alarm calls as backup */ |
| 120 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 121 | char *TCID = "sighold02"; |
| 122 | int TST_TOTAL = 2; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 123 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 124 | char signals_received[MAXMESG]; |
| 125 | int pid; /* process id of child */ |
| 126 | int Fds1[2]; /* file descriptors for pipe - child 2 parent */ |
| 127 | int Fds2[2]; /* file descriptors for pipe - parent 2 child */ |
| 128 | |
| 129 | #define PARENTSREADFD Fds1[0] |
| 130 | #define CHILDSWRITEFD Fds1[1] |
| 131 | |
| 132 | #define CHILDSREADFD Fds2[0] |
| 133 | #define PARENTSWRITEFD Fds2[1] |
| 134 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 135 | struct pipe_packet { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 136 | int result; |
| 137 | char mesg[MAXMESG]; |
| 138 | struct tblock rtimes; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | } p_p; |
| 140 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 141 | void do_child(void); |
| 142 | void setup(void); |
| 143 | void cleanup(void); |
| 144 | static void getout(void); |
Mike Frysinger | e61ddba | 2014-04-09 23:24:32 -0400 | [diff] [blame] | 145 | static void timeout(int sig); |
Garrett Cooper | 93cbfd6 | 2010-08-16 23:39:01 -0700 | [diff] [blame] | 146 | static int read_pipe(int fd); |
| 147 | static int write_pipe(int fd); |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 148 | static int setup_sigs(char *mesg); |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 149 | static void handle_sigs(int sig); |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 150 | static int set_timeout(char *mesg); |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 151 | static void clear_timeout(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 152 | |
| 153 | int Timeout = 0; |
| 154 | |
| 155 | /*********************************************************************** |
| 156 | * MAIN |
| 157 | ***********************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 158 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 159 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 160 | int term_stat; /* child return status */ |
| 161 | int sig; /* current signal */ |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 162 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 163 | const char *msg; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 164 | |
| 165 | /*************************************************************** |
| 166 | * parse standard options, and exit if there is an error |
| 167 | ***************************************************************/ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 168 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 169 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 170 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 171 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 172 | #ifdef UCLINUX |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 173 | maybe_run_child(&do_child, "dd", &CHILDSWRITEFD, &CHILDSREADFD); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 174 | #endif |
| 175 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 176 | /*************************************************************** |
| 177 | * perform global setup for test |
| 178 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 179 | setup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 180 | |
| 181 | /*************************************************************** |
| 182 | * check looping state if -c option given |
| 183 | ***************************************************************/ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 184 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 185 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 186 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 187 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 188 | signals_received[0] = '\0'; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 189 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 190 | /* |
| 191 | * fork off a child process |
| 192 | */ |
| 193 | if ((pid = FORK_OR_VFORK()) < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 194 | tst_brkm(TBROK | TERRNO, cleanup, "fork() failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 195 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 196 | } else if (pid > 0) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 197 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 198 | /* PARENT PROCESS - first set up for unexpected signals */ |
| 199 | tst_sig(FORK, DEF_HANDLER, getout); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 200 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 201 | /* wait for "ready" message from child */ |
Garrett Cooper | 93cbfd6 | 2010-08-16 23:39:01 -0700 | [diff] [blame] | 202 | if (read_pipe(PARENTSREADFD) != 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 203 | /* read_pipe() failed. */ |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 204 | tst_brkm(TBROK, getout, "%s", p_p.mesg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 205 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 206 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 207 | if (STD_TIMING_ON) { |
| 208 | /* |
| 209 | * Insure a running total for multiple loop iterations |
| 210 | */ |
| 211 | tblock.tb_total += p_p.rtimes.tb_total; |
| 212 | if (p_p.rtimes.tb_min < tblock.tb_min) |
| 213 | tblock.tb_min = p_p.rtimes.tb_min; |
| 214 | if (p_p.rtimes.tb_max > tblock.tb_max) |
| 215 | tblock.tb_max = p_p.rtimes.tb_max; |
| 216 | tblock.tb_count += p_p.rtimes.tb_count; |
| 217 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 218 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 219 | /* check for ready message */ |
| 220 | if (p_p.result != TPASS) { |
| 221 | /* child setup did not go well */ |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 222 | tst_brkm(p_p.result, getout, "%s", p_p.mesg); |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 223 | } else { |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 224 | tst_resm(p_p.result, "%s", p_p.mesg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 225 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 226 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 227 | /* |
| 228 | * send signals to child and see if it holds them |
| 229 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 230 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 231 | for (sig = 1; sig < NUMSIGS; sig++) { |
| 232 | if ((sig == 41) && !CRAYT3E && !SGI) { |
| 233 | sig = 42; /* skip over SIGPEFAILURE for non-CRAYT3E systems */ |
| 234 | } |
| 235 | if ((sig != SIGCLD) && (sig != SIGKILL) && |
| 236 | (sig != SIGALRM) && (sig != SIGSTOP) |
| 237 | && (sig != SIGCANCEL) |
| 238 | && (sig != SIGTIMER) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 239 | #ifdef SIGRECOVERY |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 240 | && (sig != SIGRECOVERY) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 241 | #endif |
| 242 | #ifdef SIGRESTART |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 243 | && (sig != SIGRESTART) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 244 | #endif |
| 245 | #ifdef SIGNOBDM |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 246 | && (sig != SIGNOBDM) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 247 | #endif |
| 248 | #ifdef SIGPTINTR |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 249 | && (sig != SIGPTINTR) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 250 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 251 | ) { |
| 252 | if (kill(pid, sig) < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 253 | tst_brkm(TBROK | TERRNO, NULL, |
| 254 | "kill(%d, %d) failed", |
| 255 | pid, sig); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 256 | getout(); |
| 257 | } |
| 258 | } |
| 259 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 260 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 261 | /* |
| 262 | * Tell child that all signals were sent. |
| 263 | */ |
| 264 | p_p.result = TPASS; |
| 265 | strcpy(p_p.mesg, "All signals were sent"); |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 266 | write_pipe(PARENTSWRITEFD); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 267 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 268 | /* |
| 269 | * Get childs reply about received signals. |
| 270 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 271 | |
Garrett Cooper | 93cbfd6 | 2010-08-16 23:39:01 -0700 | [diff] [blame] | 272 | if (read_pipe(PARENTSREADFD) < 0) { |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 273 | tst_brkm(TBROK, getout, "%s", p_p.mesg); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 274 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 275 | |
Cyril Hrubis | e38b961 | 2014-06-02 17:20:57 +0200 | [diff] [blame] | 276 | tst_resm(p_p.result, "%s", p_p.mesg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 277 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 278 | /* |
| 279 | * wait for child |
| 280 | */ |
| 281 | if (wait(&term_stat) < 0) { |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 282 | tst_brkm(TBROK, getout, "wait() failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 283 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 284 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 285 | } else { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 286 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 287 | /* |
| 288 | * CHILD PROCESS - set up to catch signals. |
| 289 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 290 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 291 | #ifdef UCLINUX |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 292 | if (self_exec(av[0], "dd", CHILDSWRITEFD, CHILDSREADFD) |
| 293 | < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 294 | tst_brkm(TBROK | TERRNO, cleanup, |
| 295 | "self_exec() failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 296 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 297 | #else |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 298 | do_child(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 299 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 300 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 301 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 302 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 303 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 304 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | /***************************************************************************** |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 308 | * do_child() |
| 309 | ****************************************************************************/ |
| 310 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 311 | void do_child(void) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 312 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 313 | int rv; /* function return value */ |
| 314 | int sig; /* current signal */ |
| 315 | int cnt; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 316 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 317 | p_p.result = TPASS; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 318 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 319 | /* set up signal handlers for the signals */ |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 320 | if (setup_sigs(p_p.mesg) < 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 321 | p_p.result = TBROK; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 322 | |
| 323 | } else { |
| 324 | /* all set up to catch signals, now hold them */ |
| 325 | |
| 326 | for (cnt = 0, sig = 1; sig < NUMSIGS; sig++) { |
| 327 | if ((sig == 41) && !CRAYT3E && !SGI) { |
| 328 | sig = 42; /* skip over SIGPEFAILURE for non-CRAYT3E systems */ |
| 329 | } |
| 330 | if ((sig != SIGCLD) && (sig != SIGKILL) && |
| 331 | (sig != SIGALRM) && (sig != SIGSTOP) |
| 332 | #ifdef SIGNOBDM |
| 333 | && (sig != SIGNOBDM) |
| 334 | #endif |
| 335 | && (sig != SIGCANCEL) && (sig != SIGTIMER) |
| 336 | ) { |
| 337 | |
| 338 | cnt++; |
| 339 | TEST(sighold(sig)); |
| 340 | rv = TEST_RETURN; |
| 341 | if (rv != 0) { |
| 342 | /* THEY say sighold ALWAYS returns 0 */ |
| 343 | p_p.result = TFAIL; |
| 344 | (void)sprintf(p_p.mesg, |
| 345 | "sighold(%d) failed, rv:%d, errno:%d", |
| 346 | sig, rv, errno); |
| 347 | break; |
| 348 | } |
| 349 | } |
| 350 | } |
| 351 | if (STD_TIMING_ON) { |
| 352 | p_p.rtimes = tblock; |
| 353 | } |
| 354 | if (p_p.result == TPASS) { |
| 355 | sprintf(p_p.mesg, |
| 356 | "Sighold called without error for %d of %d signals", |
| 357 | cnt, NUMSIGS - 1); |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | /* |
| 362 | * write to parent (if not READY, parent will BROK) and |
| 363 | * wait for parent to send signals. The timeout clock is set so |
| 364 | * that we will not wait forever - if sighold() did its job, we |
| 365 | * will not receive the signals. If sighold() blew it we will |
| 366 | * catch a signal and the interrupt handler will exit(1). |
| 367 | */ |
| 368 | #if debug |
| 369 | printf("child: %d writing to parent fd:%d\n", getpid(), CHILDSWRITEFD); |
| 370 | #endif |
| 371 | if (write_pipe(CHILDSWRITEFD) < 0 || p_p.result != TPASS) { |
| 372 | exit(2); |
| 373 | } |
| 374 | |
| 375 | /* |
| 376 | * Read pipe from parent, that will tell us that all signals were sent |
| 377 | */ |
Garrett Cooper | 93cbfd6 | 2010-08-16 23:39:01 -0700 | [diff] [blame] | 378 | if (read_pipe(CHILDSREADFD) != 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 379 | p_p.result = TBROK; |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 380 | strcpy(p_p.mesg, "read() pipe failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 381 | } else if (signals_received[0] == '\0') { |
| 382 | p_p.result = TPASS; |
| 383 | strcpy(p_p.mesg, |
| 384 | "No signals trapped after being sent by parent"); |
| 385 | } else { |
| 386 | p_p.result = TFAIL; |
| 387 | sprintf(p_p.mesg, "signals received: %s", signals_received); |
| 388 | } |
| 389 | |
| 390 | if (write_pipe(CHILDSWRITEFD) < 0) { |
| 391 | exit(2); |
| 392 | } |
| 393 | |
| 394 | /* exit back to parent */ |
| 395 | if (p_p.result == TPASS) |
| 396 | exit(0); |
| 397 | else |
| 398 | exit(1); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | /***************************************************************************** |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 402 | * read_pipe() : read data from pipe and return in buf. If an error occurs |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 403 | * put message in mesg and return NULL. Note: this routine sets a |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 404 | * timeout signal in case the pipe is blocked. |
| 405 | ****************************************************************************/ |
| 406 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 407 | int read_pipe(int fd) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 408 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 409 | int ret = -1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 410 | |
| 411 | #ifdef debug |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 412 | printf("read_pipe: %d entering, fd = %d...\n", getpid(), fd); |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 413 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 414 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 415 | /* set timeout alarm in case the pipe is blocked */ |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 416 | if (set_timeout(p_p.mesg) < 0) { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 417 | /* an error occured, message in mesg */ |
| 418 | return -1; |
| 419 | } |
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 | ret = read(fd, (char *)&p_p, sizeof(struct pipe_packet)); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 422 | |
| 423 | #ifdef debug |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 424 | printf("read_pipe: %d read() completed ret=%d\n", getpid(), ret); |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 425 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 426 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 427 | clear_timeout(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 428 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 429 | if (Timeout) { |
| 430 | (void)sprintf(p_p.mesg, |
| 431 | "read() pipe failed -timed out after %d seconds.", |
| 432 | TIMEOUT); |
| 433 | return -1; |
| 434 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 435 | #ifdef debug |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 436 | printf("read_pipe: received %s.\n", p_p.mesg); |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 437 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 438 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 439 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 440 | } |
| 441 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 442 | /***************************************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 443 | * write_pipe(msg) : write p_p to pipe. If it fails, put message in |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 444 | * mesg and return -1, else return 0. |
| 445 | ****************************************************************************/ |
| 446 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 447 | static int write_pipe(int fd) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 448 | { |
| 449 | #ifdef debug |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 450 | printf("write_pipe: sending result:%d, mesg:%s.\n", p_p.result, |
| 451 | p_p.mesg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 452 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 453 | if (write(fd, (char *)&p_p, sizeof(struct pipe_packet)) < 0) { |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 454 | if (pid) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 455 | tst_brkm(TBROK | TERRNO, getout, "write() pipe failed"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 456 | return -1; |
| 457 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 458 | #ifdef debug |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 459 | printf("write_pipe: %d complete successfully, fd:%d.\n", getpid(), fd); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 460 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 461 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 462 | } |
| 463 | |
| 464 | /***************************************************************************** |
| 465 | * set_timeout() : set alarm to signal process after the period of time |
| 466 | * indicated by TIMEOUT. If the signal occurs, the routine timeout() |
| 467 | * will be executed. If all goes ok, return 0, else load message |
| 468 | * into mesg and return -1. |
| 469 | ****************************************************************************/ |
| 470 | |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 471 | static int set_timeout(char *mesg) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 472 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 473 | if (signal(SIGALRM, timeout) == SIG_ERR) { |
| 474 | (void)sprintf(mesg, |
| 475 | "signal() failed for signal %d. error:%d %s.", |
| 476 | SIGALRM, errno, strerror(errno)); |
| 477 | return (-1); |
| 478 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 479 | #if debug |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 480 | printf("set_timeout()...\n"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 481 | #endif |
| 482 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 483 | Timeout = 0; |
| 484 | (void)alarm(TIMEOUT); |
| 485 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | /***************************************************************************** |
| 489 | * clear_timeout() : turn off the alarm so that SIGALRM will not get sent. |
| 490 | ****************************************************************************/ |
| 491 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 492 | static void clear_timeout(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 493 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 494 | (void)alarm(0); |
| 495 | Timeout = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | /***************************************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 499 | * timeout() : this routine is executed when the SIGALRM signal is |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 500 | * caught. It does nothing but return - if executed during a read() |
| 501 | * system call, a -1 will be returned by the read(). |
| 502 | ****************************************************************************/ |
| 503 | |
Mike Frysinger | e61ddba | 2014-04-09 23:24:32 -0400 | [diff] [blame] | 504 | static void timeout(int sig) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 505 | { |
| 506 | #ifdef debug |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 507 | printf("timeout: sigalrm caught.\n"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 508 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 509 | Timeout = 1; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 510 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /***************************************************************************** |
| 514 | * setup_sigs() : set child up to catch all signals. If there is |
| 515 | * trouble, write message in mesg and return -1, else return 0. |
| 516 | ****************************************************************************/ |
| 517 | |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 518 | static int setup_sigs(char *mesg) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 519 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 520 | int sig; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 521 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 522 | /* set up signal handler routine */ |
| 523 | for (sig = 1; sig < NUMSIGS; sig++) { |
| 524 | if ((sig != SIGCLD) && (sig != SIGKILL) && |
| 525 | (sig != SIGALRM) && (sig != SIGSTOP) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 526 | #ifdef SIGRESTART |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 527 | && (sig != SIGRESTART) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 528 | #endif |
| 529 | #ifdef SIGRECOVERY |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 530 | && (sig != SIGRECOVERY) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 531 | #endif |
| 532 | #ifdef SIGSWAP |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 533 | && (sig != SIGSWAP) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 534 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 535 | && (sig != SIGCANCEL) && (sig != SIGTIMER) |
| 536 | ) { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 537 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 538 | if (signal(sig, handle_sigs) == SIG_ERR) { |
| 539 | /* set up mesg to send back to parent */ |
| 540 | (void)sprintf(mesg, |
| 541 | "signal() failed for signal %d. error:%d %s.", |
| 542 | sig, errno, strerror(errno)); |
| 543 | return (-1); |
| 544 | } |
| 545 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 546 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 547 | return 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | /***************************************************************************** |
| 551 | * handle_sigs() : interrupt handler for all signals. This will be run |
| 552 | * if the child process catches a signal (resulting in |
| 553 | * a test item FAIL if tst_res has not yet been called). The parent |
| 554 | * detects this situation by a child exit value of 1. |
| 555 | ****************************************************************************/ |
| 556 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 557 | static void handle_sigs(int sig) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 558 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 559 | char string[10]; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 560 | |
| 561 | #ifdef debug |
| 562 | printf("child: handle_sigs: caught signal %d.\n", sig); |
| 563 | #endif |
| 564 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 565 | sprintf(string, " %d", sig); |
| 566 | strcat(signals_received, string); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 567 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 568 | return; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 569 | } |
| 570 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 571 | /***************************************************************************** |
| 572 | * getout() : attempt to kill child process and call cleanup(). |
| 573 | ****************************************************************************/ |
| 574 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 575 | static void getout(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 576 | { |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 577 | if (kill(pid, SIGKILL) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 578 | tst_resm(TWARN | TERRNO, "kill(%d) failed", pid); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 579 | cleanup(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 580 | } |
| 581 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 582 | /*************************************************************** |
| 583 | * setup() - performs all ONE TIME setup for this test. |
| 584 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 585 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 586 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 587 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 588 | tst_sig(FORK, DEF_HANDLER, cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 589 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 590 | /* set up pipe for child sending to parent communications */ |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 591 | if (pipe(Fds1) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 592 | tst_brkm(TBROK | TERRNO, cleanup, "pipe() failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 593 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 594 | /* set up pipe for parent sending to child communications */ |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 595 | if (pipe(Fds2) < 0) |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 596 | tst_brkm(TBROK | TERRNO, cleanup, "pipe() failed"); |
vapier | 64a5544 | 2009-08-28 13:53:04 +0000 | [diff] [blame] | 597 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 598 | #if debug |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 599 | printf("child 2 parent Fds1[0] = %d, Fds1[1] = %d\n", Fds1[0], Fds1[1]); |
| 600 | printf("parent 2 child Fds2[0] = %d, Fds2[1] = %d\n", Fds2[0], Fds2[1]); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 601 | #endif |
| 602 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 603 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 604 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 605 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 606 | |
| 607 | /*************************************************************** |
| 608 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 609 | * completion or premature exit. |
| 610 | ***************************************************************/ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 611 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 612 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 613 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 614 | } |