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
fa924dce
Commit
fa924dce
authored
Jun 13, 2018
by
Alastair Robertson
Committed by
GitHub
Jun 13, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #46 from xbe/kernel-version
Add ability to get kernel version from header at runtime
parents
641f6373
e49eb33e
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
2 deletions
+19
-2
src/attached_probe.cpp
src/attached_probe.cpp
+19
-2
No files found.
src/attached_probe.cpp
View file @
fa924dce
#include <fcntl.h>
#include <fstream>
#include <iostream>
#include <regex>
#include <sys/utsname.h>
...
...
@@ -161,7 +162,23 @@ static unsigned kernel_version(int attempt)
uname
(
&
utsname
);
unsigned
x
,
y
,
z
;
sscanf
(
utsname
.
release
,
"%d.%d.%d"
,
&
x
,
&
y
,
&
z
);
return
(
x
<<
16
)
+
(
y
<<
8
)
+
z
;
return
KERNEL_VERSION
(
x
,
y
,
z
);
case
2
:
// try to get the definition of LINUX_VERSION_CODE at runtime.
// needed if bpftrace is compiled on a different linux version than it's used on.
// e.g. if built with docker.
// the reason case 0 doesn't work for this is because it uses the preprocessor directive,
// which is by definition a compile-time constant
std
::
ifstream
linux_version_header
{
"/usr/include/linux/version.h"
};
const
std
::
string
content
{
std
::
istreambuf_iterator
<
char
>
(
linux_version_header
),
std
::
istreambuf_iterator
<
char
>
()};
const
std
::
regex
regex
{
"#define
\\
s+LINUX_VERSION_CODE
\\
s+(
\\
d+)"
};
std
::
smatch
match
;
if
(
std
::
regex_search
(
content
.
begin
(),
content
.
end
(),
match
,
regex
))
return
static_cast
<
unsigned
>
(
std
::
stoi
(
match
[
1
]));
return
0
;
}
}
...
...
@@ -182,7 +199,7 @@ void AttachedProbe::load_prog()
dup2
(
new_stderr
,
2
);
close
(
new_stderr
);
for
(
int
attempt
=
0
;
attempt
<
2
;
attempt
++
)
for
(
int
attempt
=
0
;
attempt
<
3
;
attempt
++
)
{
progfd_
=
bpf_prog_load
(
progtype
(
probe_
.
type
),
probe_
.
name
.
c_str
(),
reinterpret_cast
<
struct
bpf_insn
*>
(
insns
),
prog_len
,
license
,
...
...
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