Exemple #1
0
/*
 * setup() - performs all the ONE TIME setup for this test.
 */
void setup(void)
{
	/* 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();

	msgkey = getipckey();

	maxmsgs = get_max_msgqueues();
	if (maxmsgs < 0)
		tst_brkm(TBROK, cleanup, "maxmsgs is zero");

	msg_q_arr = (int *)calloc(maxmsgs, sizeof(int));
	if (msg_q_arr == NULL) {
		tst_brkm(TBROK, cleanup, "Couldn't allocate memory "
			 "for msg_q_arr: calloc() failed");
	}
}
Exemple #2
0
/*
 * setup() - performs all the ONE TIME setup for this test.
 */
void
setup(void)
{
	int msg_q;

	/* 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();

	msgkey = getipckey();

	maxmsgs = get_max_msgqueues();

	msg_q_arr = (int *)calloc(maxmsgs, sizeof (int));
	if (msg_q_arr == NULL) {
		tst_brkm(TBROK, cleanup, "Couldn't allocate memory "
				"for msg_q_arr: calloc() failed");
	}

	/*
	 * Use a while loop to create the maximum number of queues.
	 * When we get an error, check for ENOSPC.
	 */
	while((msg_q = msgget(msgkey + num_queue, IPC_CREAT|IPC_EXCL)) != -1) {
		msg_q_arr[num_queue] = msg_q;
		if (num_queue == maxmsgs) {
			tst_resm(TINFO, "The maximum number of message"
				 " queues (%d) has been reached", maxmsgs);
			break;
		}
		num_queue++;
	}

	/*
	 * if we have something other than ENOSPC, then something else is
	 * wrong.
	 */

	if (errno != ENOSPC) {
		tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup"
			 " - errno = %d : %s", errno, strerror(errno));
	}
}