FreeBSD/tests/sys/kern/ptrace_test.c
/*
 * Helper routine for follow fork tests.  This waits for two stops
 * that report both "sides" of a fork.  It returns the pid of the new
 * child process.
 */
Helper routine for follow fork tests.  This waits for two stops
that report both "sides" of a fork.  It returns the pid of the new
child process.
Helper routine for follow fork tests . This waits for two stops that report both " sides " of a fork . It returns the pid of the new child process .
static pid_t
handle_fork_events(pid_t parent, struct ptrace_lwpinfo *ppl)
{
	struct ptrace_lwpinfo pl;
	bool fork_reported[2];
	pid_t child, wpid;
	int i, status;
	fork_reported[0] = false;
	fork_reported[1] = false;
	child = -1;
	for (i = 0; i < 2; i++) {
		wpid = wait(&status);
		ATF_REQUIRE(wpid > 0);
		ATF_REQUIRE(WIFSTOPPED(status));
		ATF_REQUIRE(ptrace(PT_LWPINFO, wpid, (caddr_t)&pl,
		    sizeof(pl)) != -1);
		ATF_REQUIRE((pl.pl_flags & (PL_FLAG_FORKED | PL_FLAG_CHILD)) !=
		    0);
		ATF_REQUIRE((pl.pl_flags & (PL_FLAG_FORKED | PL_FLAG_CHILD)) !=
		    (PL_FLAG_FORKED | PL_FLAG_CHILD));
		if (pl.pl_flags & PL_FLAG_CHILD) {
			ATF_REQUIRE(wpid != parent);
			ATF_REQUIRE(WSTOPSIG(status) == SIGSTOP);
			ATF_REQUIRE(!fork_reported[1]);
			if (child == -1)
				child = wpid;
			else
				ATF_REQUIRE(child == wpid);
			if (ppl != NULL)
				ppl[1] = pl;
			fork_reported[1] = true;
		} else {
			ATF_REQUIRE(wpid == parent);
			ATF_REQUIRE(WSTOPSIG(status) == SIGTRAP);
			ATF_REQUIRE(!fork_reported[0]);
			if (child == -1)
				child = pl.pl_child_pid;
			else
				ATF_REQUIRE(child == pl.pl_child_pid);
			if (ppl != NULL)
				ppl[0] = pl;
			fork_reported[0] = true;
		}
	}
	return (child);
}
static pid_t handle_fork_events ( pid_t parent , struct ptrace_lwpinfo * ppl ) { struct ptrace_lwpinfo pl ; bool fork_reported [ 2 ] ; pid_t child , wpid ; int i , status ; fork_reported [ 0 ] = false ; fork_reported [ 1 ] = false ; child = -1 ; for ( i = 0 ; i < 2 ; i ++ ) { wpid = wait ( & status ) ; ATF_REQUIRE ( wpid > 0 ) ; ATF_REQUIRE ( WIFSTOPPED ( status ) ) ; ATF_REQUIRE ( ptrace ( PT_LWPINFO , wpid , ( caddr_t ) & pl , sizeof ( pl ) ) != -1 ) ; ATF_REQUIRE ( ( pl . pl_flags & ( PL_FLAG_FORKED | PL_FLAG_CHILD ) ) != 0 ) ; ATF_REQUIRE ( ( pl . pl_flags & ( PL_FLAG_FORKED | PL_FLAG_CHILD ) ) != ( PL_FLAG_FORKED | PL_FLAG_CHILD ) ) ; if ( pl . pl_flags & PL_FLAG_CHILD ) { ATF_REQUIRE ( wpid != parent ) ; ATF_REQUIRE ( WSTOPSIG ( status ) == SIGSTOP ) ; ATF_REQUIRE ( ! fork_reported [ 1 ] ) ; if ( child == -1 ) child = wpid ; else ATF_REQUIRE ( child == wpid ) ; if ( ppl != NULL ) ppl [ 1 ] = pl ; fork_reported [ 1 ] = true ; } else { ATF_REQUIRE ( wpid == parent ) ; ATF_REQUIRE ( WSTOPSIG ( status ) == SIGTRAP ) ; ATF_REQUIRE ( ! fork_reported [ 0 ] ) ; if ( child == -1 ) child = pl . pl_child_pid ; else ATF_REQUIRE ( child == pl . pl_child_pid ) ; if ( ppl != NULL ) ppl [ 0 ] = pl ; fork_reported [ 0 ] = true ; } } return ( child ) ; }
Helper routine for follow fork tests.
Helper routine for follow fork tests .
/*
	 * Each process should report a fork event.  The parent should
	 * report a PL_FLAG_FORKED event, and the child should report
	 * a PL_FLAG_CHILD event.
	 */