1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
25 * trace systems calls if possible
34 systrace(const char* id
)
43 static char* trace
[] = { "trace", "truss", "strace", "traces" };
45 if (!(s
= getenv("HOME")))
47 if (!id
&& !(id
= (const char*)error_info
.id
))
48 id
= (const char*)trace
[0];
50 out
+= sfsprintf(out
, sizeof(buf
), "%s/.%s/%s", s
, trace
[0], id
);
51 if (access(buf
, F_OK
))
59 ov
[0] = PROC_FD_DUP(open("/dev/null", O_WRONLY
), 2, PROC_FD_PARENT
|PROC_FD_CHILD
);
61 sfsprintf(out
, &buf
[sizeof(buf
)] - out
, ".%d", getpid());
62 for (n
= 0; n
< elementsof(trace
); n
++)
63 if (!procfree(procopen(trace
[n
], av
+ 1, NiL
, ov
, PROC_ARGMOD
|PROC_GID
|PROC_UID
|(n
== (elementsof(trace
) - 1) ? PROC_CLEANUP
: 0))))