robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Copyright (c) International Business Machines Corp., 2002 |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or |
| 8 | * (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See |
| 13 | * the GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
Wanlong Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | /* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ |
| 21 | /* 11/06/2002 Port to LTP dbarrera@us.ibm.com */ |
subrata_modak | 6fa4a54 | 2008-04-06 11:44:36 +0000 | [diff] [blame] | 22 | /* 12/03/2008 Fix concurrency issue mfertre@irisa.fr */ |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 23 | |
| 24 | /* |
| 25 | * NAME |
| 26 | * msgctl07 |
| 27 | * |
| 28 | * CALLS |
| 29 | * msgget(2) msgctl(2) msgop(2) |
| 30 | * |
| 31 | * ALGORITHM |
| 32 | * Get and manipulate a message queue. |
| 33 | * |
| 34 | * RESTRICTIONS |
| 35 | * |
| 36 | */ |
| 37 | |
Cyril Hrubis | 9e4b117 | 2014-09-23 13:10:52 +0200 | [diff] [blame] | 38 | #include <sys/types.h> |
| 39 | #include <sys/ipc.h> |
| 40 | #include <sys/msg.h> |
| 41 | #include <signal.h> |
| 42 | #include <wait.h> |
| 43 | #include <stdio.h> |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 44 | #include "test.h" |
subrata_modak | 6fa4a54 | 2008-04-06 11:44:36 +0000 | [diff] [blame] | 45 | #include "ipcmsg.h" |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 46 | #include <stdlib.h> |
| 47 | #include <unistd.h> |
| 48 | #include <errno.h> |
| 49 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 50 | typedef void (*sighandler_t) (int); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 51 | volatile int ready; |
| 52 | |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 53 | #define BYTES 100 |
| 54 | #define SECS 10 |
| 55 | |
| 56 | void setup(); |
| 57 | void cleanup(); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 58 | void do_child_1(); |
| 59 | void do_child_2(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 60 | |
Cyril Hrubis | 9e4b117 | 2014-09-23 13:10:52 +0200 | [diff] [blame] | 61 | char *TCID = "msgctl07"; |
| 62 | int TST_TOTAL = 1; |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 63 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 64 | /* Used by main() and do_child_1(): */ |
| 65 | static int msqid; |
| 66 | struct my_msgbuf { |
| 67 | long type; |
| 68 | char text[BYTES]; |
| 69 | } p1_msgp, p2_msgp, p3_msgp, c1_msgp, c2_msgp, c3_msgp; |
| 70 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 71 | int main(int argc, char *argv[]) |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 72 | { |
| 73 | key_t key; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 74 | int pid, status; |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 75 | int i, j, k; |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 76 | sighandler_t alrm(); |
| 77 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 78 | #ifdef UCLINUX |
Cyril Hrubis | 7422562 | 2014-06-02 17:54:38 +0200 | [diff] [blame] | 79 | const char *msg; |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 80 | |
Cyril Hrubis | 7422562 | 2014-06-02 17:54:38 +0200 | [diff] [blame] | 81 | if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 82 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 83 | |
| 84 | maybe_run_child(&do_child_1, "ndd", 1, &msqid, &c1_msgp.type); |
| 85 | maybe_run_child(&do_child_2, "ndddd", 2, &msqid, &c1_msgp.type, |
| 86 | &c2_msgp.type, &c3_msgp.type); |
| 87 | #endif |
| 88 | |
subrata_modak | 6fa4a54 | 2008-04-06 11:44:36 +0000 | [diff] [blame] | 89 | setup(); |
| 90 | |
| 91 | key = getipckey(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 92 | if ((msqid = msgget(key, IPC_CREAT | IPC_EXCL)) == -1) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 93 | tst_brkm(TFAIL | TERRNO, NULL, "msgget() failed"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 94 | |
| 95 | } |
| 96 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 97 | pid = FORK_OR_VFORK(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 98 | if (pid < 0) { |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 99 | (void)msgctl(msqid, IPC_RMID, NULL); |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 100 | tst_brkm(TFAIL, NULL, |
| 101 | "\tFork failed (may be OK if under stress)"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 102 | } else if (pid == 0) { |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 103 | #ifdef UCLINUX |
| 104 | if (self_exec(argv[0], "ndd", 1, msqid, c1_msgp.type) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 105 | tst_brkm(TFAIL, NULL, "\tself_exec failed"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 106 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 107 | #else |
| 108 | do_child_1(); |
| 109 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 110 | } else { |
robbiew | d16a793 | 2005-02-24 17:02:44 +0000 | [diff] [blame] | 111 | struct sigaction act; |
| 112 | |
| 113 | memset(&act, 0, sizeof(act)); |
| 114 | act.sa_handler = (sighandler_t) alrm; |
| 115 | sigemptyset(&act.sa_mask); |
| 116 | sigaddset(&act.sa_mask, SIGALRM); |
| 117 | if ((sigaction(SIGALRM, &act, NULL)) < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 118 | tst_resm(TFAIL | TERRNO, "signal failed"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 119 | kill(pid, SIGKILL); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 120 | (void)msgctl(msqid, IPC_RMID, NULL); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 121 | tst_exit(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 122 | } |
| 123 | ready = 0; |
| 124 | alarm(SECS); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 125 | while (!ready) /* make the child wait */ |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 126 | ; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 127 | for (i = 0; i < BYTES; i++) |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 128 | p1_msgp.text[i] = 'i'; |
| 129 | p1_msgp.type = 1; |
| 130 | if (msgsnd(msqid, &p1_msgp, BYTES, 0) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 131 | tst_resm(TFAIL | TERRNO, "msgsnd() failed"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 132 | kill(pid, SIGKILL); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 133 | (void)msgctl(msqid, IPC_RMID, NULL); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 134 | tst_exit(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 135 | } |
| 136 | wait(&status); |
| 137 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 138 | if ((status >> 8) == 1) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 139 | tst_brkm(TFAIL, NULL, "test failed. status = %d", |
| 140 | (status >> 8)); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 141 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 142 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 143 | pid = FORK_OR_VFORK(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 144 | if (pid < 0) { |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 145 | (void)msgctl(msqid, IPC_RMID, NULL); |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 146 | tst_brkm(TFAIL, NULL, |
| 147 | "\tFork failed (may be OK if under stress)"); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 148 | } else if (pid == 0) { |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 149 | #ifdef UCLINUX |
| 150 | if (self_exec(argv[0], "ndddd", 1, msqid, c1_msgp.type, |
| 151 | c2_msgp.type, c3_msgp.type) < 0) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 152 | tst_brkm(TFAIL, NULL, "\tself_exec failed"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 153 | } |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 154 | #else |
| 155 | do_child_2(); |
| 156 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 157 | } else { |
robbiew | d16a793 | 2005-02-24 17:02:44 +0000 | [diff] [blame] | 158 | struct sigaction act; |
| 159 | |
| 160 | memset(&act, 0, sizeof(act)); |
| 161 | act.sa_handler = (sighandler_t) alrm; |
| 162 | sigemptyset(&act.sa_mask); |
| 163 | sigaddset(&act.sa_mask, SIGALRM); |
| 164 | if ((sigaction(SIGALRM, &act, NULL)) < 0) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 165 | tst_resm(TFAIL | TERRNO, "signal failed"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 166 | kill(pid, SIGKILL); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 167 | (void)msgctl(msqid, IPC_RMID, NULL); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 168 | tst_exit(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 169 | } |
| 170 | ready = 0; |
| 171 | alarm(SECS); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 172 | while (!ready) /* make the child wait */ |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 173 | ; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 174 | for (i = 0; i < BYTES; i++) |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 175 | p1_msgp.text[i] = 'i'; |
| 176 | p1_msgp.type = 1; |
| 177 | if (msgsnd(msqid, &p1_msgp, BYTES, 0) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 178 | tst_resm(TFAIL | TERRNO, "msgsnd() failed"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 179 | kill(pid, SIGKILL); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 180 | (void)msgctl(msqid, IPC_RMID, NULL); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 181 | tst_exit(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 182 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 183 | for (j = 0; j < BYTES; j++) |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 184 | p2_msgp.text[j] = 'j'; |
| 185 | p2_msgp.type = 2; |
| 186 | if (msgsnd(msqid, &p2_msgp, BYTES, 0) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 187 | tst_resm(TFAIL | TERRNO, "msgsnd() failed"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 188 | kill(pid, SIGKILL); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 189 | (void)msgctl(msqid, IPC_RMID, NULL); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 190 | tst_exit(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 191 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 192 | for (k = 0; k < BYTES; k++) |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 193 | p3_msgp.text[k] = 'k'; |
| 194 | p3_msgp.type = 3; |
| 195 | if (msgsnd(msqid, &p3_msgp, BYTES, 0) == -1) { |
Wanlong Gao | 354ebb4 | 2012-12-07 10:10:04 +0800 | [diff] [blame] | 196 | tst_resm(TFAIL | TERRNO, "msgsnd() failed"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 197 | kill(pid, SIGKILL); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 198 | (void)msgctl(msqid, IPC_RMID, NULL); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 199 | tst_exit(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 200 | } |
| 201 | wait(&status); |
| 202 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 203 | if ((status >> 8) == 1) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 204 | tst_brkm(TFAIL, NULL, "test failed. status = %d", |
| 205 | (status >> 8)); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 206 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 207 | /* |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 208 | * Remove the message queue from the system |
| 209 | */ |
| 210 | #ifdef DEBUG |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 211 | tst_resm(TINFO, "Removing the message queue"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 212 | #endif |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 213 | fflush(stdout); |
Garrett Cooper | df3eb16 | 2010-11-28 22:44:32 -0800 | [diff] [blame] | 214 | (void)msgctl(msqid, IPC_RMID, NULL); |
| 215 | if ((status = msgctl(msqid, IPC_STAT, NULL)) != -1) { |
| 216 | (void)msgctl(msqid, IPC_RMID, NULL); |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 217 | tst_brkm(TFAIL, NULL, "msgctl(msqid, IPC_RMID) failed"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 218 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 219 | } |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 220 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 221 | fflush(stdout); |
| 222 | tst_resm(TPASS, "msgctl07 ran successfully!"); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 223 | |
subrata_modak | 6fa4a54 | 2008-04-06 11:44:36 +0000 | [diff] [blame] | 224 | cleanup(); |
| 225 | |
Cyril Hrubis | 4dff854 | 2014-09-23 12:11:59 +0200 | [diff] [blame] | 226 | tst_exit(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 227 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 228 | |
subrata_modak | 6fa4a54 | 2008-04-06 11:44:36 +0000 | [diff] [blame] | 229 | sighandler_t alrm(int sig) |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 230 | { |
| 231 | ready++; |
subrata_modak | 43337a3 | 2009-02-26 11:43:51 +0000 | [diff] [blame] | 232 | return 0; |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 233 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 234 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 235 | void do_child_1(void) |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 236 | { |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 237 | int i; |
| 238 | int size; |
| 239 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 240 | if ((size = msgrcv(msqid, &c1_msgp, BYTES, 0, 0)) == -1) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 241 | tst_brkm(TFAIL | TERRNO, NULL, "msgrcv() failed"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 242 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 243 | if (size != BYTES) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 244 | tst_brkm(TFAIL, NULL, "error: received %d bytes expected %d", |
| 245 | size, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 246 | BYTES); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 247 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 248 | for (i = 0; i < BYTES; i++) |
| 249 | if (c1_msgp.text[i] != 'i') { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 250 | tst_brkm(TFAIL, NULL, "error: corrup message"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 251 | } |
| 252 | exit(0); |
| 253 | } |
| 254 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 255 | void do_child_2(void) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 256 | { |
| 257 | int i, j, k; |
| 258 | int size; |
| 259 | |
| 260 | if ((size = msgrcv(msqid, &c3_msgp, BYTES, 3, 0)) == -1) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 261 | tst_brkm(TFAIL | TERRNO, NULL, "msgrcv() failed"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 262 | } |
| 263 | if (size != BYTES) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 264 | tst_brkm(TFAIL, NULL, "error: received %d bytes expected %d", |
| 265 | size, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 266 | BYTES); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 267 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 268 | for (k = 0; k < BYTES; k++) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 269 | if (c3_msgp.text[k] != 'k') { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 270 | tst_brkm(TFAIL, NULL, "error: corrupt message"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 271 | } |
| 272 | if ((size = msgrcv(msqid, &c2_msgp, BYTES, 2, 0)) == -1) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 273 | tst_brkm(TFAIL | TERRNO, NULL, "msgrcv() failed"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 274 | } |
| 275 | if (size != BYTES) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 276 | tst_brkm(TFAIL, NULL, "error: received %d bytes expected %d", |
| 277 | size, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 278 | BYTES); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 279 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 280 | for (j = 0; j < BYTES; j++) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 281 | if (c2_msgp.text[j] != 'j') { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 282 | tst_brkm(TFAIL, NULL, "error: corrupt message"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 283 | } |
| 284 | if ((size = msgrcv(msqid, &c1_msgp, BYTES, 1, 0)) == -1) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 285 | tst_brkm(TFAIL | TERRNO, NULL, "msgrcv() failed"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 286 | } |
| 287 | if (size != BYTES) { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 288 | tst_brkm(TFAIL, NULL, "error: received %d bytes expected %d", |
| 289 | size, |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 290 | BYTES); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 291 | } |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 292 | for (i = 0; i < BYTES; i++) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 293 | if (c1_msgp.text[i] != 'i') { |
Cyril Hrubis | 526fdf8 | 2014-12-04 14:35:01 +0100 | [diff] [blame] | 294 | tst_brkm(TFAIL, NULL, "error: corrupt message"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 295 | } |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 296 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 297 | exit(0); |
| 298 | } |
| 299 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 300 | void setup(void) |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 301 | { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 302 | tst_sig(FORK, DEF_HANDLER, cleanup); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 303 | |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 304 | TEST_PAUSE; |
subrata_modak | 6fa4a54 | 2008-04-06 11:44:36 +0000 | [diff] [blame] | 305 | |
subrata_modak | 6fa4a54 | 2008-04-06 11:44:36 +0000 | [diff] [blame] | 306 | tst_tmpdir(); |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 307 | } |
| 308 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 309 | void cleanup(void) |
robbiew | 577ff1a | 2002-12-05 20:12:28 +0000 | [diff] [blame] | 310 | { |
subrata_modak | 6fa4a54 | 2008-04-06 11:44:36 +0000 | [diff] [blame] | 311 | tst_rmdir(); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 312 | } |