summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEugene Syromiatnikov <esyr@redhat.com>2017-12-31 18:13:39 +0100
committerDmitry V. Levin <ldv@altlinux.org>2019-05-21 23:30:35 +0000
commit5239cc4c6ce852a2383abea302bfa36231230234 (patch)
treef05eb9e4410b521c9de028fa99c82be8ddb12a4d
parent3b4045a79da136713a7c4cc25125b1216898e86a (diff)
downloadstrace-5239cc4c6ce852a2383abea302bfa36231230234.tar.gz
strace.c: move argc/nprocs check to the tracing_backend_init routine
It is deemed that for some tracing backends it is possible to run strace without providing either program to run or PIDs to attach (attaching to already running GDB server with existing inferiors is an example). Thus, let's move this check to tracing_backend_init. * strace.c (tracing_backend_init): Add (!nprocs && !argc) check. (init): Remove (!nprocs && !argc) check, update error message for (argc < 0) check. * tests/options-syntax.test: Update expected output.
-rw-r--r--strace.c8
-rwxr-xr-xtests/options-syntax.test4
2 files changed, 7 insertions, 5 deletions
diff --git a/strace.c b/strace.c
index 5ea2efcb3..ab93dead3 100644
--- a/strace.c
+++ b/strace.c
@@ -1623,6 +1623,9 @@ tracing_backend_init(int argc, char *argv[])
{
os_release = get_os_release();
+ if (!nprocs && !argc)
+ error_msg_and_help("must have PROG [ARGS] or -p PID");
+
if (followfork)
ptrace_setoptions |= PTRACE_O_TRACECLONE |
PTRACE_O_TRACEFORK |
@@ -1831,9 +1834,8 @@ init(int argc, char *argv[])
argv += optind;
argc -= optind;
- if (argc < 0 || (!nprocs && !argc)) {
- error_msg_and_help("must have PROG [ARGS] or -p PID");
- }
+ if (argc < 0)
+ error_msg_and_help("must have command line arguments");
if (!argc && daemonized_tracer) {
error_msg_and_help("PROG [ARGS] must be specified with -D");
diff --git a/tests/options-syntax.test b/tests/options-syntax.test
index 5e43b3ab8..936ed2955 100755
--- a/tests/options-syntax.test
+++ b/tests/options-syntax.test
@@ -76,12 +76,12 @@ esac
dump_log_and_fail_with \
'zeroargc strace failed to handle the error properly'
cat > "$EXP" << __EOF__
-$STRACE_EXE: must have PROG [ARGS] or -p PID
+$STRACE_EXE: must have command line arguments
Try '$STRACE_EXE -h' for more information.
__EOF__
diff -u -- "$EXP" "$LOG" > /dev/null || {
cat > "$EXP" <<- '__EOF__'
- strace: must have PROG [ARGS] or -p PID
+ strace: must have command line arguments
Try 'strace -h' for more information.
__EOF__
match_diff "$LOG" "$EXP" \