Commit cbb16114 authored by yonghong-song's avatar yonghong-song Committed by GitHub

Merge pull request #1672 from brtmr/master

Added -q option to execsnoop to quote individual arguments. 
parents 18d3814c 059ff55d
...@@ -30,6 +30,10 @@ Include a timestamp column. ...@@ -30,6 +30,10 @@ Include a timestamp column.
\-x \-x
Include failed exec()s Include failed exec()s
.TP .TP
\-q
Add "quotemarks" around arguments. Escape quotemarks in arguments with a
backslash. For tracing empty arguments or arguments that contain whitespace.
.TP
\-n NAME \-n NAME
Only print command lines matching this name (regex) Only print command lines matching this name (regex)
.TP .TP
...@@ -52,6 +56,10 @@ Include failed exec()s: ...@@ -52,6 +56,10 @@ Include failed exec()s:
# #
.B execsnoop \-x .B execsnoop \-x
.TP .TP
Put quotemarks around arguments.
#
.B execsnoop \-q
.TP
Only trace exec()s where the filename contains "mount": Only trace exec()s where the filename contains "mount":
# #
.B execsnoop \-n mount .B execsnoop \-n mount
......
...@@ -31,6 +31,7 @@ examples = """examples: ...@@ -31,6 +31,7 @@ examples = """examples:
./execsnoop # trace all exec() syscalls ./execsnoop # trace all exec() syscalls
./execsnoop -x # include failed exec()s ./execsnoop -x # include failed exec()s
./execsnoop -t # include timestamps ./execsnoop -t # include timestamps
./execsnoop -q # add "quotemarks" around arguments
./execsnoop -n main # only print command lines containing "main" ./execsnoop -n main # only print command lines containing "main"
./execsnoop -l tpkg # only print command where arguments contains "tpkg" ./execsnoop -l tpkg # only print command where arguments contains "tpkg"
""" """
...@@ -42,6 +43,9 @@ parser.add_argument("-t", "--timestamp", action="store_true", ...@@ -42,6 +43,9 @@ parser.add_argument("-t", "--timestamp", action="store_true",
help="include timestamp on output") help="include timestamp on output")
parser.add_argument("-x", "--fails", action="store_true", parser.add_argument("-x", "--fails", action="store_true",
help="include failed exec()s") help="include failed exec()s")
parser.add_argument("-q", "--quote", action="store_true",
help="Add quotemarks (\") around arguments."
)
parser.add_argument("-n", "--name", parser.add_argument("-n", "--name",
type=ArgString, type=ArgString,
help="only print commands matching this name (regex), any arg") help="only print commands matching this name (regex), any arg")
...@@ -195,6 +199,11 @@ def print_event(cpu, data, size): ...@@ -195,6 +199,11 @@ def print_event(cpu, data, size):
if args.line and not re.search(bytes(args.line), if args.line and not re.search(bytes(args.line),
b' '.join(argv[event.pid])): b' '.join(argv[event.pid])):
skip = True skip = True
if args.quote:
argv[event.pid] = [
"\"" + arg.replace("\"", "\\\"") + "\""
for arg in argv[event.pid]
]
if not skip: if not skip:
if args.timestamp: if args.timestamp:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment