HP-UX Reference (11i v2 04/09) - 2 System Calls (vol 5)

t
ttrace(2) ttrace(2)
ev.tte_events = TTEVT_SYSCALL|TTEVT_EXEC|TTEVT_EXIT;
ev.tte_opts = TTEO_NONE;
if (pid) {
siginfo_t si;
dottrace(TT_PROC_ATTACH, pid, 0, TT_DETACH_ON_EXIT,
TT_VERSION, 0);
if (waitid(P_PID, pid, &si, WEXITED|WSTOPPED)<0||
si.si_pid != pid || si.si_code != CLD_STOPPED) {
errexit("waitid");
}
dottrace(TT_PROC_GET_FIRST_LWP_STATE, pid, 0, (uint64_t) &st,
(uint64_t) sizeof st, 0);
show_event(&st);
dottrace(TT_PROC_SET_EVENT_MASK, pid, 0,
(uint64_t) &ev, sizeof ev, 0);
}
else {
if (pipe(pfd1) < 0 || pipe(pfd2) < 0) {
errexit("pipe");
}
switch(pid = fork()) {
case -1:
errexit("fork");
case 0:
ppid = getppid();
dottrace(TT_PROC_SETTRC, 0, 0, 0, TT_VERSION, 0);
/* tell parent we are SETTRC’ed */
if (write(pfd2[1], (void *) &c, sizeof c) != sizeof c) {
errexit("write");
}
/* wait for exec event to be set*/
if (read(pfd1[0], (void *) &c, sizeof c) != sizeof c) {
errexit("read");
}
(void) close(pfd1[0]);
(void) close(pfd1[1]);
(void) close(pfd2[0]);
(void) close(pfd2[1]);
(void) execvp(*argv, argv);
ppid = 0;
errexit("exec");
}
if (read(pfd2[0], (void *) &c, sizeof c) != sizeof c) {
errexit("read");
}
dottrace(TT_PROC_SET_EVENT_MASK, pid, 0,
(uint64_t) &ev, sizeof ev, 0);
/* tell the child to exec */
if (write(pfd1[1], (void *) &c, sizeof c) != sizeof c) {
errexit("write");
}
(void) close(pfd1[0]);
(void) close(pfd1[1]);
(void) close(pfd2[0]);
(void) close(pfd2[1]);
}
dottrace(TT_PROC_CONTINUE, pid, 0, 0, 0, 0);
for (;;) {
HP-UX 11i Version 2: September 2004 18 Hewlett-Packard Company Section 2461