[PATCH 2/3] Test how PTRACE_SETOPTIONS support works
Roland McGrath
roland at redhat.com
Tue Oct 5 04:36:45 UTC 2010
> Since PTRACE_O_TRACECLONE/*FORK were introduced to kernel
> at the same time, so this test seems enough for these 3 options.
I agree.
> +#ifdef LINUX
> +/* Test whether kernel support PTRACE_O_TRACECLONE et al options.
> + * First fork a new child, call ptrace with PTRACE_SETOPTIONS on it,
> + * and then see which options are supported on this kernel.
> + */
> +int test_ptrace_setoptions()
There is no reason this can't be static, so make it static.
Also, we're using prototypes now, so make its argument list (void).
> + unsigned int test_options = PTRACE_O_TRACEFORK;
IMHO using an unchanging variable for this is less clear, not more.
Just use the constant in the actual call below.
> + kill(getpid(), SIGSTOP);
Might as well use raise, though it's the same.
> + if ((pid = fork()) < 0) {
> + exit(1);
> + }
> + exit(0);
Not that it really matters here where the parent hasn't used stdio output
calls beforehand, but a fork child should use _exit rather than exit.
> + }
> + else {
> + int status, tracee_pid, wait_errno;
> + int no_child = 0;
> + while(1) {
Put a space after the while keyword.
> + if (tracee_pid != pid)
> + ptrace(PTRACE_CONT, tracee_pid, 0, 0);
You check every other error, so might as well check the ptrace result too.
> + ptrace(PTRACE_SYSCALL, pid, 0, 0);
Likewise here.
> +#ifdef LINUX
> + if (test_ptrace_setoptions() < 0) {
> + fprintf(stderr, "Test for options supported by PTRACE_SETOPTIONS\
> + failed, give up using this feature\n");
> + ptrace_setoptions = 0;
There is no reason to do the test at all unless followfork is set (-f/-F).
Thanks,
Roland
More information about the Strace-devel
mailing list