| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 1 | #include "config.h" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 2 | |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 3 | #include <sys/ioctl.h> |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 4 | #include <assert.h> |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 5 | #include <errno.h> |
| 6 | #include <error.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <getopt.h> |
| 9 | #include <limits.h> |
| 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
| 12 | #include <unistd.h> |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 13 | |
| Juan Cespedes | f728123 | 2009-06-25 16:11:21 +0200 | [diff] [blame] | 14 | #include "common.h" |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 15 | #include "filter.h" |
| 16 | #include "glob.h" |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 17 | |
| Steve Fink | 58c73a7 | 2006-07-17 23:18:35 +0200 | [diff] [blame] | 18 | #ifndef SYSCONFDIR |
| 19 | #define SYSCONFDIR "/etc" |
| 20 | #endif |
| 21 | |
| Olaf Hering | e948e58 | 2006-10-12 23:53:44 +0200 | [diff] [blame] | 22 | #define SYSTEM_CONFIG_FILE SYSCONFDIR "/ltrace.conf" |
| Steve Fink | 58c73a7 | 2006-07-17 23:18:35 +0200 | [diff] [blame] | 23 | #define USER_CONFIG_FILE "~/.ltrace.conf" |
| 24 | |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 25 | struct options_t options = { |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 26 | .align = DEFAULT_ALIGN, /* alignment column for results */ |
| 27 | .user = NULL, /* username to run command as */ |
| 28 | .syscalls = 0, /* display syscalls */ |
| 29 | .libcalls = 1, /* display library calls */ |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 30 | #ifdef USE_DEMANGLE |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 31 | .demangle = 0, /* Demangle low-level symbol names */ |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 32 | #endif |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 33 | .indent = 0, /* indent output according to program flow */ |
| 34 | .output = NULL, /* output to a specific file */ |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 35 | .summary = 0, /* Report a summary on program exit */ |
| 36 | .debug = 0, /* debug */ |
| 37 | .arraylen = DEFAULT_ARRAYLEN, /* maximum # array elements to print */ |
| 38 | .strlen = DEFAULT_STRLEN, /* maximum # of bytes printed in strings */ |
| 39 | .follow = 0, /* trace child processes */ |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 40 | }; |
| 41 | |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 42 | static char *progname; /* Program name (`ltrace') */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 43 | int opt_i = 0; /* instruction pointer */ |
| Juan Cespedes | f666d19 | 1998-09-20 23:04:34 +0200 | [diff] [blame] | 44 | int opt_r = 0; /* print relative timestamp */ |
| Juan Cespedes | 5e0acdb | 1998-04-04 08:34:07 +0200 | [diff] [blame] | 45 | int opt_t = 0; /* print absolute timestamp */ |
| Juan Cespedes | d65efa3 | 2003-02-03 00:22:30 +0100 | [diff] [blame] | 46 | int opt_T = 0; /* show the time spent inside each call */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 47 | |
| 48 | /* List of pids given to option -p: */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 49 | struct opt_p_t *opt_p = NULL; /* attach to process with a given pid */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 50 | |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 51 | /* List of global function names given to -x: */ |
| Paul Gilliam | 24e643a | 2006-03-13 18:43:13 +0100 | [diff] [blame] | 52 | struct opt_x_t *opt_x = NULL; |
| Joe Damato | 7b0a7de | 2010-11-08 15:47:34 -0800 | [diff] [blame] | 53 | unsigned int opt_x_cnt = 0; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 54 | |
| Steve Fink | 58c73a7 | 2006-07-17 23:18:35 +0200 | [diff] [blame] | 55 | /* List of filenames give to option -F: */ |
| 56 | struct opt_F_t *opt_F = NULL; /* alternate configuration file(s) */ |
| 57 | |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 58 | #ifdef PLT_REINITALISATION_BP |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 59 | /* Set a break on the routine named here in order to re-initialize breakpoints |
| 60 | after all the PLTs have been initialzed */ |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 61 | char *PLTs_initialized_by_here = PLT_REINITALISATION_BP; |
| 62 | #endif |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 63 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 64 | static void |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 65 | err_usage(void) { |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 66 | fprintf(stderr, "Try `%s --help' for more information\n", progname); |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 67 | exit(1); |
| 68 | } |
| 69 | |
| 70 | static void |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 71 | usage(void) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 72 | fprintf(stdout, "Usage: %s [option ...] [command [arg ...]]\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 73 | "Trace library calls of a given program.\n\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 74 | " -a, --align=COLUMN align return values in a secific column.\n" |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 75 | " -A ARRAYLEN maximum number of array elements to print.\n" |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 76 | " -b, --no-signals don't print signals.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 77 | " -c count time and calls, and report a summary on exit.\n" |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 78 | # ifdef USE_DEMANGLE |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 79 | " -C, --demangle decode low-level symbol names into user-level names.\n" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 80 | # endif |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 81 | " -D, --debug=LEVEL enable debugging (see -Dh or --debug=help).\n" |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 82 | " -Dh, --debug=help show help on debugging.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 83 | " -e expr modify which events to trace.\n" |
| Juan Cespedes | c4e53a9 | 2009-05-06 20:36:42 +0200 | [diff] [blame] | 84 | " -f trace children (fork() and clone()).\n" |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 85 | " -F, --config=FILE load alternate configuration file (may be repeated).\n" |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 86 | " -g, --no-plt disable breakpoints on PLT entries.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 87 | " -h, --help display this help and exit.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 88 | " -i print instruction pointer at time of library call.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 89 | " -l, --library=FILE print library calls from this library only.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 90 | " -L do NOT display library calls.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 91 | " -n, --indent=NR indent output by NR spaces for each call level nesting.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 92 | " -o, --output=FILE write the trace output to that file.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 93 | " -p PID attach to the process with the process ID pid.\n" |
| 94 | " -r print relative timestamps.\n" |
| 95 | " -s STRLEN specify the maximum string size to print.\n" |
| 96 | " -S display system calls.\n" |
| 97 | " -t, -tt, -ttt print absolute timestamps.\n" |
| 98 | " -T show the time spent inside each call.\n" |
| 99 | " -u USERNAME run command with the userid, groupid of username.\n" |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 100 | " -V, --version output version information and exit.\n" |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 101 | #if defined(HAVE_LIBUNWIND) |
| 102 | " -w=NR, --where=NR print backtrace showing NR stack frames at most.\n" |
| 103 | #endif /* defined(HAVE_LIBUNWIND) */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 104 | " -x NAME treat the global NAME like a library subroutine.\n" |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 105 | #ifdef PLT_REINITALISATION_BP |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 106 | " -X NAME same as -x; and PLT's will be initialized by here.\n" |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 107 | #endif |
| 108 | "\nReport bugs to ltrace-devel@lists.alioth.debian.org\n", |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 109 | progname); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 112 | static void |
| 113 | usage_debug(void) { |
| 114 | fprintf(stdout, "%s debugging option, --debug=<octal> or -D<octal>:\n", progname); |
| 115 | fprintf(stdout, |
| 116 | "\n" |
| 117 | " number ref. in source description\n" |
| 118 | " 1 general Generally helpful progress information\n" |
| 119 | " 10 event Shows every event received by a traced process\n" |
| 120 | " 20 process Shows actions carried upon a traced processes\n" |
| 121 | " 40 function Shows every entry to internal functions\n" |
| 122 | "\n" |
| 123 | "Debugging options are mixed using bitwise-or.\n" |
| 124 | "Note that the meanings and values are subject to change.\n" |
| 125 | ); |
| 126 | } |
| 127 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 128 | static char * |
| 129 | search_for_command(char *filename) { |
| Juan Cespedes | f1bfe20 | 2002-03-27 00:22:23 +0100 | [diff] [blame] | 130 | static char pathname[PATH_MAX]; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 131 | char *path; |
| 132 | int m, n; |
| 133 | |
| 134 | if (strchr(filename, '/')) { |
| 135 | return filename; |
| 136 | } |
| 137 | for (path = getenv("PATH"); path && *path; path += m) { |
| 138 | if (strchr(path, ':')) { |
| 139 | n = strchr(path, ':') - path; |
| 140 | m = n + 1; |
| 141 | } else { |
| 142 | m = n = strlen(path); |
| 143 | } |
| Juan Cespedes | f1bfe20 | 2002-03-27 00:22:23 +0100 | [diff] [blame] | 144 | if (n + strlen(filename) + 1 >= PATH_MAX) { |
| 145 | fprintf(stderr, "Error: filename too long\n"); |
| 146 | exit(1); |
| 147 | } |
| 148 | strncpy(pathname, path, n); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 149 | if (n && pathname[n - 1] != '/') { |
| 150 | pathname[n++] = '/'; |
| 151 | } |
| 152 | strcpy(pathname + n, filename); |
| 153 | if (!access(pathname, X_OK)) { |
| 154 | return pathname; |
| 155 | } |
| 156 | } |
| 157 | return filename; |
| 158 | } |
| 159 | |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 160 | static void |
| 161 | guess_cols(void) { |
| 162 | struct winsize ws; |
| 163 | char *c; |
| 164 | |
| 165 | options.align = DEFAULT_ALIGN; |
| 166 | c = getenv("COLUMNS"); |
| 167 | if (c && *c) { |
| 168 | char *endptr; |
| 169 | int cols; |
| 170 | cols = strtol(c, &endptr, 0); |
| 171 | if (cols > 0 && !*endptr) { |
| 172 | options.align = cols * 5 / 8; |
| 173 | } |
| 174 | } else if (ioctl(1, TIOCGWINSZ, &ws) != -1 && ws.ws_col > 0) { |
| 175 | options.align = ws.ws_col * 5 / 8; |
| Juan Cespedes | 43739a6 | 2009-04-07 13:10:08 +0200 | [diff] [blame] | 176 | } else if (ioctl(2, TIOCGWINSZ, &ws) != -1 && ws.ws_col > 0) { |
| 177 | options.align = ws.ws_col * 5 / 8; |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 178 | } |
| 179 | } |
| 180 | |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 181 | static void |
| 182 | add_filter_rule(struct filter *filt, const char *expr, |
| 183 | enum filter_rule_type type, |
| 184 | const char *sym, int sym_re_p, |
| 185 | const char *lib, int lib_re_p) |
| 186 | { |
| 187 | fprintf(stderr, "add_filter_rule, type = %d\n", type); |
| 188 | fprintf(stderr, "+ symname = %s (re=%d)\n", sym, sym_re_p); |
| 189 | fprintf(stderr, "+ libname = %s (re=%d)\n", lib, lib_re_p); |
| 190 | struct filter_rule *rule = malloc(sizeof(*rule)); |
| 191 | struct filter_lib_matcher *matcher = malloc(sizeof(*matcher)); |
| 192 | |
| 193 | if (rule == NULL || matcher == NULL) { |
| 194 | error(0, errno, "rule near '%s' will be ignored", expr); |
| 195 | fail: |
| 196 | free(rule); |
| 197 | free(matcher); |
| 198 | return; |
| 199 | } |
| 200 | |
| 201 | regex_t symbol_re; |
| 202 | int status = (sym_re_p ? regcomp : globcomp)(&symbol_re, sym, 0); |
| 203 | if (status != 0) { |
| 204 | char buf[100]; |
| 205 | regerror(status, &symbol_re, buf, sizeof buf); |
| 206 | error(0, 0, "rule near '%s' will be ignored: %s", expr, buf); |
| 207 | goto fail; |
| 208 | } |
| 209 | |
| 210 | regex_t lib_re; |
| Petr Machata | e0973cb | 2012-04-01 19:36:41 +0200 | [diff] [blame^] | 211 | status = (lib_re_p ? regcomp : globcomp)(&lib_re, lib, 0); |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 212 | if (status != 0) { |
| 213 | char buf[100]; |
| 214 | regerror(status, &lib_re, buf, sizeof buf); |
| 215 | error(0, 0, "rule near '%s' will be ignored: %s", expr, buf); |
| 216 | |
| 217 | regfree(&symbol_re); |
| 218 | goto fail; |
| 219 | } |
| 220 | |
| 221 | filter_lib_matcher_name_init(matcher, lib_re); |
| 222 | filter_rule_init(rule, type, matcher, symbol_re); |
| Petr Machata | e0973cb | 2012-04-01 19:36:41 +0200 | [diff] [blame^] | 223 | filter_add_rule(filt, rule); |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static int |
| 227 | parse_filter(struct filter *filt, char *expr) |
| 228 | { |
| 229 | fprintf(stderr, "filter '%s'\n", expr); |
| 230 | |
| 231 | /* Filter is a chain of sym@lib rules separated by '-'. If |
| 232 | * the filter expression starts with '-', the missing initial |
| 233 | * rule is implicitly *@*. */ |
| 234 | |
| 235 | enum filter_rule_type type = FR_ADD; |
| 236 | |
| 237 | while (*expr != 0) { |
| 238 | size_t s = strcspn(expr, "@-"); |
| 239 | char *symname = expr; |
| 240 | char *libname; |
| 241 | char *next = expr + s + 1; |
| 242 | enum filter_rule_type this_type = type; |
| 243 | |
| 244 | if (expr[s] == 0) { |
| 245 | libname = "*"; |
| 246 | expr = next - 1; |
| 247 | |
| 248 | } else if (expr[s] == '-') { |
| 249 | libname = "*"; |
| 250 | expr = next; |
| 251 | type = FR_SUBTRACT; |
| 252 | |
| 253 | } else { |
| 254 | assert(expr[s] == '@'); |
| 255 | expr[s] = 0; |
| 256 | s = strcspn(next, "-"); |
| 257 | if (s == 0) { |
| 258 | libname = "*"; |
| 259 | expr = next; |
| 260 | } else if (next[s] == 0) { |
| 261 | expr = next + s; |
| 262 | libname = next; |
| 263 | |
| 264 | } else { |
| 265 | assert(next[s] == '-'); |
| 266 | type = FR_SUBTRACT; |
| 267 | next[s] = 0; |
| 268 | expr = next + s + 1; |
| 269 | libname = next; |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | assert(*libname != 0); |
| 274 | char *symend = symname + strlen(symname) - 1; |
| 275 | char *libend = libname + strlen(libname) - 1; |
| 276 | int sym_is_re = 0; |
| 277 | int lib_is_re = 0; |
| 278 | |
| 279 | /* |
| 280 | * /xxx/@... and ...@/xxx/ means that xxx are regular |
| 281 | * expressions. They are globs otherwise. |
| 282 | * |
| 283 | * /xxx@yyy/ is the same as /xxx/@/yyy/ |
| 284 | * |
| 285 | * @/xxx matches library path name |
| 286 | * @.xxx matches library relative path name |
| 287 | */ |
| 288 | if (symname[0] == '/') { |
| 289 | if (symname != symend && symend[0] == '/') { |
| 290 | ++symname; |
| 291 | *symend-- = 0; |
| 292 | sym_is_re = 1; |
| 293 | |
| 294 | } else { |
| 295 | sym_is_re = 1; |
| 296 | lib_is_re = 1; |
| 297 | ++symname; |
| 298 | |
| 299 | /* /XXX@YYY/ is the same as |
| 300 | * /XXX/@/YYY/. */ |
| 301 | if (libend[0] != '/') |
| 302 | error(0, 0, "unmatched '/'" |
| 303 | " in symbol name"); |
| 304 | else |
| 305 | *libend-- = 0; |
| 306 | } |
| 307 | } |
| 308 | |
| 309 | /* If libname ends in '/', then we expect '/' in the |
| 310 | * beginning too. Otherwise the initial '/' is part |
| 311 | * of absolute file name. */ |
| 312 | if (!lib_is_re && libend[0] == '/') { |
| 313 | lib_is_re = 1; |
| 314 | *libend-- = 0; |
| 315 | if (libname != libend && libname[0] == '/') |
| 316 | ++libname; |
| 317 | else |
| 318 | error(0, 0, "unmatched '/' in library name"); |
| 319 | } |
| 320 | |
| 321 | if (*symname == 0) /* /@AA/ */ |
| 322 | symname = "*"; |
| 323 | if (*libname == 0) /* /aa@/ */ |
| 324 | libname = "*"; |
| 325 | |
| 326 | add_filter_rule(filt, expr, this_type, |
| 327 | symname, sym_is_re, |
| 328 | libname, lib_is_re); |
| 329 | } |
| 330 | |
| 331 | return 0; |
| 332 | } |
| 333 | |
| 334 | static struct filter * |
| 335 | recursive_parse_chain(char *expr) |
| 336 | { |
| 337 | /* Event expression grammar: |
| 338 | * |
| 339 | * Chain ::= Filter FilterList |
| 340 | * FilterList ::= eps | ',' Filter FilterList |
| 341 | * Filter ::= Rule RuleList |
| 342 | * RuleList ::= eps | '-' Rule RuleList |
| 343 | * Rule ::= eps | Glob Soname |
| 344 | * Soname ::= eps | '@' Glob | '@' '/' Filename |
| 345 | * Glob ::= '/' Regex '/' |
| 346 | */ |
| 347 | |
| 348 | struct filter *filt = malloc(sizeof(*filt)); |
| 349 | if (filt == NULL) { |
| 350 | error(0, errno, "(part of) filter will be ignored: '%s'", expr); |
| 351 | return NULL; |
| 352 | } |
| 353 | |
| 354 | struct filter *next = NULL; |
| 355 | char *it; |
| 356 | int escape = 0; |
| 357 | for (it = expr; ; ++it) { |
| 358 | if (*it == 0) |
| 359 | goto done; |
| 360 | |
| 361 | if (escape) { |
| 362 | escape = 0; |
| 363 | continue; |
| 364 | } |
| 365 | |
| 366 | if (*it == '\\') { |
| 367 | escape = 1; |
| 368 | |
| 369 | } else if (*it == ',') { |
| 370 | *it = 0; |
| 371 | next = recursive_parse_chain(it + 1); |
| 372 | done: |
| 373 | filt->next = next; |
| 374 | if (parse_filter(filt, expr) < 0) { |
| 375 | fprintf(stderr, |
| 376 | "Filter '%s' will be ignored.\n", expr); |
| 377 | free(filt); |
| 378 | filt = next; |
| 379 | } |
| 380 | return filt; |
| 381 | } |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | static void |
| Petr Machata | e0973cb | 2012-04-01 19:36:41 +0200 | [diff] [blame^] | 386 | parse_filter_chain(struct options_t *options, const char *expr) |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 387 | { |
| 388 | char *str = strdup(expr); |
| 389 | if (str == NULL) { |
| 390 | error(0, errno, "filter '%s' will be ignored", expr); |
| 391 | return; |
| 392 | } |
| 393 | options->filter = recursive_parse_chain(str); |
| 394 | } |
| 395 | |
| Juan Cespedes | f135052 | 2008-12-16 18:19:58 +0100 | [diff] [blame] | 396 | char ** |
| 397 | process_options(int argc, char **argv) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 398 | progname = argv[0]; |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 399 | options.output = stderr; |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 400 | options.no_plt = 0; |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 401 | options.no_signals = 0; |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 402 | #if defined(HAVE_LIBUNWIND) |
| 403 | options.bt_depth = -1; |
| 404 | #endif /* defined(HAVE_LIBUNWIND) */ |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 405 | |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 406 | guess_cols(); |
| 407 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 408 | while (1) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 409 | int c; |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 410 | char *p; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 411 | int option_index = 0; |
| 412 | static struct option long_options[] = { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 413 | {"align", 1, 0, 'a'}, |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 414 | {"config", 1, 0, 'F'}, |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 415 | {"debug", 1, 0, 'D'}, |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 416 | # ifdef USE_DEMANGLE |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 417 | {"demangle", 0, 0, 'C'}, |
| Juan Cespedes | 8e3e082 | 1998-09-24 13:49:55 +0200 | [diff] [blame] | 418 | #endif |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 419 | {"indent", 1, 0, 'n'}, |
| 420 | {"help", 0, 0, 'h'}, |
| 421 | {"library", 1, 0, 'l'}, |
| 422 | {"output", 1, 0, 'o'}, |
| 423 | {"version", 0, 0, 'V'}, |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 424 | {"no-plt", 0, 0, 'g'}, |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 425 | {"no-signals", 0, 0, 'b'}, |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 426 | #if defined(HAVE_LIBUNWIND) |
| 427 | {"where", 1, 0, 'w'}, |
| 428 | #endif /* defined(HAVE_LIBUNWIND) */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 429 | {0, 0, 0, 0} |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 430 | }; |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 431 | c = getopt_long(argc, argv, "+cfhiLrStTVgb" |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 432 | # ifdef USE_DEMANGLE |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 433 | "C" |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 434 | # endif |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 435 | #if defined(HAVE_LIBUNWIND) |
| 436 | "a:A:D:e:F:l:n:o:p:s:u:x:X:w:", long_options, |
| 437 | #else /* !defined(HAVE_LIBUNWIND) */ |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 438 | "a:A:D:e:F:l:n:o:p:s:u:x:X:", long_options, |
| Joe Damato | ab3b72c | 2010-10-31 00:21:53 -0700 | [diff] [blame] | 439 | #endif |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 440 | &option_index); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 441 | if (c == -1) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 442 | break; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 443 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 444 | switch (c) { |
| 445 | case 'a': |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 446 | options.align = atoi(optarg); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 447 | break; |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 448 | case 'A': |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 449 | options.arraylen = atoi(optarg); |
| Steve Fink | 1150bc4 | 2006-08-07 06:04:43 +0200 | [diff] [blame] | 450 | break; |
| Joe Damato | 535e738 | 2010-11-08 15:47:43 -0800 | [diff] [blame] | 451 | case 'b': |
| 452 | options.no_signals = 1; |
| 453 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 454 | case 'c': |
| Juan Cespedes | da9b953 | 2009-04-07 15:33:50 +0200 | [diff] [blame] | 455 | options.summary++; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 456 | break; |
| Juan Cespedes | d914a20 | 2004-11-10 00:15:33 +0100 | [diff] [blame] | 457 | #ifdef USE_DEMANGLE |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 458 | case 'C': |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 459 | options.demangle++; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 460 | break; |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 461 | #endif |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 462 | case 'D': |
| 463 | if (optarg[0]=='h') { |
| 464 | usage_debug(); |
| 465 | exit(0); |
| 466 | } |
| 467 | options.debug = strtoul(optarg,&p,8); |
| 468 | if (*p) { |
| 469 | fprintf(stderr, "%s: --debug requires an octal argument\n", progname); |
| 470 | err_usage(); |
| 471 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 472 | break; |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 473 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 474 | case 'e': |
| Petr Machata | e0973cb | 2012-04-01 19:36:41 +0200 | [diff] [blame^] | 475 | parse_filter_chain(&options, optarg); |
| Petr Machata | 1e4fed2 | 2012-04-01 00:45:22 +0200 | [diff] [blame] | 476 | break; |
| 477 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 478 | case 'f': |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 479 | options.follow = 1; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 480 | break; |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 481 | case 'F': |
| 482 | { |
| 483 | struct opt_F_t *tmp = malloc(sizeof(struct opt_F_t)); |
| 484 | if (!tmp) { |
| 485 | perror("ltrace: malloc"); |
| 486 | exit(1); |
| 487 | } |
| 488 | tmp->filename = strdup(optarg); |
| 489 | tmp->next = opt_F; |
| 490 | opt_F = tmp; |
| 491 | break; |
| 492 | } |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 493 | case 'g': |
| 494 | options.no_plt = 1; |
| 495 | break; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 496 | case 'h': |
| 497 | usage(); |
| 498 | exit(0); |
| 499 | case 'i': |
| 500 | opt_i++; |
| 501 | break; |
| 502 | case 'l': |
| Petr Machata | 2b46cfc | 2012-02-18 11:17:29 +0100 | [diff] [blame] | 503 | assert(!"-l support not yet implemented"); |
| 504 | abort(); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 505 | break; |
| 506 | case 'L': |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 507 | options.libcalls = 0; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 508 | break; |
| 509 | case 'n': |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 510 | options.indent = atoi(optarg); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 511 | break; |
| 512 | case 'o': |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 513 | options.output = fopen(optarg, "w"); |
| 514 | if (!options.output) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 515 | fprintf(stderr, |
| 516 | "Can't open %s for output: %s\n", |
| 517 | optarg, strerror(errno)); |
| 518 | exit(1); |
| 519 | } |
| Juan Cespedes | b65bdc5 | 2008-12-16 19:50:16 +0100 | [diff] [blame] | 520 | setvbuf(options.output, (char *)NULL, _IOLBF, 0); |
| 521 | fcntl(fileno(options.output), F_SETFD, FD_CLOEXEC); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 522 | break; |
| 523 | case 'p': |
| 524 | { |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 525 | struct opt_p_t *tmp = malloc(sizeof(struct opt_p_t)); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 526 | if (!tmp) { |
| 527 | perror("ltrace: malloc"); |
| 528 | exit(1); |
| 529 | } |
| 530 | tmp->pid = atoi(optarg); |
| 531 | tmp->next = opt_p; |
| 532 | opt_p = tmp; |
| 533 | break; |
| 534 | } |
| 535 | case 'r': |
| 536 | opt_r++; |
| 537 | break; |
| 538 | case 's': |
| Juan Cespedes | cc813cd | 2009-04-07 15:45:53 +0200 | [diff] [blame] | 539 | options.strlen = atoi(optarg); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 540 | break; |
| 541 | case 'S': |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 542 | options.syscalls = 1; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 543 | break; |
| 544 | case 't': |
| 545 | opt_t++; |
| 546 | break; |
| 547 | case 'T': |
| 548 | opt_T++; |
| 549 | break; |
| 550 | case 'u': |
| Juan Cespedes | ce377d5 | 2008-12-16 19:38:10 +0100 | [diff] [blame] | 551 | options.user = optarg; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 552 | break; |
| 553 | case 'V': |
| 554 | printf("ltrace version " PACKAGE_VERSION ".\n" |
| Juan Cespedes | 1423f08 | 2009-04-07 00:45:33 +0200 | [diff] [blame] | 555 | "Copyright (C) 1997-2009 Juan Cespedes <cespedes@debian.org>.\n" |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 556 | "This is free software; see the GNU General Public Licence\n" |
| 557 | "version 2 or later for copying conditions. There is NO warranty.\n"); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 558 | exit(0); |
| Joe Damato | fa2aefc | 2010-10-30 19:56:50 -0700 | [diff] [blame] | 559 | break; |
| Joe Damato | 535e738 | 2010-11-08 15:47:43 -0800 | [diff] [blame] | 560 | #if defined(HAVE_LIBUNWIND) |
| 561 | case 'w': |
| 562 | options.bt_depth = atoi(optarg); |
| Joe Damato | 59e3fb1 | 2009-11-06 19:45:10 -0800 | [diff] [blame] | 563 | break; |
| Joe Damato | 535e738 | 2010-11-08 15:47:43 -0800 | [diff] [blame] | 564 | #endif /* defined(HAVE_LIBUNWIND) */ |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 565 | case 'X': |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 566 | #ifdef PLT_REINITALISATION_BP |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 567 | PLTs_initialized_by_here = optarg; |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 568 | #else |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 569 | fprintf(stderr, "WARNING: \"-X\" not used for this " |
| Paul Gilliam | be32077 | 2006-04-24 22:06:23 +0200 | [diff] [blame] | 570 | "architecture: assuming you meant \"-x\"\n"); |
| 571 | #endif |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 572 | /* Fall Thru */ |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 573 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 574 | case 'x': |
| 575 | { |
| Paul Gilliam | 24e643a | 2006-03-13 18:43:13 +0100 | [diff] [blame] | 576 | struct opt_x_t *p = opt_x; |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 577 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 578 | /* First, check for duplicate. */ |
| 579 | while (p && strcmp(p->name, optarg)) { |
| 580 | p = p->next; |
| 581 | } |
| 582 | if (p) { |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 583 | break; |
| 584 | } |
| 585 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 586 | /* If not duplicate, add to list. */ |
| Paul Gilliam | 24e643a | 2006-03-13 18:43:13 +0100 | [diff] [blame] | 587 | p = malloc(sizeof(struct opt_x_t)); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 588 | if (!p) { |
| 589 | perror("ltrace: malloc"); |
| 590 | exit(1); |
| 591 | } |
| Joe Damato | 7b0a7de | 2010-11-08 15:47:34 -0800 | [diff] [blame] | 592 | opt_x_cnt++; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 593 | p->name = optarg; |
| Paul Gilliam | 24e643a | 2006-03-13 18:43:13 +0100 | [diff] [blame] | 594 | p->found = 0; |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 595 | p->next = opt_x; |
| Joe Damato | 7b0a7de | 2010-11-08 15:47:34 -0800 | [diff] [blame] | 596 | p->hash = ~(0UL); |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 597 | opt_x = p; |
| 598 | break; |
| 599 | } |
| Ian Wienand | 9a2ad35 | 2006-02-20 22:44:45 +0100 | [diff] [blame] | 600 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 601 | default: |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 602 | err_usage(); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 603 | } |
| 604 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 605 | argc -= optind; |
| 606 | argv += optind; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 607 | |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 608 | if (!opt_F) { |
| 609 | opt_F = malloc(sizeof(struct opt_F_t)); |
| 610 | opt_F->next = malloc(sizeof(struct opt_F_t)); |
| 611 | opt_F->next->next = NULL; |
| 612 | opt_F->filename = USER_CONFIG_FILE; |
| 613 | opt_F->next->filename = SYSTEM_CONFIG_FILE; |
| 614 | } |
| Steve Fink | 58c73a7 | 2006-07-17 23:18:35 +0200 | [diff] [blame] | 615 | /* Reverse the config file list since it was built by |
| 616 | * prepending, and it would make more sense to process the |
| 617 | * files in the order they were given. Probably it would make |
| 618 | * more sense to keep a tail pointer instead? */ |
| 619 | { |
| Juan Cespedes | aee0931 | 2007-08-31 18:49:48 +0200 | [diff] [blame] | 620 | struct opt_F_t *egg = NULL; |
| 621 | struct opt_F_t *chicken; |
| 622 | while (opt_F) { |
| 623 | chicken = opt_F->next; |
| 624 | opt_F->next = egg; |
| 625 | egg = opt_F; |
| 626 | opt_F = chicken; |
| 627 | } |
| 628 | opt_F = egg; |
| Steve Fink | 58c73a7 | 2006-07-17 23:18:35 +0200 | [diff] [blame] | 629 | } |
| 630 | |
| Petr Machata | e0973cb | 2012-04-01 19:36:41 +0200 | [diff] [blame^] | 631 | if (options.filter == NULL) |
| 632 | parse_filter_chain(&options, "*"); |
| 633 | |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 634 | if (!opt_p && argc < 1) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 635 | fprintf(stderr, "%s: too few arguments\n", progname); |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 636 | err_usage(); |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 637 | } |
| Juan Cespedes | f666d19 | 1998-09-20 23:04:34 +0200 | [diff] [blame] | 638 | if (opt_r && opt_t) { |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 639 | fprintf(stderr, "%s: Incompatible options -r and -t\n", |
| 640 | progname); |
| Juan Cespedes | c5c744a | 2009-07-23 18:22:58 +0200 | [diff] [blame] | 641 | err_usage(); |
| Juan Cespedes | f666d19 | 1998-09-20 23:04:34 +0200 | [diff] [blame] | 642 | } |
| Ian Wienand | 2d45b1a | 2006-02-20 22:48:07 +0100 | [diff] [blame] | 643 | if (argc > 0) { |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 644 | command = search_for_command(argv[0]); |
| Juan Cespedes | 1fe93d5 | 1998-03-13 00:29:21 +0100 | [diff] [blame] | 645 | } |
| Juan Cespedes | ac3db29 | 1998-04-25 14:31:58 +0200 | [diff] [blame] | 646 | return &argv[0]; |
| Juan Cespedes | 5e01f65 | 1998-03-08 22:31:44 +0100 | [diff] [blame] | 647 | } |