-
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
Conversation
@LucaGuerra thank you very much for starting this PR! Continued a bit. openat* filtercheck was a quick fix. Then there were issues with
Seems to be fixed now as well at least on my fedora box. EDIT: Re the previous unit test failures because of inconsistent handling of |
c26a7d6
to
94b1f33
Compare
Since we introduced std::filesystem for the newer
When the path is relative, everything matches:
But there is a mismatch when the path is absolute:
CC @mstemm |
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.
Just a few comments. I'm not approving for the moment as I see it is WIP, but I don't see major issues.
userspace/libsinsp/threadinfo.cpp
Outdated
uint32_t size = tinfo->m_cwd.size(); | ||
|
||
if(size == 0 || (tinfo->m_cwd[size - 1] != '/')) | ||
if(len == 0 || (tinfo->m_cwd[len - 1] != '/')) |
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.
No need for len
.
if(len == 0 || (tinfo->m_cwd[len - 1] != '/')) | |
if(tinfo->m_cwd.empty() || tinfo->m_cwd.back() != '/')) |
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.
That's better, after you respond to above's comment I can rewind the last 2 commits.
@@ -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 comment
The 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
I was only curious. I understand this would be a larger change.
I think we can at least move it out of wip? |
We still have an unrelated windows CI failure. |
12a686e
to
62a8f99
Compare
EXPECT_EQ("/app", res); | ||
|
||
path1 = "/root/"; | ||
path2 = "../😉"; |
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.
Additional note: @mstemm fs.path.*
also doesn't do any sanitation in case we are interested in equalizing fd.name
and fs.path.name
in the future.
Thank you all for the reviews! I'm going through all comments and the Windows + shared libs failure to get this in a mergeable state :) |
So the Windows failure is kind of expected, and it's a problem. This is because we are hitting a problem that I did not consider earlier: STL will interpret paths in different ways depending on the platform. This is actually documented: https://en.cppreference.com/w/cpp/filesystem/path . The problem is that Windows has a concept of I think this is not acceptable in the current situation, so I thought about three solutions:
I'm thinking about trying to find a simple library that can solve our issues without having to have a custom algorithm here. |
While I honor us supporting multi-platform for scap files and plugins, I don't think this should sacrifice the primary Linux syscalls monitoring, plus we already use std::filesystem for |
Since we are already using |
299af28
to
3eae1ad
Compare
Signed-off-by: Luca Guerra <[email protected]>
Signed-off-by: Melissa Kilby <[email protected]>
Signed-off-by: Melissa Kilby <[email protected]>
Signed-off-by: Melissa Kilby <[email protected]>
Co-authored-by: Federico Aponte <[email protected]> Signed-off-by: Melissa Kilby <[email protected]>
Co-authored-by: Nathan Baker <[email protected]> Signed-off-by: Melissa Kilby <[email protected]>
…e etc Signed-off-by: Melissa Kilby <[email protected]>
…clarify output Signed-off-by: Luca Guerra <[email protected]>
Signed-off-by: Luca Guerra <[email protected]>
3eae1ad
to
b02351f
Compare
Signed-off-by: Luca Guerra <[email protected]>
b02351f
to
217bcee
Compare
@incertum @federico-sysdig I ended up implementing the workaround. All tests are passing including the corner cases we identified. It's not the best but it will do. Also, the |
Thanks a bunch @LucaGuerra LGTM! @federico-sysdig could we get another review pass from you, ty! 🙏 |
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.
lgtm, just nits that can be read, understood, and ignored
@@ -4470,14 +4447,12 @@ void sinsp_parser::parse_getcwd_exit(sinsp_evt *evt) | |||
return; | |||
} | |||
|
|||
parinfo = evt->get_param(1); | |||
std::string cwd = std::string(evt->get_param(1)->as<std::string_view>()); |
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.
std::string cwd(evt->get_param(1)->as<std::string_view>());
@@ -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 comment
The 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>();
@federico-sysdig: changing LGTM is restricted to collaborators In response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
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.
Since I also contributed my
/approve
is on behalf of @federico-sysdig, thanks a bunch for your help!
LGTM label has been added. Git tree hash: 0765025267b638a9aa0f633d3a07676a22268a64
|
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.
/approve
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Andreagit97, federico-sysdig, incertum, LucaGuerra The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
What type of PR is this?
/kind bug
/kind cleanup
Any specific area of the project related to this PR?
/area libsinsp
/area tests
Does this PR require a change in the driver versions?
No
What this PR does / why we need it:
This gets rid of a scary function that was operating on path strings by hand and is prone to breakage or (worse) memory error issues and replaces with a native C++ implementation.
@incertum I still have a failing test and I would like to be more certain of when we depend on specific behaviors in libs before I go through. Can you take a look? Thanks!
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Does this PR introduce a user-facing change?: