View | Details | Raw Unified | Return to bug 41310
Collapse All | Expand All

(-)truss/alpha-fbsd.c (-4 / +4 lines)
Lines 115-121 Link Here
115
115
116
void
116
void
117
alpha_syscall_entry(int pid, int nargs) {
117
alpha_syscall_entry(int pid, int nargs) {
118
  char buf[32];
118
  char buf[MAXPATHLEN];
119
  struct reg regs = { { 0 } };
119
  struct reg regs = { { 0 } };
120
  int syscall;
120
  int syscall;
121
  int i;
121
  int i;
Lines 124-130 Link Here
124
  int indir = 0;	/* indirect system call */
124
  int indir = 0;	/* indirect system call */
125
125
126
  if (fd == -1 || pid != cpid) {
126
  if (fd == -1 || pid != cpid) {
127
    sprintf(buf, "/proc/%d/regs", pid);
127
    snprintf(buf, sizeof buf, "%s/%d/regs", procpath, pid);
128
    fd = open(buf, O_RDWR);
128
    fd = open(buf, O_RDWR);
129
    if (fd == -1) {
129
    if (fd == -1) {
130
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
130
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
Lines 262-268 Link Here
262
262
263
void
263
void
264
alpha_syscall_exit(int pid, int syscall) {
264
alpha_syscall_exit(int pid, int syscall) {
265
  char buf[32];
265
  char buf[MAXPATHLEN];
266
  struct reg regs;
266
  struct reg regs;
267
  int retval;
267
  int retval;
268
  int i;
268
  int i;
Lines 270-276 Link Here
270
  struct syscall *sc;
270
  struct syscall *sc;
271
271
272
  if (fd == -1 || pid != cpid) {
272
  if (fd == -1 || pid != cpid) {
273
    sprintf(buf, "/proc/%d/regs", pid);
273
    snprintf(buf, MAXPATHLEN, "%s/%d/regs", procpath, pid);
274
    fd = open(buf, O_RDONLY);
274
    fd = open(buf, O_RDONLY);
275
    if (fd == -1) {
275
    if (fd == -1) {
276
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
276
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
(-)truss/i386-fbsd.c (-4 / +7 lines)
Lines 44-49 Link Here
44
44
45
#include <sys/types.h>
45
#include <sys/types.h>
46
#include <sys/ioctl.h>
46
#include <sys/ioctl.h>
47
#include <sys/param.h>
47
#include <sys/pioctl.h>
48
#include <sys/pioctl.h>
48
#include <sys/syscall.h>
49
#include <sys/syscall.h>
49
50
Lines 67-72 Link Here
67
extern FILE *outfile;
68
extern FILE *outfile;
68
#include "syscalls.h"
69
#include "syscalls.h"
69
70
71
extern char *procpath;
72
70
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
73
static int nsyscalls = sizeof(syscallnames) / sizeof(syscallnames[0]);
71
74
72
/*
75
/*
Lines 112-118 Link Here
112
115
113
void
116
void
114
i386_syscall_entry(int pid, int nargs) {
117
i386_syscall_entry(int pid, int nargs) {
115
  char buf[32];
118
  char buf[MAXPATHLEN];
116
  struct reg regs = { 0 };
119
  struct reg regs = { 0 };
117
  int syscall;
120
  int syscall;
118
  int i;
121
  int i;
Lines 120-126 Link Here
120
  struct syscall *sc;
123
  struct syscall *sc;
121
124
122
  if (fd == -1 || pid != cpid) {
125
  if (fd == -1 || pid != cpid) {
123
    sprintf(buf, "/proc/%d/regs", pid);
126
    snprintf(buf, sizeof buf, "%s/%d/regs", procpath, pid);
124
    fd = open(buf, O_RDWR);
127
    fd = open(buf, O_RDWR);
125
    if (fd == -1) {
128
    if (fd == -1) {
126
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
129
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
Lines 240-246 Link Here
240
243
241
void
244
void
242
i386_syscall_exit(int pid, int syscall) {
245
i386_syscall_exit(int pid, int syscall) {
243
  char buf[32];
246
  char buf[MAXPATHLEN];
244
  struct reg regs;
247
  struct reg regs;
245
  int retval;
248
  int retval;
246
  int i;
249
  int i;
Lines 248-254 Link Here
248
  struct syscall *sc;
251
  struct syscall *sc;
249
252
250
  if (fd == -1 || pid != cpid) {
253
  if (fd == -1 || pid != cpid) {
251
    sprintf(buf, "/proc/%d/regs", pid);
254
    snprintf(buf, sizeof buf, "%s/%d/regs", procpath, pid);
252
    fd = open(buf, O_RDONLY);
255
    fd = open(buf, O_RDONLY);
253
    if (fd == -1) {
256
    if (fd == -1) {
254
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
257
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
(-)truss/i386-linux.c (-4 / +7 lines)
Lines 42-47 Link Here
42
42
43
#include <sys/types.h>
43
#include <sys/types.h>
44
#include <sys/ioctl.h>
44
#include <sys/ioctl.h>
45
#include <sys/param.h>
45
#include <sys/pioctl.h>
46
#include <sys/pioctl.h>
46
47
47
#include <machine/reg.h>
48
#include <machine/reg.h>
Lines 65-70 Link Here
65
extern FILE *outfile;
66
extern FILE *outfile;
66
#include "linux_syscalls.h"
67
#include "linux_syscalls.h"
67
68
69
extern char *procpath;
70
68
static int nsyscalls =
71
static int nsyscalls =
69
	sizeof(linux_syscallnames) / sizeof(linux_syscallnames[0]);
72
	sizeof(linux_syscallnames) / sizeof(linux_syscallnames[0]);
70
73
Lines 92-105 Link Here
92
95
93
void
96
void
94
i386_linux_syscall_entry(int pid, int nargs) {
97
i386_linux_syscall_entry(int pid, int nargs) {
95
  char buf[32];
98
  char buf[MAXPATHLEN];
96
  struct reg regs = { 0 };
99
  struct reg regs = { 0 };
97
  int syscall;
100
  int syscall;
98
  int i;
101
  int i;
99
  struct syscall *sc;
102
  struct syscall *sc;
100
103
101
  if (fd == -1 || pid != cpid) {
104
  if (fd == -1 || pid != cpid) {
102
    sprintf(buf, "/proc/%d/regs", pid);
105
    snprintf(buf, sizeof buf, "%s/%d/regs", procpath, pid);
103
    fd = open(buf, O_RDWR);
106
    fd = open(buf, O_RDWR);
104
    if (fd == -1) {
107
    if (fd == -1) {
105
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
108
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
Lines 198-204 Link Here
198
201
199
void
202
void
200
i386_linux_syscall_exit(int pid, int syscall) {
203
i386_linux_syscall_exit(int pid, int syscall) {
201
  char buf[32];
204
  char buf[MAXPATHLEN];
202
  struct reg regs;
205
  struct reg regs;
203
  int retval;
206
  int retval;
204
  int i;
207
  int i;
Lines 206-212 Link Here
206
  struct syscall *sc;
209
  struct syscall *sc;
207
210
208
  if (fd == -1 || pid != cpid) {
211
  if (fd == -1 || pid != cpid) {
209
    sprintf(buf, "/proc/%d/regs", pid);
212
    snprintf(buf, sizeof buf, "%s/%d/regs", procpath, pid);
210
    fd = open(buf, O_RDONLY);
213
    fd = open(buf, O_RDONLY);
211
    if (fd == -1) {
214
    if (fd == -1) {
212
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
215
      fprintf(outfile, "-- CANNOT READ REGISTERS --\n");
(-)truss/main.c (-3 / +12 lines)
Lines 40-45 Link Here
40
 * do a lot of the work :).
40
 * do a lot of the work :).
41
 */
41
 */
42
42
43
#define	PROCPATH	"/proc"
44
43
#include <sys/param.h>
45
#include <sys/param.h>
44
#include <sys/ioctl.h>
46
#include <sys/ioctl.h>
45
#include <sys/pioctl.h>
47
#include <sys/pioctl.h>
Lines 64-69 Link Here
64
int nosigs = 0;
66
int nosigs = 0;
65
FILE *outfile;
67
FILE *outfile;
66
int Procfd;
68
int Procfd;
69
char *procpath = NULL;
67
70
68
static inline void
71
static inline void
69
usage(void)
72
usage(void)
Lines 103-113 Link Here
103
static struct ex_types *
106
static struct ex_types *
104
set_etype(void) {
107
set_etype(void) {
105
  struct ex_types *funcs;
108
  struct ex_types *funcs;
106
  char etype[24];
109
  char etype[MAXPATHLEN];
107
  char progt[32];
110
  char progt[32];
108
  int fd;
111
  int fd;
109
112
110
  sprintf(etype, "/proc/%d/etype", pid);
113
  snprintf(etype, sizeof etype, "%s/%d/etype", procpath, pid);
111
  if ((fd = open(etype, O_RDONLY)) == -1) {
114
  if ((fd = open(etype, O_RDONLY)) == -1) {
112
    strcpy(progt, "FreeBSD a.out");
115
    strcpy(progt, "FreeBSD a.out");
113
  } else {
116
  } else {
Lines 140-146 Link Here
140
  int sigexit = 0;
143
  int sigexit = 0;
141
144
142
  outfile = stderr;
145
  outfile = stderr;
143
  while ((c = getopt(ac, av, "p:o:S")) != -1) {
146
  while ((c = getopt(ac, av, "p:o:d:S")) != -1) {
144
    switch (c) {
147
    switch (c) {
145
    case 'p':	/* specified pid */
148
    case 'p':	/* specified pid */
146
      pid = atoi(optarg);
149
      pid = atoi(optarg);
Lines 148-153 Link Here
148
    case 'o':	/* Specified output file */
151
    case 'o':	/* Specified output file */
149
      fname = optarg;
152
      fname = optarg;
150
      break;
153
      break;
154
    case 'd':	/* Specified procfs directory */
155
      procpath = optarg;
156
      break;
151
    case 'S':	/* Don't trace signals */ 
157
    case 'S':	/* Don't trace signals */ 
152
      nosigs = 1;
158
      nosigs = 1;
153
      break;
159
      break;
Lines 164-169 Link Here
164
    if ((outfile = fopen(fname, "w")) == NULL)
170
    if ((outfile = fopen(fname, "w")) == NULL)
165
      errx(1, "cannot open %s", fname);
171
      errx(1, "cannot open %s", fname);
166
  }
172
  }
173
174
  if (procpath == NULL)
175
    procpath = strdup(PROCPATH);
167
176
168
  /*
177
  /*
169
   * If truss starts the process itself, it will ignore some signals --
178
   * If truss starts the process itself, it will ignore some signals --
(-)truss/setup.c (-6 / +9 lines)
Lines 55-60 Link Here
55
55
56
#include "extern.h"
56
#include "extern.h"
57
57
58
extern char *procpath;
59
58
static int evflags = 0;
60
static int evflags = 0;
59
61
60
/*
62
/*
Lines 67-73 Link Here
67
int
69
int
68
setup_and_wait(char *command[]) {
70
setup_and_wait(char *command[]) {
69
  struct procfs_status pfs;
71
  struct procfs_status pfs;
70
  char buf[32];
72
  char buf[MAXPATHLEN];
71
  int fd;
73
  int fd;
72
  int pid;
74
  int pid;
73
  int flags;
75
  int flags;
Lines 78-86 Link Here
78
  }
80
  }
79
  if (pid == 0) {	/* Child */
81
  if (pid == 0) {	/* Child */
80
    int mask = S_EXEC | S_EXIT;
82
    int mask = S_EXEC | S_EXIT;
81
    fd = open("/proc/curproc/mem", O_WRONLY);
83
    snprintf(buf, sizeof buf, "%s/curproc/mem", procpath);
84
    fd = open(buf, O_WRONLY);
82
    if (fd == -1)
85
    if (fd == -1)
83
      err(2, "cannot open /proc/curproc/mem");
86
      err(2, "cannot open %s", buf);
84
    fcntl(fd, F_SETFD, 1);
87
    fcntl(fd, F_SETFD, 1);
85
    if (ioctl(fd, PIOCBIS, mask) == -1)
88
    if (ioctl(fd, PIOCBIS, mask) == -1)
86
      err(3, "PIOCBIS");
89
      err(3, "PIOCBIS");
Lines 107-113 Link Here
107
    exit(1);
110
    exit(1);
108
  }
111
  }
109
112
110
  sprintf(buf, "/proc/%d/mem", pid);
113
  snprintf(buf, MAXPATHLEN, "%s/%d/mem", procpath, pid);
111
  if ((fd = open(buf, O_RDWR)) == -1)
114
  if ((fd = open(buf, O_RDWR)) == -1)
112
    err(5, "cannot open %s", buf);
115
    err(5, "cannot open %s", buf);
113
  if (ioctl(fd, PIOCWAIT, &pfs) == -1)
116
  if (ioctl(fd, PIOCWAIT, &pfs) == -1)
Lines 131-139 Link Here
131
int
134
int
132
start_tracing(int pid, int flags) {
135
start_tracing(int pid, int flags) {
133
  int fd;
136
  int fd;
134
  char buf[32];
137
  char buf[MAXPATHLEN];
135
  struct procfs_status tmp;
138
  struct procfs_status tmp;
136
  sprintf(buf, "/proc/%d/mem", pid);
139
  snprintf(buf, sizeof buf, "%s/%d/mem", procpath, pid);
137
140
138
  fd = open(buf, O_RDWR);
141
  fd = open(buf, O_RDWR);
139
  if (fd == -1) {
142
  if (fd == -1) {
(-)truss/truss.1 (+6 lines)
Lines 10-19 Link Here
10
.Nm
10
.Nm
11
.Op Fl S
11
.Op Fl S
12
.Op Fl o Ar file
12
.Op Fl o Ar file
13
.Op Fl d Ar path
13
.Fl p Ar pid
14
.Fl p Ar pid
14
.Nm
15
.Nm
15
.Op Fl S
16
.Op Fl S
16
.Op Fl o Ar file
17
.Op Fl o Ar file
18
.Op Fl d Ar path
17
command
19
command
18
.Op args
20
.Op args
19
.Sh DESCRIPTION
21
.Sh DESCRIPTION
Lines 35-40 Link Here
35
Print the output to the specified
37
Print the output to the specified
36
.Ar file
38
.Ar file
37
instead of standard error.
39
instead of standard error.
40
.It Fl d Ar path
41
Use specified
42
.Ar path
43
for procfs instead of ,,/proc''.
38
.It Fl p Ar pid
44
.It Fl p Ar pid
39
Follow the process specified by
45
Follow the process specified by
40
.Ar pid
46
.Ar pid

Return to bug 41310