Skip to content

Conversation

@thisptr-hub
Copy link
Contributor

When using CentOS 9 I encountered cgroup paths with colons for multiple Gnome apps:

Unexpected tokens count [0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-dbus\x2d:1.2\x2dorg.gnome.OnlineAccounts.slice/dbus-:1.2-org.gnome.OnlineAccounts@0.service] Unexpected tokens count [0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-dbus\x2d:1.2\x2dorg.gnome.Identity.slice/dbus-:1.2-org.gnome.Identity@0.service] Unexpected tokens count [0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-dbus\x2d:1.2\x2dorg.gnome.Shell.Notifications.slice/dbus-:1.2-org.gnome.Shell.Notifications@0.service] Unexpected tokens count [0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-dbus\x2d:1.21\x2dorg.a11y.atspi.Registry.slice/dbus-:1.21-org.a11y.atspi.Registry@0.service] Unexpected tokens count [0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-dbus\x2d:1.2\x2dorg.gnome.ScreenSaver.slice/dbus-:1.2-org.gnome.ScreenSaver@0.service] Unexpected tokens count [0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-dbus\x2d:1.2\x2dorg.freedesktop.portal.IBus.slice/dbus-:1.2-org.freedesktop.portal.IBus@0.service] Unexpected tokens count [0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-dbus\x2d:1.2\x2dorg.gnome.Shell.CalendarServer.slice/dbus-:1.2-org.gnome.Shell.CalendarServer@0.service] Unexpected tokens count [0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-dbus\x2d:1.2\x2dorg.gnome.OnlineAccounts.slice/dbus-:1.2-org.gnome.OnlineAccounts@0.service] Unexpected tokens count [0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-dbus\x2d:1.2\x2dorg.gnome.Identity.slice/dbus-:1.2-org.gnome.Identity@0.service] Unexpected tokens count [0::/user.slice/user-1000.slice/user@1000.service/app.slice/app-dbus\x2d:1.2\x2dorg.gnome.Shell.Notifications.slice/dbus-:1.2-org.gnome.Shell.Notifications@0.service] 

this pull request prevents errors when encountering cgroup paths with colons in them

@thisptr-hub
Copy link
Contributor Author

@dtrugman could you have a look any time soon?

@dtrugman
Copy link
Owner

dtrugman commented Sep 5, 2025

Thanks for the comment. Managed to miss this.
Taking a look!

src/utils.cpp Outdated
size_t index = buffer.find(delim, curr);
if (index == std::string::npos)
{
out.emplace_back(buffer.substr(curr));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid the extra copy by passing the iterators directly? Something like this should work

out.emplace_back(buffer.begin() + curr, buffer.begin() + index); 
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed but the resulting string will be moved so there is no extra copy, so performance gain is hardly noticeable while readability is decreased

return out;
}

std::pair<std::string, std::string> split_once(const std::string& buffer,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's update this implementation to use split_times?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

split_once always returns 2 elements, even if there is no delimiter. split_times returns 1 element if there is no delimiter.

{
std::string input;
std::vector<std::string> tokens;
char delim = ' ';
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should not have a default value, same as times.
every test should set those.

Copy link
Contributor Author

@thisptr-hub thisptr-hub Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't mind removing the default value, but this will generate the uninitialized warning and setting default values for the variables of basic types is consistent with other tests in this file.

times = 1;
}

REQUIRE(split_times(input, delim, times) == tokens);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] let's extract the method call out of the REQUIRE clause

tokens = split_times(input, delim, times) 
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doesn't make a difference for me, but in most tests here the method call is within the REQUIRE clause

TEST_CASE("Split times", "[utils]")
{
std::string input;
std::vector<std::string> tokens;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's call this expected?


auto tokens = utils::split(line, DELIM, /* keep_empty = */ true);
if (tokens.size() != COUNT)
auto tokens = utils::split_times(line, DELIM, COUNT - 1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[comment belongs to line 42]
Let's add an example where this actually matters?


auto tokens = utils::split(line, DELIM, /* keep_empty = */ true);
if (tokens.size() != COUNT)
auto tokens = utils::split_times(line, DELIM, COUNT - 1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add a comment here clearly explaining why we use split_times(..., COUNT - 1) split here instead of split.

auto tokens = utils::split(line, DELIM, /* keep_empty = */ true);
if (tokens.size() != COUNT)
auto tokens = utils::split_times(line, DELIM, COUNT - 1);
if (tokens.size() < COUNT)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can never happen, right? So we should remove this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean it can't happen from C++ perspective or from Linux perspective? From C++ perspective it can definitely happen because split_times can return less (but not more) than COUNT elements. From Linux perspective it shouldn't but this might change or there can be some case which we didn't account for

@dtrugman
Copy link
Owner

dtrugman commented Sep 5, 2025

Thanks for the PR @thisptr-hub !

@thisptr-hub
Copy link
Contributor Author

thisptr-hub commented Sep 22, 2025

@dtrugman thanks a lot for the review! Sorry it took me so long, but I addressed some of the review comments and responded to the others so please take another look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants