summaryrefslogtreecommitdiffhomepage
path: root/test/util/cgroup_util.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/util/cgroup_util.cc')
-rw-r--r--test/util/cgroup_util.cc13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/util/cgroup_util.cc b/test/util/cgroup_util.cc
index 65d9c4986..d8d3fe471 100644
--- a/test/util/cgroup_util.cc
+++ b/test/util/cgroup_util.cc
@@ -17,6 +17,7 @@
#include <sys/syscall.h>
#include <unistd.h>
+#include "absl/strings/str_cat.h"
#include "absl/strings/str_split.h"
#include "test/util/fs_util.h"
#include "test/util/mount_util.h"
@@ -50,6 +51,18 @@ PosixErrorOr<int64_t> Cgroup::ReadIntegerControlFile(
return val;
}
+PosixError Cgroup::WriteControlFile(absl::string_view name,
+ const std::string& value) const {
+ ASSIGN_OR_RETURN_ERRNO(FileDescriptor fd, Open(Relpath(name), O_WRONLY));
+ RETURN_ERROR_IF_SYSCALL_FAIL(WriteFd(fd.get(), value.c_str(), value.size()));
+ return NoError();
+}
+
+PosixError Cgroup::WriteIntegerControlFile(absl::string_view name,
+ int64_t value) const {
+ return WriteControlFile(name, absl::StrCat(value));
+}
+
PosixErrorOr<absl::flat_hash_set<pid_t>> Cgroup::Procs() const {
ASSIGN_OR_RETURN_ERRNO(std::string buf, ReadControlFile("cgroup.procs"));
return ParsePIDList(buf);