i hope this is worth a few tens of microseconds of
amusement.

the problem is this.  how to get a backtrace when
you may be killed by your parent who is cleaning
up after himself before somone wielding a debugger
has a chance to react?  the amusing answer is just run
acid yourself.  how?  well just catch the note.

sleazy, no? think of it as one more reason to enjoy plan 9.

- erik

----
; cat /rc/bin/stk
#!/bin/rc
for(i)
        echo 'stk()' | acid $i
----
#include <u.h>
#include <libc.h>

void
system(char *cmd, char **av)
{
        int in, pid;

        switch(pid=fork()){
        case -1:
                return;
        case 0:
                in = open("/dev/null", OREAD);
                close(0);
                dup(in, 0);
                exec(cmd, av);
                _exits(0);
        default:
                while(waitpid() < 0)
                        postnote(PNPROC, pid, "die");
                break;
        }
}

void
acid(void)
{
        char *av[3], buf[16];

        snprint(buf, sizeof buf, "%d", getpid());
        av[0] = "stk";
        av[1] = buf;
        av[2] = 0;
        system("/bin/stk", av);
}

int
an(void*, char*)
{
        acid();
        return 0;
}

void
main(void)
{
        atnotify(an, 1);
        abort();
        exits("");
}

Reply via email to