Skip to content

Commit b26e26b

Browse files
jaycecaoyonghong-song
authored andcommitted
fix iovisor#1851 for Arch Linux users (iovisor#2214)
* fix iovisor#1851 for Arch Linux users
1 parent bc0d472 commit b26e26b

File tree

3 files changed

+38
-2
lines changed

3 files changed

+38
-2
lines changed

Diff for: man/man8/bashreadline.8

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
.SH NAME
33
bashreadline \- Print entered bash commands system wide. Uses Linux eBPF/bcc.
44
.SH SYNOPSIS
5-
.B bashreadline
5+
.B bashreadline [\-h] [\-s SHARED]
66
.SH DESCRIPTION
77
bashreadline traces the return of the readline() function using uprobes, to
88
show the bash commands that were entered interactively, system wide. The
@@ -17,6 +17,15 @@ which uses an older mechanism
1717
Since this uses BPF, only the root user can use this tool.
1818
.SH REQUIREMENTS
1919
CONFIG_BPF and bcc.
20+
.SH OPTIONS
21+
.TP
22+
\-h
23+
Print usage message.
24+
.TP
25+
\-s
26+
Specify the location of libreadline.so shared library when you failed to run the
27+
script directly with error: "Exception: could not determine address of symbol
28+
\'readline\'". Default value is /lib/libreadline.so.
2029
.SH EXAMPLES
2130
.TP
2231
Trace bash commands system wide:

Diff for: tools/bashreadline.py

+18-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
# bashreadline Print entered bash commands from all running shells.
44
# For Linux, uses BCC, eBPF. Embedded C.
55
#
6+
# USAGE: bashreadline [-s SHARED]
67
# This works by tracing the readline() function using a uretprobe (uprobes).
8+
# When you failed to run the script directly with error:
9+
# `Exception: could not determine address of symbol b'readline'`,
10+
# you may need specify the location of libreadline.so library
11+
# with `-s` option.
712
#
813
# Copyright 2016 Netflix, Inc.
914
# Licensed under the Apache License, Version 2.0 (the "License")
@@ -14,6 +19,18 @@
1419
from __future__ import print_function
1520
from bcc import BPF
1621
from time import strftime
22+
import argparse
23+
24+
parser = argparse.ArgumentParser(
25+
description="Print entered bash commands from all running shells",
26+
formatter_class=argparse.RawDescriptionHelpFormatter)
27+
parser.add_argument("-s", "--shared", nargs="?",
28+
const="/lib/libreadline.so", type=str,
29+
help="specify the location of libreadline.so library.\
30+
Default is /lib/libreadline.so")
31+
args = parser.parse_args()
32+
33+
name = args.shared if args.shared else "/bin/bash"
1734

1835
# load BPF program
1936
bpf_text = """
@@ -41,7 +58,7 @@
4158
"""
4259

4360
b = BPF(text=bpf_text)
44-
b.attach_uretprobe(name="/bin/bash", sym="readline", fn_name="printret")
61+
b.attach_uretprobe(name=name, sym="readline", fn_name="printret")
4562

4663
# header
4764
print("%-9s %-6s %s" % ("TIME", "PID", "COMMAND"))

Diff for: tools/bashreadline_example.txt

+10
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ TIME PID COMMAND
1414
05:29:04 3059 echo another shell
1515
05:29:13 21176 echo first shell again
1616

17+
When running the script on Arch Linux, you may need to specify the location
18+
of libreadline.so library:
19+
20+
# ./bashreadline -s /lib/libreadline.so
21+
TIME PID COMMAND
22+
11:17:34 28796 whoami
23+
11:17:41 28796 ps -ef
24+
11:17:51 28796 echo "Hello eBPF!"
25+
26+
1727
The entered command may fail. This is just showing what command lines were
1828
entered interactively for bash to process.
1929

0 commit comments

Comments
 (0)