File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change @@ -70,13 +70,24 @@ StatusOr<std::vector<std::string>> CGroupBasePaths(std::string_view sysfs_path)
7070
7171StatusOr<std::string> FindSelfCGroupProcs (std::string_view base_path) {
7272 int pid = getpid ();
73+ std::error_code ec;
7374
74- for (auto & p : std::filesystem::recursive_directory_iterator (base_path)) {
75- if (p.path ().filename () == " cgroup.procs" ) {
76- std::string contents = ReadFileToString (p.path ().string ()).ValueOr (" " );
75+ auto it = std::filesystem::recursive_directory_iterator (
76+ base_path, std::filesystem::directory_options::skip_permission_denied, ec);
77+ if (ec) {
78+ return error::Internal (" Failed to iterate cgroup path: $0" , ec.message ());
79+ }
80+
81+ for (auto end = std::filesystem::recursive_directory_iterator (); it != end; it.increment (ec)) {
82+ if (ec) {
83+ ec.clear ();
84+ continue ;
85+ }
86+ if (it->path ().filename () == " cgroup.procs" ) {
87+ std::string contents = ReadFileToString (it->path ().string ()).ValueOr (" " );
7788 int contents_pid;
7889 if (absl::SimpleAtoi (contents, &contents_pid) && pid == contents_pid) {
79- return p. path ().string ();
90+ return it-> path ().string ();
8091 }
8192 }
8293 }
You can’t perform that action at this time.
0 commit comments