mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-11-16 07:11:05 +01:00
Sort Xrefs. Use err(3). Remove uneeded #include.
Correct usage: one of {-p pid, command} is required. Open output file when command line is fully analyzed: incorrect `truss -o f' command does not create an empty file anymore.
This commit is contained in:
parent
2632a83f1e
commit
3cf51049e0
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=32275
@ -27,9 +27,13 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* FreeBSD/386-specific system call handling. This is probably the most
|
||||
* complex part of the entire truss program, although I've got lots of
|
||||
@ -37,17 +41,13 @@
|
||||
* automatically, thanks to /usr/src/sys/kern/syscalls.master. The
|
||||
* names used for the various structures are confusing, I sadly admit.
|
||||
*/
|
||||
/*
|
||||
* $Id: i386-fbsd.c,v 1.1 1997/12/06 05:22:50 sef Exp $
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/pioctl.h>
|
||||
@ -113,7 +113,6 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
int i;
|
||||
int memfd;
|
||||
unsigned int parm_offset;
|
||||
struct syscall *sc;
|
||||
|
||||
@ -190,7 +189,6 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
*/
|
||||
|
||||
if (fsc.name) {
|
||||
char *tmp;
|
||||
|
||||
#if DEBUG
|
||||
fprintf(stderr, "syscall %s(", fsc.name);
|
||||
|
@ -27,24 +27,25 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* Linux/i386-specific system call handling. Given how much of this code
|
||||
* is taken from the freebsd equivalent, I can probably put even more of
|
||||
* it in support routines that can be used by any personality support.
|
||||
*/
|
||||
/*
|
||||
* $Id: i386-linux.c,v 1.1 1997/12/06 05:22:54 sef Exp $
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/pioctl.h>
|
||||
@ -91,7 +92,6 @@ i386_linux_syscall_entry(int pid, int nargs) {
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
int i;
|
||||
int memfd;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
@ -149,7 +149,6 @@ i386_linux_syscall_entry(int pid, int nargs) {
|
||||
lsc.sc = sc;
|
||||
|
||||
if (lsc.name) {
|
||||
char *tmp;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "syscall %s(", lsc.name);
|
||||
|
@ -27,9 +27,13 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* FreeBSD/386-specific system call handling. This is probably the most
|
||||
* complex part of the entire truss program, although I've got lots of
|
||||
@ -37,17 +41,13 @@
|
||||
* automatically, thanks to /usr/src/sys/kern/syscalls.master. The
|
||||
* names used for the various structures are confusing, I sadly admit.
|
||||
*/
|
||||
/*
|
||||
* $Id: i386-fbsd.c,v 1.1 1997/12/06 05:22:50 sef Exp $
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/pioctl.h>
|
||||
@ -113,7 +113,6 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
int i;
|
||||
int memfd;
|
||||
unsigned int parm_offset;
|
||||
struct syscall *sc;
|
||||
|
||||
@ -190,7 +189,6 @@ i386_syscall_entry(int pid, int nargs) {
|
||||
*/
|
||||
|
||||
if (fsc.name) {
|
||||
char *tmp;
|
||||
|
||||
#if DEBUG
|
||||
fprintf(stderr, "syscall %s(", fsc.name);
|
||||
|
@ -27,24 +27,25 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* Linux/i386-specific system call handling. Given how much of this code
|
||||
* is taken from the freebsd equivalent, I can probably put even more of
|
||||
* it in support routines that can be used by any personality support.
|
||||
*/
|
||||
/*
|
||||
* $Id: i386-linux.c,v 1.1 1997/12/06 05:22:54 sef Exp $
|
||||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/pioctl.h>
|
||||
@ -91,7 +92,6 @@ i386_linux_syscall_entry(int pid, int nargs) {
|
||||
struct reg regs = { 0 };
|
||||
int syscall;
|
||||
int i;
|
||||
int memfd;
|
||||
struct syscall *sc;
|
||||
|
||||
if (fd == -1 || pid != cpid) {
|
||||
@ -149,7 +149,6 @@ i386_linux_syscall_entry(int pid, int nargs) {
|
||||
lsc.sc = sc;
|
||||
|
||||
if (lsc.name) {
|
||||
char *tmp;
|
||||
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "syscall %s(", lsc.name);
|
||||
|
@ -27,25 +27,26 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* The main module for truss. Suprisingly simple, but, then, the other
|
||||
* files handle the bulk of the work. And, of course, the kernel has to
|
||||
* do a lot of the work :).
|
||||
*/
|
||||
/*
|
||||
* $Id: main.c,v 1.5 1997/12/13 03:13:47 sef Exp $
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
#include <signal.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/pioctl.h>
|
||||
@ -65,14 +66,15 @@ extern void i386_linux_syscall_exit(int, int);
|
||||
int pid = 0;
|
||||
int nosigs = 0;
|
||||
FILE *outfile = stderr;
|
||||
char *prog;
|
||||
int Procfd;
|
||||
char progtype[50]; /* OS and type of executable */
|
||||
|
||||
static inline void
|
||||
usage(void) {
|
||||
fprintf(stderr, "usage: %s [-o <file>] [-S] { [-p <pid> ] | "
|
||||
"[ <command> <args>] }\n", prog);
|
||||
usage(void)
|
||||
{
|
||||
fprintf(stderr, "%s\n%s\n",
|
||||
"usage: truss [-S] [-o file] -p pid",
|
||||
" truss [-S] [-o file] command [args]");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@ -116,18 +118,15 @@ set_etype() {
|
||||
return funcs;
|
||||
}
|
||||
|
||||
int
|
||||
main(int ac, char **av) {
|
||||
int mask;
|
||||
int c;
|
||||
int i;
|
||||
char **command;
|
||||
struct procfs_status pfs;
|
||||
char etype[25];
|
||||
struct ex_types *funcs;
|
||||
int fd;
|
||||
int in_exec = 0;
|
||||
|
||||
prog = av[0];
|
||||
char *fname = NULL;
|
||||
|
||||
while ((c = getopt(ac, av, "p:o:S")) != EOF) {
|
||||
switch (c) {
|
||||
@ -135,10 +134,7 @@ main(int ac, char **av) {
|
||||
pid = atoi(optarg);
|
||||
break;
|
||||
case 'o': /* Specified output file */
|
||||
if ((outfile = fopen(optarg, "w")) == NULL) {
|
||||
fprintf (stderr, "%s: cannot open %s\n", av[0], optarg);
|
||||
exit(1);
|
||||
}
|
||||
fname = optarg;
|
||||
break;
|
||||
case 'S': /* Don't trace signals */
|
||||
nosigs = 1;
|
||||
@ -152,6 +148,11 @@ main(int ac, char **av) {
|
||||
if ((pid == 0 && ac == 0) || (pid != 0 && ac != 0))
|
||||
usage();
|
||||
|
||||
if (fname != NULL) { /* Use output file */
|
||||
if ((outfile = fopen(fname, "w")) == NULL)
|
||||
errx(1, "cannot open %s", fname);
|
||||
}
|
||||
|
||||
/*
|
||||
* If truss starts the process itself, it will ignore some signals --
|
||||
* they should be passed off to the process, which may or may not
|
||||
@ -193,7 +194,7 @@ main(int ac, char **av) {
|
||||
int val = 0;
|
||||
|
||||
if (ioctl(Procfd, PIOCWAIT, &pfs) == -1)
|
||||
perror("PIOCWAIT top of loop");
|
||||
warn("PIOCWAIT top of loop");
|
||||
else {
|
||||
switch(i = pfs.why) {
|
||||
case S_SCE:
|
||||
@ -229,7 +230,7 @@ main(int ac, char **av) {
|
||||
}
|
||||
}
|
||||
if (ioctl(Procfd, PIOCCONT, val) == -1)
|
||||
perror("PIOCCONT");
|
||||
warn("PIOCCONT");
|
||||
} while (pfs.why != S_EXIT);
|
||||
return 0;
|
||||
}
|
||||
|
@ -27,25 +27,26 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* Various setup functions for truss. Not the cleanest-written code,
|
||||
* I'm afraid.
|
||||
*/
|
||||
/*
|
||||
* $Id: setup.c,v 1.5 1997/12/13 03:13:47 sef Exp $
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <err.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/pioctl.h>
|
||||
#include <sys/types.h>
|
||||
@ -66,7 +67,6 @@ setup_and_wait(char *command[]) {
|
||||
char buf[32];
|
||||
int fd;
|
||||
int pid;
|
||||
extern char *prog;
|
||||
int flags;
|
||||
|
||||
pid = vfork();
|
||||
@ -88,7 +88,7 @@ setup_and_wait(char *command[]) {
|
||||
* we want.
|
||||
*/
|
||||
if (ioctl(fd, PIOCSFL, flags) == -1)
|
||||
perror("cannot set PF_LINGER");
|
||||
warn("cannot set PF_LINGER");
|
||||
execvp(command[0], command);
|
||||
mask = ~0;
|
||||
ioctl(fd, PIOCBIC, ~0);
|
||||
@ -151,7 +151,7 @@ start_tracing(int pid, int flags) {
|
||||
*/
|
||||
|
||||
if (ioctl(fd, PIOCSFL, 0) == -1)
|
||||
perror("cannot clear PF_LINGER");
|
||||
warn("cannot clear PF_LINGER");
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
@ -27,17 +27,19 @@
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef lint
|
||||
static const char rcsid[] =
|
||||
"$Id$";
|
||||
#endif /* not lint */
|
||||
|
||||
/*
|
||||
* This file has routines used to print out system calls and their
|
||||
* arguments.
|
||||
*/
|
||||
/*
|
||||
* $Id: syscalls.c,v 1.2 1997/12/06 06:51:14 sef Exp $
|
||||
*/
|
||||
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -75,9 +77,11 @@ struct syscall syscalls[] = {
|
||||
{ { Int, 0}, { Ioctl, 1 }, { Hex, 2 }}},
|
||||
{ "break", 1, 1, { { Hex, 0 }}},
|
||||
{ "exit", 0, 1, { { Hex, 0 }}},
|
||||
{ 0, 0, 0, { 0, 0 } },
|
||||
{ 0, 0, 0, { { 0, 0 }}},
|
||||
};
|
||||
|
||||
char * ioctlname __P((int));
|
||||
|
||||
/*
|
||||
* If/when the list gets big, it might be desirable to do it
|
||||
* as a hash table or binary search.
|
||||
@ -104,14 +108,12 @@ get_syscall(const char *name) {
|
||||
|
||||
char *
|
||||
get_string(int procfd, void *offset, int max) {
|
||||
char *buf, *tmp;
|
||||
char *buf;
|
||||
int size, len, c;
|
||||
FILE *p;
|
||||
|
||||
if ((p = fdopen(procfd, "r")) == NULL) {
|
||||
perror("fdopen");
|
||||
exit(1);
|
||||
}
|
||||
if ((p = fdopen(procfd, "r")) == NULL)
|
||||
err(1, "fdopen");
|
||||
buf = malloc( size = (max ? max : 64 ) );
|
||||
len = 0;
|
||||
fseek(p, (long)offset, SEEK_SET);
|
||||
@ -164,7 +166,7 @@ make_quad(unsigned long p1, unsigned long p2) {
|
||||
|
||||
char *
|
||||
print_arg(int fd, struct syscall_args *sc, unsigned long *args) {
|
||||
char *tmp;
|
||||
char *tmp = NULL;
|
||||
switch (sc->type & ARG_MASK) {
|
||||
case Hex:
|
||||
tmp = malloc(12);
|
||||
|
@ -2,35 +2,41 @@
|
||||
.Dt TRUSS 1
|
||||
.Os FreeBSD
|
||||
.Sh NAME
|
||||
.Nm \&truss
|
||||
.Nm truss
|
||||
.Nd trace system calls
|
||||
.Sh Synopsis
|
||||
.Nm \&truss
|
||||
.Sh SYNOPSIS
|
||||
.Nm truss
|
||||
.Op Fl S
|
||||
.Op Fl o Ar file
|
||||
.Fl p Ar pid
|
||||
.Nm truss
|
||||
.Op Fl S
|
||||
.Op Fl p Ar pid
|
||||
.Op Fl o Ar file
|
||||
command
|
||||
.Op args
|
||||
.Sh DESCRIPTION
|
||||
.Nm \&truss
|
||||
.Nm Truss
|
||||
traces the system calls called by the specified process or program.
|
||||
Output is to the specified output file, or standard error by default.
|
||||
It does this by stopping and restarting the process being monitored via
|
||||
.Xr procfs 5 .
|
||||
.Pp
|
||||
The options are as follows:
|
||||
.Bl -tag -width command
|
||||
.Bl -tag -width indent
|
||||
.It Fl S
|
||||
Do not display information about signals received by the process.
|
||||
(Normally,
|
||||
.Nm \&truss
|
||||
.Nm
|
||||
displays signal as well as system call events.)
|
||||
.It Fl p
|
||||
.It Fl o Ar file
|
||||
Print the output to the specified
|
||||
.Ar file
|
||||
instead of standard error.
|
||||
.It Fl p Ar pid
|
||||
Follow the process specified by
|
||||
.Ar pid
|
||||
instead of a new command.
|
||||
.It Fl o
|
||||
Print the output to the specified file instead of standard error.
|
||||
.It Ar command
|
||||
.It Ar command Op args
|
||||
Execute
|
||||
.Ar command
|
||||
and trace the system calls of it.
|
||||
@ -47,11 +53,15 @@ options are mutually exclusive.)
|
||||
# Follow an already-running process
|
||||
.Dl $ truss -p 1
|
||||
.Sh SEE ALSO
|
||||
.Xr procfs 5 ,
|
||||
.Xr kdump 1 ,
|
||||
.Xr ktrace 1 ,
|
||||
.Xr kdump 1
|
||||
.Xr procfs 5
|
||||
.Sh HISTORY
|
||||
The
|
||||
.Nm truss
|
||||
command was written by Sean Eric Fagan for FreeBSD; it was modeled after
|
||||
.Nm
|
||||
command was written by
|
||||
.An Sean Eric Fagan
|
||||
for
|
||||
.Bx Free Ns ;
|
||||
it was modeled after
|
||||
similar commands available for System V Release 4 and SunOS.
|
||||
|
Loading…
Reference in New Issue
Block a user