Deleted Added
full compact
main.c (101282) main.c (101283)
1/*
2 * Copryight 1997 Sean Eric Fagan
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 17 unchanged lines hidden (view full) ---

26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#ifndef lint
33static const char rcsid[] =
1/*
2 * Copryight 1997 Sean Eric Fagan
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.

--- 17 unchanged lines hidden (view full) ---

26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#ifndef lint
33static const char rcsid[] =
34 "$FreeBSD: head/usr.bin/truss/main.c 101282 2002-08-04 00:46:48Z mdodd $";
34 "$FreeBSD: head/usr.bin/truss/main.c 101283 2002-08-04 01:02:52Z mdodd $";
35#endif /* not lint */
36
37/*
38 * The main module for truss. Suprisingly simple, but, then, the other
39 * files handle the bulk of the work. And, of course, the kernel has to
40 * do a lot of the work :).
41 */
42

--- 19 unchanged lines hidden (view full) ---

62 */
63
64int Procfd;
65
66static __inline void
67usage(void)
68{
69 fprintf(stderr, "%s\n%s\n",
35#endif /* not lint */
36
37/*
38 * The main module for truss. Suprisingly simple, but, then, the other
39 * files handle the bulk of the work. And, of course, the kernel has to
40 * do a lot of the work :).
41 */
42

--- 19 unchanged lines hidden (view full) ---

62 */
63
64int Procfd;
65
66static __inline void
67usage(void)
68{
69 fprintf(stderr, "%s\n%s\n",
70 "usage: truss [-S] [-o file] -p pid",
71 " truss [-S] [-o file] command [args]");
70 "usage: truss [-fS] [-o file] -p pid",
71 " truss [-fS] [-o file] command [args]");
72 exit(1);
73}
74
75/*
76 * WARNING! "FreeBSD a.out" must be first, or set_etype will not
77 * work correctly.
78 */
79struct ex_types {

--- 60 unchanged lines hidden (view full) ---

140
141 /* Initialize the trussinfo struct */
142 trussinfo = (struct trussinfo *)malloc(sizeof(struct trussinfo));
143 if (trussinfo == NULL)
144 errx(1, "malloc() failed");
145 bzero(trussinfo, sizeof(struct trussinfo));
146 trussinfo->outfile = stderr;
147
72 exit(1);
73}
74
75/*
76 * WARNING! "FreeBSD a.out" must be first, or set_etype will not
77 * work correctly.
78 */
79struct ex_types {

--- 60 unchanged lines hidden (view full) ---

140
141 /* Initialize the trussinfo struct */
142 trussinfo = (struct trussinfo *)malloc(sizeof(struct trussinfo));
143 if (trussinfo == NULL)
144 errx(1, "malloc() failed");
145 bzero(trussinfo, sizeof(struct trussinfo));
146 trussinfo->outfile = stderr;
147
148 while ((c = getopt(ac, av, "p:o:S")) != -1) {
148 while ((c = getopt(ac, av, "p:o:fS")) != -1) {
149 switch (c) {
150 case 'p': /* specified pid */
151 trussinfo->pid = atoi(optarg);
152 break;
149 switch (c) {
150 case 'p': /* specified pid */
151 trussinfo->pid = atoi(optarg);
152 break;
153 case 'f': /* Follow fork()'s */
154 trussinfo->flags |= FOLLOWFORKS;
155 break;
153 case 'o': /* Specified output file */
154 fname = optarg;
155 break;
156 case 'S': /* Don't trace signals */
157 trussinfo->flags |= NOSIGS;
158 break;
159 default:
160 usage();

--- 29 unchanged lines hidden (view full) ---

190 }
191
192
193 /*
194 * At this point, if we started the process, it is stopped waiting to
195 * be woken up, either in exit() or in execve().
196 */
197
156 case 'o': /* Specified output file */
157 fname = optarg;
158 break;
159 case 'S': /* Don't trace signals */
160 trussinfo->flags |= NOSIGS;
161 break;
162 default:
163 usage();

--- 29 unchanged lines hidden (view full) ---

193 }
194
195
196 /*
197 * At this point, if we started the process, it is stopped waiting to
198 * be woken up, either in exit() or in execve().
199 */
200
201START_TRACE:
198 Procfd = start_tracing(
199 trussinfo->pid, S_EXEC | S_SCE | S_SCX | S_CORE | S_EXIT |
202 Procfd = start_tracing(
203 trussinfo->pid, S_EXEC | S_SCE | S_SCX | S_CORE | S_EXIT |
200 ((trussinfo->flags & NOSIGS) ? 0 : S_SIG));
204 ((trussinfo->flags & NOSIGS) ? 0 : S_SIG),
205 ((trussinfo->flags & FOLLOWFORKS) ? PF_FORK : 0));
201 if (Procfd == -1)
202 return 0;
203
204 pfs.why = 0;
205
206 funcs = set_etype(trussinfo);
207 /*
208 * At this point, it's a simple loop, waiting for the process to

--- 18 unchanged lines hidden (view full) ---

227 * conveniently, ensures that the first message printed out
228 * isn't the return-from-syscall used to create the process.
229 */
230
231 if (in_exec) {
232 in_exec = 0;
233 break;
234 }
206 if (Procfd == -1)
207 return 0;
208
209 pfs.why = 0;
210
211 funcs = set_etype(trussinfo);
212 /*
213 * At this point, it's a simple loop, waiting for the process to

--- 18 unchanged lines hidden (view full) ---

232 * conveniently, ensures that the first message printed out
233 * isn't the return-from-syscall used to create the process.
234 */
235
236 if (in_exec) {
237 in_exec = 0;
238 break;
239 }
240
241 if (trussinfo->in_fork && (trussinfo->flags & FOLLOWFORKS)) {
242 int childpid;
243
244 trussinfo->in_fork = 0;
245 childpid = funcs->exit_syscall(trussinfo, pfs.val);
246
247 /*
248 * Fork a new copy of ourself to trace the child of the
249 * original traced process.
250 */
251 if (fork() == 0) {
252 trussinfo->pid = childpid;
253 goto START_TRACE;
254 }
255 break;
256 }
235 funcs->exit_syscall(trussinfo, pfs.val);
236 break;
237 case S_SIG:
238 fprintf(trussinfo->outfile, "SIGNAL %lu\n", pfs.val);
239 sigexit = pfs.val;
240 break;
241 case S_EXIT:
242 fprintf (trussinfo->outfile, "process exit, rval = %lu\n", pfs.val);

--- 26 unchanged lines hidden ---
257 funcs->exit_syscall(trussinfo, pfs.val);
258 break;
259 case S_SIG:
260 fprintf(trussinfo->outfile, "SIGNAL %lu\n", pfs.val);
261 sigexit = pfs.val;
262 break;
263 case S_EXIT:
264 fprintf (trussinfo->outfile, "process exit, rval = %lu\n", pfs.val);

--- 26 unchanged lines hidden ---