From: Denys Vlasenko Date: Tue, 24 Jan 2012 10:37:03 +0000 (+0100) Subject: Slightly more compact handling of argv[] X-Git-Tag: v4.7~198 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=837399af4ffefec55f9693022dc6d8608da442cf;p=strace Slightly more compact handling of argv[] text data bss dec hex filename 238274 672 20484 259430 3f566 strace.before 238226 672 20484 259382 3f536 strace * strace.c (main): Slightly more compact handling of argv[] Signed-off-by: Denys Vlasenko --- diff --git a/strace.c b/strace.c index 835003ef..745294dd 100644 --- a/strace.c +++ b/strace.c @@ -1119,6 +1119,8 @@ main(int argc, char *argv[]) break; } } + argv += optind; + /* argc -= optind; - no need, argc is not used below */ acolumn_spaces = malloc(acolumn + 1); if (!acolumn_spaces) @@ -1126,7 +1128,8 @@ main(int argc, char *argv[]) memset(acolumn_spaces, ' ', acolumn); acolumn_spaces[acolumn] = '\0'; - if ((optind == argc) == !pflag_seen) + /* Must have PROG [ARGS], or -p PID. Not both. */ + if (!argv[0] == !pflag_seen) usage(stderr, 1); if (pflag_seen && daemonized_tracer) { @@ -1187,25 +1190,25 @@ main(int argc, char *argv[]) die_out_of_memory(); setvbuf(outf, buf, _IOLBF, BUFSIZ); } - if (outfname && optind < argc) { + if (outfname && argv[0]) { interactive = 0; qflag = 1; } /* Valid states here: - optind < argc pflag_seen outfname interactive - 1 0 0 1 - 0 1 0 1 - 1 0 1 0 - 0 1 1 1 + argv[0] pflag_seen outfname interactive + yes 0 0 1 + no 1 0 1 + yes 0 1 0 + no 1 1 1 */ /* STARTUP_CHILD must be called before the signal handlers get installed below as they are inherited into the spawned process. Also we do not need to be protected by them as during interruption in the STARTUP_CHILD mode we kill the spawned process anyway. */ - if (!pflag_seen) - startup_child(&argv[optind]); + if (argv[0]) + startup_child(argv); sigemptyset(&empty_set); sigemptyset(&blocked_set); @@ -1214,6 +1217,10 @@ main(int argc, char *argv[]) sa.sa_flags = 0; sigaction(SIGTTOU, &sa, NULL); sigaction(SIGTTIN, &sa, NULL); + /* In interactive mode (if no -o OUTFILE, or -p PID is used), + * fatal signals are blocked across syscall waits, and acted on + * in between. In non-interactive mode, signals are ignored. + */ if (interactive) { sigaddset(&blocked_set, SIGHUP); sigaddset(&blocked_set, SIGINT);