Example #1
0
void cleanup(void)
{
	/* if they exist, remove the semaphore resources */
	rm_sema(sem_id_1);
	rm_sema(sem_id_2);

	tst_rmdir();
}
Example #2
0
File: semop05.c Project: Nan619/ltp
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 *	       or premature exit.
 */
void cleanup(void)
{
    /* if it exists, remove the semaphore resource */
    rm_sema(sem_id_1);

    tst_rmdir();
}
Example #3
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void
cleanup(void)
{
	/* if they exist, remove the semaphore resources */
	rm_sema(sem_id_1);
	rm_sema(sem_id_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();
}
Example #4
0
File: semget05.c Project: 1587/ltp
void cleanup(void)
{
	int i;

	for (i = 0; i < num_sems; i++) {
		rm_sema(sem_id_arr[i]);
	}

	free(sem_id_arr);
	tst_rmdir();
}
Example #5
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	void check_functionality(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 */

	/* 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
		 */

		TEST(semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA));

		if (TEST_RETURN == -1) {
			tst_resm(TFAIL, "%s call failed - errno = %d : %s",
				 TCID, TEST_ERRNO, strerror(TEST_ERRNO));
		} else {
			/* get the semaphore ID */
			sem_id_1 = TEST_RETURN;

			if (STD_FUNCTIONAL_TEST) {
				check_functionality();
			} else {
				tst_resm(TPASS, "semaphore was created");
			}
		}

		/*
		 * remove the semaphore that was created and mark the ID
		 * as invalid.
		 */
		if (sem_id_1 != -1) {
			rm_sema(sem_id_1);
			sem_id_1 = -1;
		}
	}

	cleanup();

	 /*NOTREACHED*/ return 0;
}
Example #6
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void cleanup(void)
{
	/* if it exists, remove the semaphore resource */
	rm_sema(sem_id_1);

	tst_rmdir();

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

}
Example #7
0
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, NULL, NULL)) != NULL) {
        tst_brkm(TBROK, NULL, "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 the non root user */
        if (setuid(ltp_uid) == -1) {
            tst_resm(TBROK, "setuid() failed");
            exit(1);
        }

        do_child();

    } else {
        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 semaphore resouce */
        rm_sema(sem_id_1);

        tst_rmdir();
    }
    cleanup();

    tst_exit();
}
Example #8
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void cleanup(void)
{
	/* if it exists, remove the semaphore resouce */
	rm_sema(sem_id_1);

	/* free malloced memory */
	free(get_arr.array);

	/* 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();
}
Example #9
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void cleanup(void)
{
	int i;

	/* remove the semaphore resources that were created */
	for (i = 0; i < num_sems; i++) {
		rm_sema(sem_id_arr[i]);
	}

	/* free malloced memory */
	free(sem_id_arr);

	tst_rmdir();

	/*
	 * print timing stats if that option was specified.
	 * print errno log if that option was specified.
	 */
	TEST_CLEANUP;

}
Example #10
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void
cleanup(void)
{
	int i;

	/* remove the semaphore resources that were created */
	for (i=0; i<num_sems; i++) {
		rm_sema(sem_id_arr[i]);
	}

	/* 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();
}
Example #11
0
/*
 * cleanup() - performs all the ONE TIME cleanup for this test at completion
 * 	       or premature exit.
 */
void
cleanup(void)
{
	if (seteuid(0) == -1) {
		tst_resm(TINFO, "setuid back to root error!\n");
	}

	/* if it exists, remove the semaphore resouce */
	rm_sema(sem_id_1);

	/* 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();
}
Example #12
0
int main(int ac, char **av)
{
	pid_t pid;
	void do_child(void);

	tst_parse_opts(ac, av, NULL, NULL);

	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 the non root user */
		if (setuid(ltp_uid) == -1) {
			tst_resm(TBROK, "setuid() failed");
			exit(1);
		}

		do_child();

	} else {
		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 semaphore resouce */
		rm_sema(sem_id_1);

		tst_rmdir();
	}
	cleanup();

	tst_exit();
}
Example #13
0
File: semop05.c Project: Nan619/ltp
int main(int ac, char **av)
{
    int lc;
    int i;
    pid_t pid;
    void do_child();

    tst_parse_opts(ac, av, NULL, NULL);

#ifdef UCLINUX
    maybe_run_child(&do_child_uclinux, "dd", &i_uclinux, &sem_id_1);
#endif

    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;

        for (i = 0; i < TST_TOTAL; i++) {

            /* initialize the s_buf buffer */
            s_buf.sem_op = TC[i].op;
            s_buf.sem_flg = TC[i].flg;
            s_buf.sem_num = TC[i].num;

            /* initialize all of the primitive semaphores */
            if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].semunptr)
                    == -1) {
                tst_brkm(TBROK, cleanup, "semctl() failed");
            }

            if ((pid = FORK_OR_VFORK()) == -1) {
                tst_brkm(TBROK, cleanup, "could not fork");
            }

            if (pid == 0) {	/* child */

#ifdef UCLINUX
                if (self_exec(av[0], "dd", i, sem_id_1) < 0) {
                    tst_brkm(TBROK, cleanup,
                             "could not self_exec");
                }
#else
                do_child(i);
#endif
            } else {
                TST_PROCESS_STATE_WAIT(cleanup, pid, 'S');

                /*
                 * If we are testing for EIDRM then remove
                 * the semaphore, else send a signal that
                 * must be caught as we are testing for
                 * EINTR.
                 */
                if (TC[i].error == EIDRM) {
                    /* remove the semaphore resource */
                    rm_sema(sem_id_1);
                } else {
                    if (kill(pid, SIGHUP) == -1) {
                        tst_brkm(TBROK, cleanup,
                                 "kill failed");
                    }
                }

                /* let the child carry on */
                waitpid(pid, NULL, 0);
            }

            /*
             * recreate the semaphore resource if needed
             */
            if (TC[i].error == EINTR) {
                continue;
            }

            if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT |
                                   IPC_EXCL | SEM_RA)) == -1) {
                tst_brkm(TBROK, cleanup, "couldn't recreate "
                         "semaphore");
            }
        }
    }

    cleanup();

    tst_exit();
}
Example #14
0
int main(int ac, char **av)
{
	int lc;			/* loop counter */
	char *msg;		/* message returned from parse_opts */
	int i;
	pid_t pid;
	void do_child();

	/* parse standard options */
	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, "dd", &i_uclinux, &sem_id_1);
#endif

	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;

		for (i = 0; i < TST_TOTAL; i++) {

			if (sync_pipe_create(sync_pipes, PIPE_NAME) == -1)
				tst_brkm(TBROK, cleanup,
					 "sync_pipe_create failed");

			/* initialize the s_buf buffer */
			s_buf.sem_op = TC[i].op;
			s_buf.sem_flg = TC[i].flg;
			s_buf.sem_num = TC[i].num;

			/* initialize all of the primitive semaphores */
			if (semctl(sem_id_1, TC[i].num, SETVAL, TC[i].semunptr)
			    == -1) {
				tst_brkm(TBROK, cleanup, "semctl() failed");
			}

			if ((pid = FORK_OR_VFORK()) == -1) {
				tst_brkm(TBROK, cleanup, "could not fork");
			}

			if (pid == 0) {	/* child */

#ifdef UCLINUX
				if (self_exec(av[0], "dd", i, sem_id_1) < 0) {
					tst_brkm(TBROK, cleanup,
						 "could not self_exec");
				}
#else
				do_child(i);
#endif
			} else {	/* parent */

				if (sync_pipe_wait(sync_pipes) == -1)
					tst_brkm(TBROK, cleanup,
						 "sync_pipe_wait failed: %d",
						 errno);

				if (sync_pipe_close(sync_pipes, PIPE_NAME) ==
				    -1)
					tst_brkm(TBROK, cleanup,
						 "sync_pipe_close failed: %d",
						 errno);

				/* After son has been created, give it a chance to execute the
				 * semop command before we continue. Without this sleep, on SMP machine
				 * the father rm_sema/kill could be executed before the son semop.
				 */
				sleep(1);

				/*
				 * If we are testing for EIDRM then remove
				 * the semaphore, else send a signal that
				 * must be caught as we are testing for
				 * EINTR.
				 */
				if (TC[i].error == EIDRM) {
					/* remove the semaphore resource */
					rm_sema(sem_id_1);
				} else {
					if (kill(pid, SIGHUP) == -1) {
						tst_brkm(TBROK, cleanup,
							 "kill failed");
					}
				}

				/* let the child carry on */
				waitpid(pid, NULL, 0);
			}

			/*
			 * recreate the semaphore resource if needed
			 */
			if (TC[i].error == EINTR) {
				continue;
			}

			if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT |
					       IPC_EXCL | SEM_RA)) == -1) {
				tst_brkm(TBROK, cleanup, "couldn't recreate "
					 "semaphore");
			}
		}
	}

	cleanup();

	tst_exit();
}
Example #15
0
File: semctl07.c Project: 1587/ltp
void cleanup(void)
{
	rm_sema(semid);
	tst_rmdir();
}