blob: 272870b23cc625e8bd9d278d5125c961cfc9a49e [file] [log] [blame]
Juan Cespedesac3db291998-04-25 14:31:58 +02001#if HAVE_CONFIG_H
2#include "config.h"
3#endif
4
Juan Cespedes5e01f651998-03-08 22:31:44 +01005#include <string.h>
6#include <stdlib.h>
7#include <unistd.h>
Juan Cespedes1b9cfd61999-08-30 19:34:50 +02008#include <fcntl.h>
Juan Cespedes5e01f651998-03-08 22:31:44 +01009#include <errno.h>
10#include <limits.h>
11
Juan Cespedesac3db291998-04-25 14:31:58 +020012#if HAVE_GETOPT_H
13#include <getopt.h>
14#endif
15
Juan Cespedes5e01f651998-03-08 22:31:44 +010016#include "ltrace.h"
17#include "options.h"
18#include "defs.h"
19
Steve Fink58c73a72006-07-17 23:18:35 +020020#ifndef SYSCONFDIR
21#define SYSCONFDIR "/etc"
22#endif
23
24#define SYSTEM_CONFIG_FILE SYSCONFDIR "/trace.conf"
25#define USER_CONFIG_FILE "~/.ltrace.conf"
26
Juan Cespedes1cd999a2001-07-03 00:46:04 +020027#define MAX_LIBRARY 30
28char *library[MAX_LIBRARY];
29int library_num = 0;
Juan Cespedesac3db291998-04-25 14:31:58 +020030static char *progname; /* Program name (`ltrace') */
Ian Wienand2d45b1a2006-02-20 22:48:07 +010031FILE *output;
Juan Cespedes5e01f651998-03-08 22:31:44 +010032int opt_a = DEFAULT_ACOLUMN; /* default alignment column for results */
Steve Fink1150bc42006-08-07 06:04:43 +020033int opt_A = DEFAULT_ARRAYLEN; /* default maximum # array elements to print */
Juan Cespedesd65efa32003-02-03 00:22:30 +010034int opt_c = 0; /* Count time, calls, and report a summary on program exit */
Juan Cespedes5e01f651998-03-08 22:31:44 +010035int opt_d = 0; /* debug */
36int opt_i = 0; /* instruction pointer */
37int opt_s = DEFAULT_STRLEN; /* default maximum # of bytes printed in strings */
38int opt_S = 0; /* display syscalls */
39int opt_L = 1; /* display library calls */
40int opt_f = 0; /* trace child processes as they are created */
Ian Wienand2d45b1a2006-02-20 22:48:07 +010041char *opt_u = NULL; /* username to run command as */
Juan Cespedesf666d191998-09-20 23:04:34 +020042int opt_r = 0; /* print relative timestamp */
Juan Cespedes5e0acdb1998-04-04 08:34:07 +020043int opt_t = 0; /* print absolute timestamp */
Juan Cespedesd914a202004-11-10 00:15:33 +010044#ifdef USE_DEMANGLE
Juan Cespedesac3db291998-04-25 14:31:58 +020045int opt_C = 0; /* Demangle low-level symbol names into user-level names */
46#endif
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +020047int opt_n = 0; /* indent trace output according to program flow */
Juan Cespedesd65efa32003-02-03 00:22:30 +010048int opt_T = 0; /* show the time spent inside each call */
Juan Cespedes5e01f651998-03-08 22:31:44 +010049
50/* List of pids given to option -p: */
Ian Wienand2d45b1a2006-02-20 22:48:07 +010051struct opt_p_t *opt_p = NULL; /* attach to process with a given pid */
Juan Cespedes5e01f651998-03-08 22:31:44 +010052
Juan Cespedesac3db291998-04-25 14:31:58 +020053/* List of function names given to option -e: */
Ian Wienand2d45b1a2006-02-20 22:48:07 +010054struct opt_e_t *opt_e = NULL;
55int opt_e_enable = 1;
Juan Cespedesac3db291998-04-25 14:31:58 +020056
Ian Wienand9a2ad352006-02-20 22:44:45 +010057/* List of global function names given to -x: */
Paul Gilliam24e643a2006-03-13 18:43:13 +010058struct opt_x_t *opt_x = NULL;
Ian Wienand9a2ad352006-02-20 22:44:45 +010059
Steve Fink58c73a72006-07-17 23:18:35 +020060/* List of filenames give to option -F: */
61struct opt_F_t *opt_F = NULL; /* alternate configuration file(s) */
62
Paul Gilliambe320772006-04-24 22:06:23 +020063#ifdef PLT_REINITALISATION_BP
Ian Wienand9a2ad352006-02-20 22:44:45 +010064/* Set a break on the routine named here in order to re-initialize breakpoints
65 after all the PLTs have been initialzed */
Paul Gilliambe320772006-04-24 22:06:23 +020066char *PLTs_initialized_by_here = PLT_REINITALISATION_BP;
67#endif
Ian Wienand9a2ad352006-02-20 22:44:45 +010068
Ian Wienand2d45b1a2006-02-20 22:48:07 +010069static void usage(void)
70{
Juan Cespedesac3db291998-04-25 14:31:58 +020071#if !(HAVE_GETOPT || HAVE_GETOPT_LONG)
72 fprintf(stdout, "Usage: %s [command [arg ...]]\n"
Ian Wienand2d45b1a2006-02-20 22:48:07 +010073 "Trace library calls of a given program.\n\n", progname);
Juan Cespedesac3db291998-04-25 14:31:58 +020074#else
75 fprintf(stdout, "Usage: %s [option ...] [command [arg ...]]\n"
Ian Wienand2d45b1a2006-02-20 22:48:07 +010076 "Trace library calls of a given program.\n\n"
Juan Cespedesac3db291998-04-25 14:31:58 +020077# if HAVE_GETOPT_LONG
Ian Wienand2d45b1a2006-02-20 22:48:07 +010078 " -a, --align=COLUMN align return values in a secific column.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +020079# else
Ian Wienand2d45b1a2006-02-20 22:48:07 +010080 " -a COLUMN align return values in a secific column.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +020081# endif
Steve Fink1150bc42006-08-07 06:04:43 +020082 " -A ARRAYLEN maximum number of array elements to print.\n"
Ian Wienand2d45b1a2006-02-20 22:48:07 +010083 " -c count time and calls, and report a summary on exit.\n"
Juan Cespedesd914a202004-11-10 00:15:33 +010084# ifdef USE_DEMANGLE
Juan Cespedesac3db291998-04-25 14:31:58 +020085# if HAVE_GETOPT_LONG
Ian Wienand2d45b1a2006-02-20 22:48:07 +010086 " -C, --demangle decode low-level symbol names into user-level names.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +020087# else
Ian Wienand2d45b1a2006-02-20 22:48:07 +010088 " -C decode low-level symbol names into user-level names.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +020089# endif
90# endif
91# if HAVE_GETOPT_LONG
Ian Wienand2d45b1a2006-02-20 22:48:07 +010092 " -d, --debug print debugging info.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +020093# else
Ian Wienand2d45b1a2006-02-20 22:48:07 +010094 " -d print debugging info.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +020095# endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +010096 " -e expr modify which events to trace.\n"
97 " -f follow forks.\n"
Juan Cespedesd65efa32003-02-03 00:22:30 +010098# if HAVE_GETOPT_LONG
Steve Fink58c73a72006-07-17 23:18:35 +020099 " -F, --config=FILE load alternate configuration file\n"
100# else
101 " -F FILE load alternate configuration file\n"
102# endif
103 " (can be repeated).\n"
104# if HAVE_GETOPT_LONG
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100105 " -h, --help display this help and exit.\n"
Juan Cespedesd65efa32003-02-03 00:22:30 +0100106# else
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100107 " -h display this help and exit.\n"
Juan Cespedesd65efa32003-02-03 00:22:30 +0100108# endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100109 " -i print instruction pointer at time of library call.\n"
Juan Cespedesd65efa32003-02-03 00:22:30 +0100110# if HAVE_GETOPT_LONG
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100111 " -l, --library=FILE print library calls from this library only.\n"
Juan Cespedesd65efa32003-02-03 00:22:30 +0100112# else
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100113 " -l FILE print library calls from this library only.\n"
Juan Cespedesd65efa32003-02-03 00:22:30 +0100114# endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100115 " -L do NOT display library calls.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +0200116# if HAVE_GETOPT_LONG
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100117 " -n, --indent=NR indent output by NR spaces for each call level nesting.\n"
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200118# else
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100119 " -n NR indent output by NR spaces for each call level nesting.\n"
Juan Cespedes5b3ffdf2001-07-02 00:52:45 +0200120# endif
121# if HAVE_GETOPT_LONG
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100122 " -o, --output=FILE write the trace output to that file.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +0200123# else
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100124 " -o FILE write the trace output to that file.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +0200125# endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100126 " -p PID attach to the process with the process ID pid.\n"
127 " -r print relative timestamps.\n"
128 " -s STRLEN specify the maximum string size to print.\n"
129 " -S display system calls.\n"
130 " -t, -tt, -ttt print absolute timestamps.\n"
131 " -T show the time spent inside each call.\n"
132 " -u USERNAME run command with the userid, groupid of username.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +0200133# if HAVE_GETOPT_LONG
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100134 " -V, --version output version information and exit.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +0200135# else
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100136 " -V output version information and exit.\n"
Juan Cespedesac3db291998-04-25 14:31:58 +0200137# endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100138 " -x NAME treat the global NAME like a library subroutine.\n"
Paul Gilliambe320772006-04-24 22:06:23 +0200139#ifdef PLT_REINITALISATION_BP
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100140 " -X NAME same as -x; and PLT's will be initialized by here.\n"
Paul Gilliambe320772006-04-24 22:06:23 +0200141#endif
142 "\nReport bugs to ltrace-devel@lists.alioth.debian.org\n",
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100143 progname);
Juan Cespedesac3db291998-04-25 14:31:58 +0200144#endif
Juan Cespedes5e01f651998-03-08 22:31:44 +0100145}
146
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100147static char *search_for_command(char *filename)
148{
Juan Cespedesf1bfe202002-03-27 00:22:23 +0100149 static char pathname[PATH_MAX];
Juan Cespedes5e01f651998-03-08 22:31:44 +0100150 char *path;
151 int m, n;
152
153 if (strchr(filename, '/')) {
154 return filename;
155 }
156 for (path = getenv("PATH"); path && *path; path += m) {
157 if (strchr(path, ':')) {
158 n = strchr(path, ':') - path;
159 m = n + 1;
160 } else {
161 m = n = strlen(path);
162 }
Juan Cespedesf1bfe202002-03-27 00:22:23 +0100163 if (n + strlen(filename) + 1 >= PATH_MAX) {
164 fprintf(stderr, "Error: filename too long\n");
165 exit(1);
166 }
167 strncpy(pathname, path, n);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100168 if (n && pathname[n - 1] != '/') {
169 pathname[n++] = '/';
170 }
171 strcpy(pathname + n, filename);
172 if (!access(pathname, X_OK)) {
173 return pathname;
174 }
175 }
176 return filename;
177}
178
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100179char **process_options(int argc, char **argv)
180{
Juan Cespedesac3db291998-04-25 14:31:58 +0200181 progname = argv[0];
Juan Cespedes5e01f651998-03-08 22:31:44 +0100182 output = stderr;
183
Juan Cespedesac3db291998-04-25 14:31:58 +0200184#if HAVE_GETOPT || HAVE_GETOPT_LONG
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100185 while (1) {
Juan Cespedesac3db291998-04-25 14:31:58 +0200186 int c;
187#if HAVE_GETOPT_LONG
188 int option_index = 0;
189 static struct option long_options[] = {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100190 {"align", 1, 0, 'a'},
Steve Fink58c73a72006-07-17 23:18:35 +0200191 {"config", 1, 0, 'F'},
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100192 {"debug", 0, 0, 'd'},
Juan Cespedesd914a202004-11-10 00:15:33 +0100193# ifdef USE_DEMANGLE
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100194 {"demangle", 0, 0, 'C'},
Juan Cespedes8e3e0821998-09-24 13:49:55 +0200195#endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100196 {"indent", 1, 0, 'n'},
197 {"help", 0, 0, 'h'},
198 {"library", 1, 0, 'l'},
199 {"output", 1, 0, 'o'},
200 {"version", 0, 0, 'V'},
201 {0, 0, 0, 0}
Juan Cespedesac3db291998-04-25 14:31:58 +0200202 };
Juan Cespedesd65efa32003-02-03 00:22:30 +0100203 c = getopt_long(argc, argv, "+cdfhiLrStTV"
Juan Cespedesd914a202004-11-10 00:15:33 +0100204# ifdef USE_DEMANGLE
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100205 "C"
Juan Cespedesac3db291998-04-25 14:31:58 +0200206# endif
Steve Fink1150bc42006-08-07 06:04:43 +0200207 "a:A:e:F:l:n:o:p:s:u:x:X:", long_options,
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100208 &option_index);
Juan Cespedesac3db291998-04-25 14:31:58 +0200209#else
Juan Cespedesd65efa32003-02-03 00:22:30 +0100210 c = getopt(argc, argv, "+cdfhiLrStTV"
Juan Cespedesd914a202004-11-10 00:15:33 +0100211# ifdef USE_DEMANGLE
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100212 "C"
Juan Cespedesac3db291998-04-25 14:31:58 +0200213# endif
Steve Fink1150bc42006-08-07 06:04:43 +0200214 "a:A:e:F:l:n:o:p:s:u:x:X:");
Juan Cespedesac3db291998-04-25 14:31:58 +0200215#endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100216 if (c == -1) {
Juan Cespedesac3db291998-04-25 14:31:58 +0200217 break;
Juan Cespedes5e01f651998-03-08 22:31:44 +0100218 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100219 switch (c) {
220 case 'a':
221 opt_a = atoi(optarg);
222 break;
Steve Fink1150bc42006-08-07 06:04:43 +0200223 case 'A':
224 opt_A = atoi(optarg);
225 break;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100226 case 'c':
227 opt_c++;
228 break;
Juan Cespedesd914a202004-11-10 00:15:33 +0100229#ifdef USE_DEMANGLE
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100230 case 'C':
231 opt_C++;
232 break;
Juan Cespedesac3db291998-04-25 14:31:58 +0200233#endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100234 case 'd':
235 opt_d++;
236 break;
237 case 'e':
238 {
239 char *str_e = strdup(optarg);
240 if (!str_e) {
241 perror("ltrace: strdup");
242 exit(1);
Ian Wienand9a2ad352006-02-20 22:44:45 +0100243 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100244 if (str_e[0] == '!') {
245 opt_e_enable = 0;
246 str_e++;
247 }
248 while (*str_e) {
249 struct opt_e_t *tmp;
250 char *str2 = strchr(str_e, ',');
251 if (str2) {
252 *str2 = '\0';
253 }
254 tmp = malloc(sizeof(struct opt_e_t));
Juan Cespedesd65efa32003-02-03 00:22:30 +0100255 if (!tmp) {
256 perror("ltrace: malloc");
257 exit(1);
258 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100259 tmp->name = str_e;
260 tmp->next = opt_e;
261 opt_e = tmp;
262 if (str2) {
263 str_e = str2 + 1;
264 } else {
265 break;
266 }
Ian Wienand9a2ad352006-02-20 22:44:45 +0100267 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100268 break;
269 }
270 case 'f':
271 opt_f = 1;
272 break;
Steve Fink58c73a72006-07-17 23:18:35 +0200273 case 'F':
274 {
275 struct opt_F_t *tmp = malloc(sizeof(struct opt_F_t));
276 if (!tmp) {
277 perror("ltrace: malloc");
278 exit(1);
279 }
280 tmp->filename = strdup(optarg);
281 tmp->next = opt_F;
282 opt_F = tmp;
283 break;
284 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100285 case 'h':
286 usage();
287 exit(0);
288 case 'i':
289 opt_i++;
290 break;
291 case 'l':
292 if (library_num == MAX_LIBRARY) {
293 fprintf(stderr,
294 "Too many libraries. Maximum is %i.\n",
295 MAX_LIBRARY);
296 exit(1);
297 }
298 library[library_num++] = optarg;
299 break;
300 case 'L':
301 opt_L = 0;
302 break;
303 case 'n':
304 opt_n = atoi(optarg);
305 break;
306 case 'o':
307 output = fopen(optarg, "w");
308 if (!output) {
309 fprintf(stderr,
310 "Can't open %s for output: %s\n",
311 optarg, strerror(errno));
312 exit(1);
313 }
314 setvbuf(output, (char *)NULL, _IOLBF, 0);
315 fcntl(fileno(output), F_SETFD, FD_CLOEXEC);
316 break;
317 case 'p':
318 {
319 struct opt_p_t *tmp =
320 malloc(sizeof(struct opt_p_t));
321 if (!tmp) {
322 perror("ltrace: malloc");
323 exit(1);
324 }
325 tmp->pid = atoi(optarg);
326 tmp->next = opt_p;
327 opt_p = tmp;
328 break;
329 }
330 case 'r':
331 opt_r++;
332 break;
333 case 's':
334 opt_s = atoi(optarg);
335 break;
336 case 'S':
337 opt_S = 1;
338 break;
339 case 't':
340 opt_t++;
341 break;
342 case 'T':
343 opt_T++;
344 break;
345 case 'u':
346 opt_u = optarg;
347 break;
348 case 'V':
349 printf("ltrace version " PACKAGE_VERSION ".\n"
350 "Copyright (C) 1997-2006 Juan Cespedes <cespedes@debian.org>.\n"
351 "This is free software; see the GNU General Public Licence\n"
352 "version 2 or later for copying conditions. There is NO warranty.\n");
353 exit(0);
354 case 'X':
Paul Gilliambe320772006-04-24 22:06:23 +0200355#ifdef PLT_REINITALISATION_BP
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100356 PLTs_initialized_by_here = optarg;
Paul Gilliambe320772006-04-24 22:06:23 +0200357#else
358 fprintf(stderr, "WANRING: \"-X\" not used for this "
359 "architecture: assuming you meant \"-x\"\n");
360#endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100361 /* Fall Thru */
Juan Cespedesac3db291998-04-25 14:31:58 +0200362
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100363 case 'x':
364 {
Paul Gilliam24e643a2006-03-13 18:43:13 +0100365 struct opt_x_t *p = opt_x;
Ian Wienand9a2ad352006-02-20 22:44:45 +0100366
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100367 /* First, check for duplicate. */
368 while (p && strcmp(p->name, optarg)) {
369 p = p->next;
370 }
371 if (p) {
Ian Wienand9a2ad352006-02-20 22:44:45 +0100372 break;
373 }
374
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100375 /* If not duplicate, add to list. */
Paul Gilliam24e643a2006-03-13 18:43:13 +0100376 p = malloc(sizeof(struct opt_x_t));
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100377 if (!p) {
378 perror("ltrace: malloc");
379 exit(1);
380 }
381 p->name = optarg;
Paul Gilliam24e643a2006-03-13 18:43:13 +0100382 p->found = 0;
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100383 p->next = opt_x;
384 opt_x = p;
385 break;
386 }
Ian Wienand9a2ad352006-02-20 22:44:45 +0100387
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100388 default:
Juan Cespedesac3db291998-04-25 14:31:58 +0200389#if HAVE_GETOPT_LONG
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100390 fprintf(stderr,
391 "Try `%s --help' for more information\n",
392 progname);
Juan Cespedesac3db291998-04-25 14:31:58 +0200393#else
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100394 fprintf(stderr, "Try `%s -h' for more information\n",
395 progname);
Juan Cespedesac3db291998-04-25 14:31:58 +0200396#endif
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100397 exit(1);
Juan Cespedes5e01f651998-03-08 22:31:44 +0100398 }
399 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100400 argc -= optind;
401 argv += optind;
Juan Cespedesac3db291998-04-25 14:31:58 +0200402#endif
Juan Cespedes5e01f651998-03-08 22:31:44 +0100403
Steve Fink58c73a72006-07-17 23:18:35 +0200404 if (!opt_F) {
405 opt_F = malloc(sizeof(struct opt_F_t));
406 opt_F->next = malloc(sizeof(struct opt_F_t));
407 opt_F->next->next = NULL;
408 opt_F->filename = USER_CONFIG_FILE;
409 opt_F->next->filename = SYSTEM_CONFIG_FILE;
410 }
411 /* Reverse the config file list since it was built by
412 * prepending, and it would make more sense to process the
413 * files in the order they were given. Probably it would make
414 * more sense to keep a tail pointer instead? */
415 {
416 struct opt_F_t *egg = NULL;
417 struct opt_F_t *chicken;
418 while (opt_F) {
419 chicken = opt_F->next;
420 opt_F->next = egg;
421 egg = opt_F;
422 opt_F = chicken;
423 }
424 opt_F = egg;
425 }
426
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100427 if (!opt_p && argc < 1) {
Juan Cespedesac3db291998-04-25 14:31:58 +0200428 fprintf(stderr, "%s: too few arguments\n", progname);
Juan Cespedes5c3fe062004-06-14 18:08:37 +0200429 usage();
Juan Cespedes5e01f651998-03-08 22:31:44 +0100430 exit(1);
431 }
Juan Cespedesf666d191998-09-20 23:04:34 +0200432 if (opt_r && opt_t) {
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100433 fprintf(stderr, "%s: Incompatible options -r and -t\n",
434 progname);
Juan Cespedesf666d191998-09-20 23:04:34 +0200435 exit(1);
436 }
Ian Wienand2d45b1a2006-02-20 22:48:07 +0100437 if (argc > 0) {
Juan Cespedesac3db291998-04-25 14:31:58 +0200438 command = search_for_command(argv[0]);
Juan Cespedes1fe93d51998-03-13 00:29:21 +0100439 }
Juan Cespedesac3db291998-04-25 14:31:58 +0200440 return &argv[0];
Juan Cespedes5e01f651998-03-08 22:31:44 +0100441}