Skip to content

Commit 27d206f

Browse files
committed
Merge pull request brendangregg#14 from g2p/master
execsnoop: Instrument sys_execve first
2 parents 41fe778 + 50893c8 commit 27d206f

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

execsnoop

+10-9
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
# USAGE: ./execsnoop [-hrt] [-n name]
1010
#
1111
# REQUIREMENTS: FTRACE and KPROBE CONFIG, sched:sched_process_fork tracepoint,
12-
# and either the stub_execve() or do_execve() kernel function. You may already
13-
# have these on recent kernels. And awk.
12+
# and either the sys_execve, stub_execve or do_execve kernel function. You may
13+
# already have these on recent kernels. And awk.
1414
#
1515
# This traces exec() from the fork()->exec() sequence, which means it won't
1616
# catch new processes that only fork(). With the -r option, it will also catch
@@ -21,9 +21,9 @@
2121
#
2222
# This implementation is designed to work on older kernel versions, and without
2323
# kernel debuginfo. It works by dynamic tracing an execve kernel function to
24-
# read the arguments from the %si register. The stub_execve() function is tried
25-
# first, and then the do_execve() function. The sched:sched_process_fork
26-
# tracepoint, is used for the PPID. This program is a workaround that should be
24+
# read the arguments from the %si register. The sys_execve function is tried
25+
# first, then stub_execve and do_execve. The sched:sched_process_fork
26+
# tracepoint is used to get the PPID. This program is a workaround that should be
2727
# improved in the future when other kernel capabilities are made available. If
2828
# you need a more reliable tool now, then consider other tracing alternatives
2929
# (eg, SystemTap). This tool is really a proof of concept to see what ftrace can
@@ -184,15 +184,15 @@ function makeprobe {
184184
(( i++ ))
185185
done
186186
}
187-
# try stub_execve() first, then do_execve() and sys_execve
188-
makeprobe stub_execve
187+
# try in this order: sys_execve, stub_execve, do_execve
188+
makeprobe sys_execve
189189

190190
### setup and begin tracing
191191
echo nop > current_tracer
192192
if ! echo $kprobe >> kprobe_events 2>/dev/null; then
193-
makeprobe do_execve
193+
makeprobe stub_execve
194194
if ! echo $kprobe >> kprobe_events 2>/dev/null; then
195-
makeprobe sys_execve
195+
makeprobe do_execve
196196
if ! echo $kprobe >> kprobe_events 2>/dev/null; then
197197
edie "ERROR: adding a kprobe for execve. Exiting."
198198
fi
@@ -204,6 +204,7 @@ fi
204204
if ! echo 1 > events/sched/sched_process_fork/enable; then
205205
edie "ERROR: enabling sched:sched_process_fork tracepoint. Exiting."
206206
fi
207+
echo "Instrumenting $func"
207208
(( opt_time )) && printf "%-16s " "TIMEs"
208209
printf "%6s %6s %s\n" "PID" "PPID" "ARGS"
209210

0 commit comments

Comments
 (0)