/* * cleanup() - performs all the ONE TIME cleanup for this test at completion * or premature exit. */ void cleanup(void) { /* if it exists, remove the message queue #1 */ rm_queue(msg_q_1); /* if it exists, remove the message queue #2 */ rm_queue(msg_q_2); tst_rmdir(); }
/* * cleanup() - performs all the ONE TIME cleanup for this test at completion * or premature exit. */ void cleanup(void) { int i; /* * remove the message queues if they were created */ if (msg_q_arr != NULL) { for (i = 0; i < num_queue; i++) { rm_queue(msg_q_arr[i]); } (void)free(msg_q_arr); } /* Remove the temporary directory */ tst_rmdir(); /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; /* exit with return code appropriate for results */ tst_exit(); }
/* * do_child() */ void do_child() { TEST(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, 1, 0)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded when error expected"); exit(-1); } TEST_ERROR_LOG(TEST_ERRNO); switch(TEST_ERRNO) { case EIDRM: tst_resm(TPASS, "expected failure - errno = %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); /* mark the queue as invalid as it was removed */ msg_q_1 = -1; break; default: tst_resm(TFAIL, "call failed with an unexpected error - %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); break; } /* if it exists, remove the message queue that was created */ rm_queue(msg_q_1); exit(0); }
/* * cleanup() - performs all the ONE TIME cleanup for this test at completion * or premature exit. */ void cleanup(void) { /* if it exists, remove the message queue #1 */ rm_queue(msg_q_1); /* if it exists, remove the message queue #2 */ rm_queue(msg_q_2); tst_rmdir(); /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; }
/* * cleanup() - performs all the ONE TIME cleanup for this test at completion * or premature exit. */ void cleanup(void) { /* if it exists, remove the message queue that was created */ rm_queue(msg_q_1); tst_rmdir(); }
/* * cleanup() - performs all the ONE TIME cleanup for this test at completion * or premature exit. */ void cleanup(void) { /* * remove the message queues that were created. */ rm_queue(msg_q_1); rm_queue(msg_q_2); tst_rmdir(); /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; }
/* * cleanup() - performs all the ONE TIME cleanup for this test at completion * or premature exit. */ void cleanup(void) { /* * remove the message queues that were created. */ rm_queue(msg_q_1); rm_queue(msg_q_2); /* Remove the temporary directory */ tst_rmdir(); /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; /* exit with return code appropriate for results */ tst_exit(); }
int main(int ac, char **av) { int lc; void check_functionality(void); tst_parse_opts(ac, av, NULL, NULL); setup(); /* global setup */ /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset tst_count in case we are looping */ tst_count = 0; /* * Use TEST macro to make the call to create the message queue */ TEST(msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RD | MSG_WR)); if (TEST_RETURN == -1) { tst_resm(TFAIL, "%s call failed - errno = %d : %s", TCID, TEST_ERRNO, strerror(TEST_ERRNO)); } else { msg_q_1 = TEST_RETURN; /* * write a message to the queue. * read back the message. * PASS the test if they are the same. */ check_functionality(); } /* * remove the message queue that was created and mark the ID * as invalid. */ if (msg_q_1 != -1) { rm_queue(msg_q_1); msg_q_1 = -1; } } cleanup(); tst_exit(); }
int main(int ac, char **av) { char *msg; /* message returned from parse_opts */ pid_t pid; void do_child(void); /* parse standard options */ if ((msg = parse_opts(ac, av, (option_t *)NULL, NULL)) != (char *)NULL){ tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg); } setup(); /* global setup */ if ((pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "could not fork"); } if (pid == 0) { /* child */ /* set the user ID of the child to nobody */ if (setuid(ltp_uid) == -1) { tst_resm(TBROK, "setuid() failed"); exit(1); } do_child(); } else { /* parent */ if (waitpid(pid, NULL, 0) == -1) { tst_resm(TBROK, "waitpid() failed"); tst_resm(TINFO, "waitpid() error = %d : %s", errno, strerror(errno)); } /* if it exists, remove the message queue */ rm_queue(msg_q_1); /* Remove the temporary directory */ tst_rmdir(); } cleanup (); /**NOT REACHED**/ return(0); }
/* * do_child() */ void do_child() { if (sync_pipe_notify(sync_pipes) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_notify failed"); if (sync_pipe_close(sync_pipes, PIPE_NAME) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_close failed"); TEST(msgrcv(msg_q_1, &rcv_buf, MSGSIZE, 1, 0)); if (TEST_RETURN != -1) { tst_resm(TFAIL, "call succeeded when error expected"); exit(-1); } TEST_ERROR_LOG(TEST_ERRNO); switch (TEST_ERRNO) { case EIDRM: tst_resm(TPASS, "expected failure - errno = %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); /* mark the queue as invalid as it was removed */ msg_q_1 = -1; break; default: tst_resm(TFAIL, "call failed with an unexpected error - %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); break; } /* if it exists, remove the message queue that was created */ rm_queue(msg_q_1); tst_exit(); }
/* * cleanup() - performs all the ONE TIME cleanup for this test at completion * or premature exit. */ void cleanup(void) { int i; /* * remove the message queues if they were created */ if (msg_q_arr != NULL) { for (i = 0; i < num_queue; i++) { rm_queue(msg_q_arr[i]); } (void)free(msg_q_arr); } tst_rmdir(); /* * print timing stats if that option was specified. * print errno log if that option was specified. */ TEST_CLEANUP; }
int main(int ac, char **av) { int lc; char *msg; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } #ifdef UCLINUX maybe_run_child(&do_child_uclinux, "d", &msg_q_1); #endif setup(); /* global setup */ if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_create failed"); /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset tst_count in case we are looping */ tst_count = 0; /* * set up the queue here so that multiple test iterations * will work. */ msgkey = getipckey(); /* create a message queue with read/write permission */ if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) { tst_brkm(TBROK, cleanup, "Can't create message queue"); } /* * fork a child that will attempt to read a non-existent * message from the queue */ if ((c_pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "could not fork"); } if (c_pid == 0) { /* child */ /* * Attempt to read a message without IPC_NOWAIT. * With no message to read, the child sleeps. */ #ifdef UCLINUX if (self_exec(av[0], "d", msg_q_1) < 0) { tst_brkm(TBROK, cleanup, "could not self_exec"); } #else do_child(); #endif } else { /* parent */ if (sync_pipe_wait(sync_pipes) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_wait failed"); if (sync_pipe_close(sync_pipes, PIPE_NAME) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_close failed"); sleep(1); /* remove the queue */ rm_queue(msg_q_1); waitpid(c_pid, NULL, 0); } } tst_exit(); }
int main(int ac, char **av) { int lc; char *msg; pid_t c_pid; int status, e_code; if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } #ifdef UCLINUX #define PIPE_NAME "msgsnd06" maybe_run_child(&do_child, "d", &msg_q_1); #endif setup(); /* global setup */ if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_create failed"); /* The following loop checks looping state if -i option given */ for (lc = 0; TEST_LOOPING(lc); lc++) { /* reset Tst_count in case we are looping */ Tst_count = 0; msgkey = getipckey(); /* create a message queue with read/write permission */ if ((msg_q_1 = msgget(msgkey, IPC_CREAT | IPC_EXCL | MSG_RW)) == -1) { tst_brkm(TBROK, cleanup, "Can't create message queue"); } /* initialize the message buffer */ init_buf(&msg_buf, MSGTYPE, MSGSIZE); /* write messages to the queue until it is full */ while (msgsnd(msg_q_1, &msg_buf, MSGSIZE, IPC_NOWAIT) != -1) { msg_buf.mtype += 1; } /* * fork a child that will attempt to write a message * to the queue without IPC_NOWAIT */ if ((c_pid = FORK_OR_VFORK()) == -1) { tst_brkm(TBROK, cleanup, "could not fork"); } if (c_pid == 0) { /* child */ #ifdef UCLINUX if (self_exec(av[0], "d", msg_q_1) < 0) { tst_brkm(TBROK, cleanup, "could not self_exec"); } #else do_child(); #endif } else { /* parent */ if (sync_pipe_wait(sync_pipes) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_wait failed"); if (sync_pipe_close(sync_pipes, PIPE_NAME) == -1) tst_brkm(TBROK, cleanup, "sync_pipe_close failed"); /* After son has been created, give it a chance to execute the * msgsnd command before we continue. Without this sleep, on SMP machine * the father rm_queue could be executed before the son msgsnd. */ sleep(2); /* remove the queue */ rm_queue(msg_q_1); /* wait for the child to finish */ wait(&status); /* make sure the child returned a good exit status */ e_code = status >> 8; if (e_code != 0) { tst_resm(TFAIL, "Failures reported above"); } } } cleanup(); tst_exit(); }