Skip to content

Commit a52538f

Browse files
committed
killsnoop: can't work with mawk
On Ubuntu Linux release, mawk is used by default. This issue caused killsnoop can't work on Ubuntu by default. There are two issues, a. The strtonum is not supported by mawk. Try to use int to convert string to number. For gawk, int usage need the --non-decimal-data option. On very old RHEL release(2.6.18 kernel), the gawk can support this option. b. killsnoop still has no results due to mawk buffering porblems. Using -W interactive could solve this isue. The option is available on mawk 1.2, RHEL 4+ should support it. Signed-off-by: Oliver Yang <[email protected]>
1 parent 27d206f commit a52538f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

killsnoop

+8-5
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,11 @@ else
131131
fi
132132

133133
### select awk
134-
(( opt_duration )) && use=mawk || use=gawk # workaround for mawk fflush()
135-
[[ -x /usr/bin/$use ]] && awk=$use || awk=awk
134+
# workaround for mawk fflush()
135+
[[ -x /usr/bin/mawk ]] && awk="mawk" && mawk -W interactive && \
136+
[ $? -eq 0 ] && awk="mawk -W interactive"
137+
# workaround for gawk strtonum()
138+
[[ -x /usr/bin/gawk ]] && awk="gawk --non-decimal-data"
136139

137140
### check permissions
138141
cd $tracing || die "ERROR: accessing tracing. Root user? Kernel has FTRACE?
@@ -219,15 +222,15 @@ fi ) | $awk -v o=$offset -v opt_name=$opt_name -v name=$name \
219222
signal = $(7+o)
220223
sub(/,$/, "", kpid)
221224
sub(/\)$/, "", signal)
222-
kpid = strtonum("0x"kpid)
223-
signal = strtonum("0x"signal)
225+
kpid = int("0x"kpid)
226+
signal = int("0x"signal)
224227
current[pid,"kpid"] = kpid
225228
current[pid,"signal"] = signal
226229
}
227230
228231
# sys_kill exit
229232
$1 != "#" && $(5+o) ~ /->/ {
230-
rv = strtonum($NF)
233+
rv = int($NF)
231234
killed_pid = current[pid,"kpid"]
232235
signal = current[pid,"signal"]
233236

0 commit comments

Comments
 (0)