FreeBSD/tools/regression/priv/main.c
/*
 * Run a test in a particular credential context -- always call the setup and
 * cleanup routines; if setup succeeds, also run the test.  Test cleanup must
 * handle cases where the setup has failed, so may need to maintain their own
 * state in order to know what needs cleaning up (such as whether temporary
 * files were created).
 */
Run a test in a particular credential context -- always call the setup and
cleanup routines; if setup succeeds, also run the test.  Test cleanup must
handle cases where the setup has failed, so may need to maintain their own
state in order to know what needs cleaning up (such as whether temporary
files were created).
Run a test in a particular credential context -- always call the setup and cleanup routines ; if setup succeeds also run the test . Test cleanup must handle cases where the setup has failed so may need to maintain their own state in order to know what needs cleaning up ( such as whether temporary files were created ) .
static void
run(struct test *test, int asroot, int injail)
{
	pid_t childpid, pid;
	if (test->t_setup_func != NULL) {
		if ((test->t_setup_func)(asroot, injail, test) != 0) {
			warnx("run(%s, %d, %d) setup failed", test->t_name,
			    asroot, injail);
			goto cleanup;
		}
	}
	fflush(stdout);
	fflush(stderr);
	childpid = fork();
	if (childpid == -1) {
		warn("run(%s, %d, %d) fork failed", test->t_name, asroot,
		    injail);
		goto cleanup;
	}
	if (childpid == 0) {
		run_child(test, asroot, injail);
		fflush(stdout);
		fflush(stderr);
		exit(something_failed ? EXIT_FAILURE : EXIT_SUCCESS);
	} else {
		while (1) {
			int status;
			pid = waitpid(childpid, &status, 0);
			if (pid == -1) {
				something_failed = 1;
				warn("test: waitpid %s", test->t_name);
			}
			if (pid == childpid) {
				if (WIFEXITED(status) &&
				    WEXITSTATUS(status) == EXIT_SUCCESS) {
				} else {
					something_failed = 1;
				}
				break;
			}
		}
	}
	fflush(stdout);
	fflush(stderr);
cleanup:
	if (test->t_cleanup_func != NULL)
		test->t_cleanup_func(asroot, injail, test);
}
static void run ( struct test * test , int asroot , int injail ) { pid_t childpid , pid ; if ( test -> t_setup_func != NULL ) { if ( ( test -> t_setup_func ) ( asroot , injail , test ) != 0 ) { warnx ( " " , test -> t_name , asroot , injail ) ; goto cleanup ; } } fflush ( stdout ) ; fflush ( stderr ) ; childpid = fork ( ) ; if ( childpid == -1 ) { warn ( " " , test -> t_name , asroot , injail ) ; goto cleanup ; } if ( childpid == 0 ) { run_child ( test , asroot , injail ) ; fflush ( stdout ) ; fflush ( stderr ) ; exit ( something_failed ? EXIT_FAILURE : EXIT_SUCCESS ) ; } else { while ( 1 ) { int status ; pid = waitpid ( childpid , & status , 0 ) ; if ( pid == -1 ) { something_failed = 1 ; warn ( " " , test -> t_name ) ; } if ( pid == childpid ) { if ( WIFEXITED ( status ) && WEXITSTATUS ( status ) == EXIT_SUCCESS ) { } else { something_failed = 1 ; } break ; } } } fflush ( stdout ) ; fflush ( stderr ) ; cleanup : if ( test -> t_cleanup_func != NULL ) test -> t_cleanup_func ( asroot , injail , test ) ; }
Run a test in a particular credential context -- always call the setup and
 cleanup routines; if setup succeeds, also run the test.
Run a test in a particular credential context -- always call the setup and cleanup routines ; if setup succeeds also run the test .
/* All good in the subprocess! */