From: ramsdell@mitre.org (John D. Ramsdell)
To: linux-audit@redhat.com
Subject: Re: An autrace that follows forks
Date: 15 Oct 2006 11:38:16 -0400 [thread overview]
Message-ID: <ogtzmbxk2s7.fsf@divan.mitre.org> (raw)
In-Reply-To: <ogtlknk2ul5.fsf@divan.mitre.org>
ramsdell@mitre.org (John D. Ramsdell) writes:
> The tricky part seems to be that the SIGTRAP generated by the
> parent's immediate child has to be converted to a SIGSTOP before
> continuing the child.
If you trace a shell, you find out you must always convert a SIGTRAP
to a SIGSTOP.
John
> static int /* Watch all children */
> watch(pid_t pid) /* This process' child is pid */
> { /* Function returns an exit code */
> if (add_rule(pid))
> return 1;
> for (;;) {
> int status;
> pid = wait_for_it(&status);
> if (pid < 0) {
> if (errno == ECHILD) /* No children to wait for */
> return 0; /* Declare success */
> perror("wait");
> return 1;
> }
> if (WIFSTOPPED(status)) {
> int signal = WSTOPSIG(status);
> if (signal == SIGTRAP) { /* Tracing causes this signal */
signal = SIGSTOP;
> unsigned long msg;
> if (geteventmsg(pid, &msg) < 0) {
> perror("ptrace(PTRACE_GETEVENTMSG, ...)");
> return 1;
> }
> pid_t child = (pid_t)msg;
> if (child) {
> /* The child of each traced fork is noted here */
> if (add_rule(child))
> return 1;
> }
> /* Only this process' child gets to this location, and just
> one time */
> else if (setoptions(pid, PTRACE_O_TRACEFORK) < 0) {
> perror("ptrace(PTRACE_SETOPTIONS, ...)");
> return 1;
> }
/* Wrong
> else
> signal = SIGSTOP;
*/
> }
> if (restart(pid, signal) < 0) {
> perror("ptrace(PTRACE_CONT, ...)");
> return 1;
> }
> }
> }
> }
prev parent reply other threads:[~2006-10-15 15:38 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-10-11 20:06 An autrace that follows forks John D. Ramsdell
2006-10-11 20:24 ` Steve Grubb
2006-10-12 10:51 ` John D. Ramsdell
2006-10-13 14:07 ` Steve Grubb
2006-10-15 15:32 ` John D. Ramsdell
2006-10-11 20:55 ` James Antill
2006-10-12 11:09 ` John D. Ramsdell
2006-10-12 11:40 ` John D. Ramsdell
2006-10-13 13:50 ` John D. Ramsdell
2006-10-15 15:38 ` John D. Ramsdell [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ogtzmbxk2s7.fsf@divan.mitre.org \
--to=ramsdell@mitre.org \
--cc=linux-audit@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.