-
Notifications
You must be signed in to change notification settings - Fork 171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor(libsinsp): rewrite concatenate_paths with std::filesystem #1533
Changes from all commits
c8d86eb
6c129a3
35f3b60
31d4a9f
20b253f
61a0f9a
1d03301
640d945
13cd8a2
217bcee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -439,8 +439,7 @@ uint8_t* extract_argraw(sinsp_evt *evt, OUT uint32_t* len, const char *argname) | |
|
||
uint8_t *sinsp_filter_check_event::extract_abspath(sinsp_evt *evt, OUT uint32_t *len) | ||
{ | ||
const sinsp_evt_param *parinfo; | ||
string spath; | ||
std::string spath; | ||
|
||
if(evt->m_tinfo == NULL) | ||
{ | ||
|
@@ -476,7 +475,7 @@ uint8_t *sinsp_filter_check_event::extract_abspath(sinsp_evt *evt, OUT uint32_t | |
else if(etype == PPME_SYSCALL_OPEN_BY_HANDLE_AT_X) | ||
{ | ||
int fd = 0; | ||
char fullname[SCAP_MAX_PATH_SIZE]; | ||
std::string fullname; | ||
|
||
// | ||
// We can extract the file path only in case of a successful file opening (fd>0). | ||
|
@@ -488,12 +487,8 @@ uint8_t *sinsp_filter_check_event::extract_abspath(sinsp_evt *evt, OUT uint32_t | |
// | ||
// Get the file path directly from the ring buffer. | ||
// | ||
parinfo = evt->get_param(3); | ||
m_strstorage = sinsp_utils::concatenate_paths("", evt->get_param(3)->as<std::string_view>()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why concatenate when one item is an empty path? Is it because the function enforces a final slash? If so, wouldn't it be better to put the slash when the path is finally used for its purpose? I know this logic was already there, but it seems a lot of work to check the path at any point it is manipulated when it could be done only once at the final step. End of rant. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It also does the directory traversal if applicable. We wouldn't need this here? for this one perhaps let's do a 2 step, first get this one in, before risking breaking things and take the time to check more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was only curious. I understand this would be a larger change. |
||
|
||
sinsp_utils::concatenate_paths(fullname, SCAP_MAX_PATH_SIZE, "", 0, | ||
parinfo->m_val, parinfo->m_len); | ||
|
||
m_strstorage = fullname; | ||
RETURN_EXTRACT_STRING(m_strstorage); | ||
} | ||
} | ||
|
@@ -598,11 +593,7 @@ uint8_t *sinsp_filter_check_event::extract_abspath(sinsp_evt *evt, OUT uint32_t | |
} | ||
} | ||
|
||
char fullname[SCAP_MAX_PATH_SIZE]; | ||
sinsp_utils::concatenate_paths(fullname, SCAP_MAX_PATH_SIZE, sdir.c_str(), | ||
(uint32_t)sdir.length(), path.data(), path.size()); | ||
|
||
m_strstorage = fullname; | ||
m_strstorage = sinsp_utils::concatenate_paths(sdir, path); | ||
|
||
RETURN_EXTRACT_STRING(m_strstorage); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,9 +214,7 @@ bool sinsp_filter_check_fd::extract_fdname_from_creator(sinsp_evt *evt, OUT uint | |
{ | ||
sinsp_evt enter_evt; | ||
const sinsp_evt_param *parinfo; | ||
const char *name; | ||
uint32_t namelen; | ||
string sdir; | ||
std::string sdir; | ||
|
||
if(etype == PPME_SYSCALL_OPENAT_X) | ||
{ | ||
|
@@ -232,30 +230,21 @@ bool sinsp_filter_check_fd::extract_fdname_from_creator(sinsp_evt *evt, OUT uint | |
} | ||
|
||
parinfo = etype == PPME_SYSCALL_OPENAT_X ? enter_evt.get_param(1) : evt->get_param(2); | ||
name = parinfo->m_val; | ||
namelen = parinfo->m_len; | ||
std::string_view name = parinfo->as<std::string_view>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Perhaps we can avoid repeating the type in this kind of definitions as it is already on the RHS. Just a thought for the future. Leave it as it is for the moment. auto name = parinfo->as<std::string_view>(); |
||
|
||
parinfo = etype == PPME_SYSCALL_OPENAT_X ? enter_evt.get_param(0) : evt->get_param(1); | ||
ASSERT(parinfo->m_len == sizeof(int64_t)); | ||
int64_t dirfd = *(int64_t *)parinfo->m_val; | ||
int64_t dirfd = parinfo->as<int64_t>(); | ||
|
||
sinsp_parser::parse_dirfd(evt, name, dirfd, &sdir); | ||
|
||
char fullpath[SCAP_MAX_PATH_SIZE]; | ||
|
||
sinsp_utils::concatenate_paths(fullpath, SCAP_MAX_PATH_SIZE, | ||
sdir.c_str(), | ||
(uint32_t)sdir.length(), | ||
name, | ||
namelen); | ||
sinsp_parser::parse_dirfd(evt, name.data(), dirfd, &sdir); | ||
|
||
if(fd_nameraw) | ||
{ | ||
m_tstr = name; | ||
} | ||
else | ||
{ | ||
m_tstr = fullpath; | ||
// fullpath | ||
m_tstr = sinsp_utils::concatenate_paths(sdir, name); // here we'd like a string | ||
} | ||
|
||
if(sanitize_strings) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: the type name need not be repeated. Just noticed, but it can be left as it is.