Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
B
bpftrace
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
bpftrace
Commits
2ced3ad2
Commit
2ced3ad2
authored
Apr 29, 2018
by
Alastair Robertson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prog load: Try using LINUX_VERSION_CODE before reading from uname
parent
a2a689b4
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
10 deletions
+35
-10
src/attached_probe.cpp
src/attached_probe.cpp
+35
-10
No files found.
src/attached_probe.cpp
View file @
2ced3ad2
#include <fcntl.h>
#include <iostream>
#include <regex>
#include <sys/utsname.h>
...
...
@@ -9,6 +10,7 @@
#include "common.h"
#include "libbpf.h"
#include <linux/perf_event.h>
#include <linux/version.h>
namespace
bpftrace
{
...
...
@@ -148,13 +150,19 @@ uint64_t AttachedProbe::offset() const
return
sym
.
offset
;
}
static
unsigned
kernel_version
()
static
unsigned
kernel_version
(
int
attempt
)
{
switch
(
attempt
)
{
case
0
:
return
LINUX_VERSION_CODE
;
case
1
:
struct
utsname
utsname
;
uname
(
&
utsname
);
unsigned
x
,
y
,
z
;
sscanf
(
utsname
.
release
,
"%d.%d.%d"
,
&
x
,
&
y
,
&
z
);
return
(
x
<<
16
)
+
(
y
<<
8
)
+
z
;
}
}
void
AttachedProbe
::
load_prog
()
...
...
@@ -162,14 +170,31 @@ void AttachedProbe::load_prog()
uint8_t
*
insns
=
std
::
get
<
0
>
(
func_
);
int
prog_len
=
std
::
get
<
1
>
(
func_
);
const
char
*
license
=
"GPL"
;
unsigned
kern_version
=
kernel_version
();
int
log_level
=
0
;
char
*
log_buf
=
nullptr
;
unsigned
log_buf_size
=
0
;
// Redirect stderr, so we don't get error messages from BCC
int
old_stderr
,
new_stderr
;
fflush
(
stderr
);
old_stderr
=
dup
(
2
);
new_stderr
=
open
(
"/dev/null"
,
O_WRONLY
);
dup2
(
new_stderr
,
2
);
close
(
new_stderr
);
for
(
int
attempt
=
0
;
attempt
<
2
;
attempt
++
)
{
progfd_
=
bpf_prog_load
(
progtype
(
probe_
.
type
),
probe_
.
name
.
c_str
(),
reinterpret_cast
<
struct
bpf_insn
*>
(
insns
),
prog_len
,
license
,
kern_version
,
log_level
,
log_buf
,
log_buf_size
);
reinterpret_cast
<
struct
bpf_insn
*>
(
insns
),
prog_len
,
license
,
kernel_version
(
attempt
),
log_level
,
log_buf
,
log_buf_size
);
if
(
progfd_
>=
0
)
break
;
}
// Restore stderr
fflush
(
stderr
);
dup2
(
old_stderr
,
2
);
close
(
old_stderr
);
if
(
progfd_
<
0
)
throw
std
::
runtime_error
(
"Error loading program: "
+
probe_
.
name
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment