/***********************************************************************1* *2* This software is part of the ast package *3* Copyright (c) 1985-2011 AT&T Intellectual Property *4* and is licensed under the *5* Eclipse Public License, Version 1.0 *6* by AT&T Intellectual Property *7* *8* A copy of the License is available at *9* http://www.eclipse.org/org/documents/epl-v10.html *10* (with md5 checksum b35adb5213ca9657e911e9befb180842) *11* *12* Information and Software Systems Research *13* AT&T Research *14* Florham Park NJ *15* *16* Glenn Fowler <[email protected]> *17* David Korn <[email protected]> *18* Phong Vo <[email protected]> *19* *20***********************************************************************/21#pragma prototyped2223/*24* trace systems calls if possible25*/2627#include <ast.h>28#include <error.h>29#include <proc.h>30#include <debug.h>3132void33systrace(const char* id)34{35register int n;36register char* out;37char* s;38char buf[PATH_MAX];39char* av[7];40long ov[2];4142static char* trace[] = { "trace", "truss", "strace", "traces" };4344if (!(s = getenv("HOME")))45return;46if (!id && !(id = (const char*)error_info.id))47id = (const char*)trace[0];48out = buf;49out += sfsprintf(out, sizeof(buf), "%s/.%s/%s", s, trace[0], id);50if (access(buf, F_OK))51return;52av[1] = trace[0];53av[2] = "-o";54av[3] = buf;55av[4] = "-p";56av[5] = out + 1;57av[6] = 0;58ov[0] = PROC_FD_DUP(open("/dev/null", O_WRONLY), 2, PROC_FD_PARENT|PROC_FD_CHILD);59ov[1] = 0;60sfsprintf(out, &buf[sizeof(buf)] - out, ".%d", getpid());61for (n = 0; n < elementsof(trace); n++)62if (!procfree(procopen(trace[n], av + 1, NiL, ov, PROC_ARGMOD|PROC_GID|PROC_UID|(n == (elementsof(trace) - 1) ? PROC_CLEANUP : 0))))63{64sleep(1);65break;66}67}686970