summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMasatake YAMATO <yamato@redhat.com>2021-09-09 22:43:32 +0900
committerDmitry V. Levin <ldv@strace.io>2021-11-14 08:00:00 +0000
commitbd5a5ee359395b2f1d2ce0efb6c084b29b47b8f2 (patch)
treeb442b36377a077ebea2f1b708d8a2fe5a328665b
parent4af3e77a296b549e55cdea1ea679be9f4e66c465 (diff)
downloadstrace-bd5a5ee359395b2f1d2ce0efb6c084b29b47b8f2.tar.gz
Introduce --decode-pids=pidns as an alias for --pidns-translation
In preparation for the forthcoming -Y/--decode-pids=comm option. * doc/strace.1.in (.SS Output format): Document --decode-pids=pidns option. * src/defs.h (pidns_translation): Remove. (pid_decoding): New variable declaration. (enum pid_decoding_flags): New enum. (qualify_decode_pid): New function prototype. * src/strace.c (pidns_translation): Remove. (pid_decoding): New variable. (usage): Describe --decode-pids=pidns option. (init) <enum>: Add GETOPT_QUAL_DECODE_PID. <longopts>: Add --decode-pids as a long option. <case GETOPT_PIDNS_TRANSLATION>: Call qualify_decode_pid to update pid_decoding indirectly. <case GETOPT_QUAL_DECODE_PID>: New condition. * src/filter_qualify.c (qualify_decode_pid): New function. * src/pidns.c (printpid_translation): Refer to pid_decoding as the replacement for pidns_translation. * tests/init.sh (test_pidns_run_strace): Replace --pidns-translation with --decode-pids=pidns. * tests/options-syntax.test: Check invalid --decode-pids argument. * NEWS: Mention this change. Making --decode-pids option a super set of --pidns-translation option is Suggested-by: by Eugene Syromyatnikov <evgsyr@gmail.com>. Signed-off-by: Masatake YAMATO <yamato@redhat.com> Co-authored-by: Dmitry V. Levin <ldv@strace.io>
-rw-r--r--NEWS1
-rw-r--r--doc/strace.1.in2
-rw-r--r--src/defs.h6
-rw-r--r--src/filter_qualify.c9
-rw-r--r--src/pidns.c2
-rw-r--r--src/strace.c11
-rw-r--r--tests/init.sh2
-rwxr-xr-xtests/options-syntax.test1
8 files changed, 29 insertions, 5 deletions
diff --git a/NEWS b/NEWS
index 887fa2d09..86508c73f 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,7 @@ Noteworthy changes in release ?.?? (????-??-??)
* Improvements
* Implemented --strings-in-hex=non-ascii-chars option for using hexadecimal
numbers instead of octal ones in escape sequences in the output strings.
+ * Implemented --decode-pids=pidns as an alias to --pidns-translation option.
* Improved printing of syscall names in places where the associated
AUDIT_ARCH_* value is present (ptrace PTRACE_GET_SYSCALL_INFO request,
SIGSYS siginfo_t).
diff --git a/doc/strace.1.in b/doc/strace.1.in
index 0de927694..aefb0096f 100644
--- a/doc/strace.1.in
+++ b/doc/strace.1.in
@@ -1124,6 +1124,8 @@ block/character device number associated with device file descriptors,
and PIDs associated with pidfd file descriptors.
.TP
.B \-\-pidns\-translation
+.TQ
+.BR \-\-decode\-pids = pidns
If strace and tracee are in different PID namespaces, print PIDs in
strace's namespace, too.
.if '@ENABLE_SECONTEXT_FALSE@'#' .TP
diff --git a/src/defs.h b/src/defs.h
index 45e2b4a71..2c00f4e1f 100644
--- a/src/defs.h
+++ b/src/defs.h
@@ -508,7 +508,10 @@ extern int Tflag_scale;
extern int Tflag_width;
extern bool iflag;
extern bool count_wallclock;
-extern unsigned int pidns_translation;
+extern unsigned int pid_decoding;
+enum pid_decoding_flags {
+ PID_DECODING_NS_TRANSLATION = 1 << 0,
+};
/* are we filtering traces based on paths? */
extern struct path_set {
const char **paths_selected;
@@ -1328,6 +1331,7 @@ extern void qualify_signals(const char *);
extern void qualify_status(const char *);
extern void qualify_quiet(const char *);
extern void qualify_decode_fd(const char *);
+extern void qualify_decode_pid(const char *);
extern void qualify_read(const char *);
extern void qualify_write(const char *);
extern void qualify_fault(const char *);
diff --git a/src/filter_qualify.c b/src/filter_qualify.c
index 7fc2b23b6..1eb96021b 100644
--- a/src/filter_qualify.c
+++ b/src/filter_qualify.c
@@ -466,6 +466,15 @@ qualify_decode_fd(const char *const str)
}
void
+qualify_decode_pid(const char *const str)
+{
+ if (strcmp(str, "pidns") == 0)
+ pid_decoding |= PID_DECODING_NS_TRANSLATION;
+ else
+ error_msg_and_die("invalid --decode-pids= argument: '%s'", str);
+}
+
+void
qualify_trace(const char *const str)
{
if (!trace_set)
diff --git a/src/pidns.c b/src/pidns.c
index 9c7b7ce1a..eda87aad9 100644
--- a/src/pidns.c
+++ b/src/pidns.c
@@ -527,7 +527,7 @@ get_proc_pid(int pid)
static void
printpid_translation(struct tcb *tcp, int pid, enum pid_type type)
{
- if (!pidns_translation)
+ if (!(pid_decoding & PID_DECODING_NS_TRANSLATION))
return;
int strace_pid = translate_pid(tcp, pid, type, NULL);
diff --git a/src/strace.c b/src/strace.c
index 21376b4fd..f08f1c996 100644
--- a/src/strace.c
+++ b/src/strace.c
@@ -137,7 +137,7 @@ static unsigned int daemonized_tracer;
static int post_attach_sigstop = TCB_IGNORE_ONE_SIGSTOP;
#define use_seize (post_attach_sigstop == 0)
-unsigned int pidns_translation;
+unsigned int pid_decoding;
static bool detach_on_execve;
@@ -418,6 +418,8 @@ Output format:\n\
-yy, --decode-fds=all\n\
print all available information associated with file\n\
descriptors in addition to paths\n\
+ --decode-pids=pidns\n\
+ print PIDs in strace's namespace, too\n\
"
#ifdef ENABLE_SECONTEXT
"\
@@ -2082,6 +2084,7 @@ init(int argc, char *argv[])
GETOPT_QUAL_KVM,
GETOPT_QUAL_QUIET,
GETOPT_QUAL_DECODE_FD,
+ GETOPT_QUAL_DECODE_PID,
};
static const struct option longopts[] = {
{ "columns", required_argument, 0, 'a' },
@@ -2143,6 +2146,7 @@ init(int argc, char *argv[])
{ "silent", optional_argument, 0, GETOPT_QUAL_QUIET },
{ "silence", optional_argument, 0, GETOPT_QUAL_QUIET },
{ "decode-fds", optional_argument, 0, GETOPT_QUAL_DECODE_FD },
+ { "decode-pids",required_argument, 0, GETOPT_QUAL_DECODE_PID },
{ 0, 0, 0, 0 }
};
@@ -2340,7 +2344,7 @@ init(int argc, char *argv[])
yflag_short++;
break;
case GETOPT_PIDNS_TRANSLATION:
- pidns_translation++;
+ qualify_decode_pid("pidns");
break;
case 'z':
clear_number_set_array(status_set, 1);
@@ -2405,6 +2409,9 @@ init(int argc, char *argv[])
case GETOPT_QUAL_DECODE_FD:
qualify_decode_fd(optarg ?: yflag_qual);
break;
+ case GETOPT_QUAL_DECODE_PID:
+ qualify_decode_pid(optarg);
+ break;
default:
error_msg_and_help(NULL);
break;
diff --git a/tests/init.sh b/tests/init.sh
index e39673fb0..23dacfcdc 100644
--- a/tests/init.sh
+++ b/tests/init.sh
@@ -481,7 +481,7 @@ test_pidns_run_strace()
run_prog > /dev/null
args="$prog_args"
- run_strace --pidns-translation -f "$@" $args > "$EXP"
+ run_strace --decode-pids=pidns -f "$@" $args > "$EXP"
# filter out logs made by the parent or init process of the pidns test
parent_pid="$(tail -n 2 $LOG | head -n 1 | cut -d' ' -f1)"
diff --git a/tests/options-syntax.test b/tests/options-syntax.test
index 765b2f867..a6a5d53de 100755
--- a/tests/options-syntax.test
+++ b/tests/options-syntax.test
@@ -221,6 +221,7 @@ check_h 'deprecated option -F ignored
check_e "invalid system call '/getcwd@ohmy'" -e trace=/getcwd@ohmy
check_e "invalid -e kvm= argument: 'chdir'" -e kvm=chdir
check_e "invalid -e kvm= argument: 'chdir'" --kvm=chdir
+check_e "invalid --decode-pids= argument: 'chdir'" --decode-pids=chdir
case "$STRACE_NATIVE_ARCH" in
x86_64)