|
|
1.1 ! root 1: #include <stdio.h> ! 2: #include <signal.h> ! 3: #include <sys/ptrace.h> ! 4: #include <sys/wait.h> ! 5: ! 6: /* ! 7: * bsd semi-equivalent of Ninth Edition hang ! 8: * ! 9: * D. A. Kapilow 12/18/87 ! 10: */ ! 11: ! 12: main(argc,argv) ! 13: int argc; char **argv; ! 14: { ! 15: int pid, wpid; ! 16: union wait status; ! 17: ! 18: if (argc <= 1) { ! 19: fprintf(stderr,"Usage: %s cmd [args...]\n",*argv); ! 20: exit(1); ! 21: } ! 22: if ((pid = fork()) == 0) { ! 23: ptrace(PTRACE_TRACEME, 0, 0, 0, 0); ! 24: execvp(argv[1], argv+1); ! 25: perror(argv[1]); ! 26: exit(1); ! 27: } ! 28: if (pid < 0) { ! 29: fprintf(stderr,"%s: can't fork\n",*argv); ! 30: exit(1); ! 31: } ! 32: while ((wpid = wait(&status)) != pid) ! 33: ; ! 34: if (!WIFSTOPPED(status) || status.w_stopsig != SIGTRAP) { ! 35: fprintf(stderr,"%s: child died\n",*argv); ! 36: exit(1); ! 37: } ! 38: kill(pid, SIGSTOP); ! 39: ptrace(PTRACE_DETACH, pid, (int *)1, 0, 0); ! 40: fprintf(stderr, "%d %s\n", pid, argv[1]); ! 41: while ((wpid = wait(&status)) != pid) ! 42: if (wpid < 0) ! 43: exit(1); ! 44: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.