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(); }
/* * setup() - performs all the ONE TIME setup for this test. */ void setup(void) { key_t shmkey2; /* Switch to nobody user for correct error code collection */ if (geteuid() != 0) { tst_brkm(TBROK, tst_exit, "Test must be run as root"); } ltpuser = getpwnam(nobody_uid); if (setuid(ltpuser->pw_uid) == -1) { tst_resm(TINFO, "setuid failed to " "to set the effective uid to %d", ltpuser->pw_uid); perror("setuid"); } /* capture signals */ tst_sig(NOFORK, DEF_HANDLER, cleanup); /* Set up the expected error numbers for -e option */ TEST_EXP_ENOS(exp_enos); /* Pause if that option was specified */ TEST_PAUSE; /* * Create a temporary directory and cd into it. * This helps to ensure that a unique msgkey is created. * See ../lib/libipc.c for more information. */ tst_tmpdir(); /* get an IPC resource key */ shmkey = getipckey(); /* create a shared memory resource with read and write permissions */ /* also post increment the shmkey for the next shmget call */ if ((shm_id_2 = shmget(shmkey, INT_SIZE, SHM_RW | IPC_CREAT | IPC_EXCL)) == -1) { tst_brkm(TBROK, cleanup, "Failed to create shared memory " "resource #1 in setup()"); } /* Get an new IPC resource key. */ shmkey2 = getipckey(); /* create a shared memory resource without read and write permissions */ if ((shm_id_3 = shmget(shmkey2, INT_SIZE, IPC_CREAT | IPC_EXCL)) == -1) { tst_brkm(TBROK, cleanup, "Failed to create shared memory " "resource #2 in setup()"); } /* Probe an available linear address for attachment */ if ((base_addr = shmat(shm_id_2, NULL, 0)) == (void *)-1) { tst_brkm(TBROK, cleanup, "Couldn't attach shared memory"); } if (shmdt((const void *)base_addr) == -1) { tst_brkm(TBROK, cleanup, "Couldn't detach shared memory"); } /* some architectures (e.g. parisc) are strange, so better always align to * next SHMLBA address. */ base_addr = (void *)(((unsigned long)(base_addr) & ~(SHMLBA - 1)) + SHMLBA); }
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(); }
/*--------------------------------------------------------------*/ /*ARGSUSED*/ int main(int argc, char **argv) { register int i, pid; int count, child, status, nwait; #ifdef UCLINUX char *msg; if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) { tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); } argv0 = argv[0]; maybe_run_child(&do_child, "dS", &id_uclinux, &maxsemstring); #endif prog = argv[0]; nwait = 0; setup(); /*--------------------------------------------------------------*/ tid = -1; for (i = 0; i < NPROCS; i++) keyarray[i] = getipckey(); if ((signal(SIGTERM, term)) == SIG_ERR) { tst_resm(TFAIL, "\tsignal failed. errno = %d", errno); } for (i = 0; i < NPROCS; i++) { if ((pid = FORK_OR_VFORK()) < 0) { tst_resm(TFAIL, "\tFork failed (may be OK if under stress)"); } if (pid == 0) { procstat = 1; dotest(keyarray[i]); exit(0); } pidarray[i] = pid; nwait++; } /* * Wait for children to finish. */ count = 0; while ((child = wait(&status)) > 0) { if (status) { tst_resm(TFAIL, "%s[%d] Test failed. exit=0x%x", prog, child, status); local_flag = FAILED; } ++count; } /* * Should have collected all children. */ if (count != nwait) { tst_resm(TFAIL, "\tWrong # children waited on, count = %d", count); local_flag = FAILED; } if (local_flag != FAILED) tst_resm(TPASS, "semctl06 ran successfully!"); else tst_resm(TFAIL, "semctl06 failed"); /*--------------------------------------------------------------*/ /* Clean up any files created by test before call to anyfail. */ cleanup(); return (0); /* shut lint up */ }