You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2024/03/22 00:05:00 UTC
(mesos) branch master updated: [cgroups2] Fix controllers::enable/available empty handling.
This is an automated email from the ASF dual-hosted git repository.
bmahler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mesos.git
The following commit(s) were added to refs/heads/master by this push:
new 0aa65cd70 [cgroups2] Fix controllers::enable/available empty handling.
0aa65cd70 is described below
commit 0aa65cd70aeee5c12e01ce3958dae849039aa47d
Author: Devin Leamy <dl...@twitter.com>
AuthorDate: Thu Mar 21 19:44:02 2024 -0400
[cgroups2] Fix controllers::enable/available empty handling.
"cgroup.controllers" and "cgroup.subtree_control" control files can be empty,
in which case `strings::split(s, " ")` returns `[""]` which causes us to use
an empty string for a controller.
This closes #530
---
src/linux/cgroups2.cpp | 23 ++++++++++++++++++-----
1 file changed, 18 insertions(+), 5 deletions(-)
diff --git a/src/linux/cgroups2.cpp b/src/linux/cgroups2.cpp
index 7e1a801a3..c2892f544 100644
--- a/src/linux/cgroups2.cpp
+++ b/src/linux/cgroups2.cpp
@@ -115,7 +115,14 @@ struct State
static State parse(const string& contents)
{
State control;
- vector<string> controllers = strings::split(contents, " ");
+
+ // Trim trailing newline.
+ const string trimmed = strings::trim(contents);
+ if (trimmed.empty()) {
+ return control;
+ }
+
+ vector<string> controllers = strings::split(trimmed, " ");
control._enabled.insert(
std::make_move_iterator(controllers.begin()),
std::make_move_iterator(controllers.end()));
@@ -359,15 +366,21 @@ namespace controllers {
Try<set<string>> available(const string& cgroup)
{
- Try<string> contents =
+ Try<string> read =
cgroups2::read<string>(cgroup, cgroups2::control::CONTROLLERS);
- if (contents.isError()) {
+ if (read.isError()) {
return Error("Failed to read cgroup.controllers in '" + cgroup + "': "
- + contents.error());
+ + read.error());
+ }
+
+ // Trim trailing newline.
+ const string contents = strings::trim(*read);
+ if (contents.empty()) {
+ return set<string>();
}
- vector<string> controllers = strings::split(*contents, " ");
+ vector<string> controllers = strings::split(contents, " ");
return set<string>(
std::make_move_iterator(controllers.begin()),
std::make_move_iterator(controllers.end()));