annotate dep/animone/src/fd/proc.cc @ 367:8d45d892be88 default tip

*: instead of pugixml, use Qt XML features this means we have one extra Qt dependency though...
author Paper <paper@tflc.us>
date Sun, 17 Nov 2024 22:55:47 -0500
parents f81bed4e04ac
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
310
a4257370de16 dep/animone: prepare for v1.0 release; it should be ready by now
Paper <paper@paper.us.eu.org>
parents: 309
diff changeset
1 /*
a4257370de16 dep/animone: prepare for v1.0 release; it should be ready by now
Paper <paper@paper.us.eu.org>
parents: 309
diff changeset
2 * fd/win32.cc: support for linux's /proc filesystem
a4257370de16 dep/animone: prepare for v1.0 release; it should be ready by now
Paper <paper@paper.us.eu.org>
parents: 309
diff changeset
3 *
a4257370de16 dep/animone: prepare for v1.0 release; it should be ready by now
Paper <paper@paper.us.eu.org>
parents: 309
diff changeset
4 * plan 9 caused this monstrocity...
a4257370de16 dep/animone: prepare for v1.0 release; it should be ready by now
Paper <paper@paper.us.eu.org>
parents: 309
diff changeset
5 */
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
6 #include "animone/fd/proc.h"
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
7 #include "animone.h"
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
8 #include "animone/util.h"
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
9
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
10 #include <filesystem>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
11 #include <fstream>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
12 #include <sstream>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
13 #include <string>
309
bf89fbf7ff38 misc: remove copyrighted app icon
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
14 #include <algorithm>
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
15
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
16 #include <fcntl.h>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
17 #include <sys/stat.h>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
18 #include <unistd.h>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
19
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
20 static constexpr std::string_view PROC_LOCATION = "/proc";
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
21
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
22 namespace animone::internal::proc {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
23
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
24 struct Fdinfo {
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
25 bool Parse(std::istream& istr);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
26 std::unordered_map<std::string, std::string> data;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
27 };
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
28
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
29 bool Fdinfo::Parse(std::istream& istr) {
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
30 /* shift to the start of the stream */
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
31 istr.seekg(0);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
32
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
33 for (std::string line; std::getline(istr, line); ) {
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
34 if (line.empty()) /* huh? */
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
35 continue;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
36
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
37 std::size_t colon = line.find(':');
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
38 if (colon == std::string::npos)
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
39 return false;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
40
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
41 std::string key = line.substr(0, colon);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
42 std::string value = line.substr(colon + 1);
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
43 util::TrimLeft(value, " ");
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
44
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
45 data[key] = value;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
46 }
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
47
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
48 return true;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
49 }
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
50
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
51 static bool IsRegularFile(const std::string& link) {
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
52 struct stat sb;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
53 if (stat(link.c_str(), &sb) == -1)
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
54 return false;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
55
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
56 return S_ISREG(sb.st_mode);
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
57 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
58
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
59 static bool AreFlagsOk(pid_t pid, int fd) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
60 const std::filesystem::path path =
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
61 std::filesystem::path(PROC_LOCATION) / std::to_string(pid) / "fdinfo" / std::to_string(fd);
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
62
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
63 std::ifstream file(path);
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
64 if (!file)
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
65 return false;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
66
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
67 Fdinfo fdinfo;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
68 if (!fdinfo.Parse(file))
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
69 return false;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
70
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
71 if (fdinfo.data.find("flags") == fdinfo.data.end())
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
72 return false;
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
73
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
74 /* check if the file was opened in a write mode */
365
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
75 try {
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
76 const long long accflags = std::stoll(fdinfo.data["flags"]) & O_ACCMODE;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
77
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
78 if (accflags == O_WRONLY || accflags == O_RDWR)
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
79 return false;
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
80 } catch (const std::exception& ex) {
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
81 return false; /* huh ? */
f81bed4e04ac *: megacommit that probably breaks things
Paper <paper@paper.us.eu.org>
parents: 337
diff changeset
82 }
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
83
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
84 return true;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
85 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
86
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
87 static bool GetFilenameFromFd(std::string link, std::string& out) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
88 /* /proc is a "virtual filesystem", so we have to guess the path size. yippee! */
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
89 constexpr size_t OUT_MAX = (1ul << 15); // 32KiB
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
90 out.resize(32);
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
91
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
92 ssize_t exe_used = 0;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
93 do {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
94 out.resize(out.length() * 2);
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
95
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
96 exe_used = readlink(link.c_str(), &out.front(), out.length());
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
97 if (exe_used == (ssize_t)-1 || exe_used < (ssize_t)1)
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
98 return false; // we got a bad result. SAD!
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
99 } while (out.length() < OUT_MAX && exe_used >= static_cast<ssize_t>(out.length()));
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
100
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
101 out.resize(out.find('\0'));
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
102
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
103 return true;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
104 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
105
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
106 static bool IsSystemFile(const std::string& path) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
107 static constexpr std::array<std::string_view, 9> invalid_paths = {"/boot", "/dev", "/bin", "/usr", "/opt",
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
108 "/proc", "/var", "/etc", "/dev"};
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
109
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
110 for (const auto& invalid_path : invalid_paths)
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
111 if (!path.rfind(invalid_path, 0))
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
112 return true;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
113
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
114 return false;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
115 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
116
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
117 bool GetProcessName(pid_t pid, std::string& result) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
118 const std::filesystem::path path = std::filesystem::path(PROC_LOCATION) / std::to_string(pid) / "comm";
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
119
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
120 if (!util::ReadFile(path, result))
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
121 return false;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
122
309
bf89fbf7ff38 misc: remove copyrighted app icon
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
123 result.erase(std::remove(result.begin(), result.end(), '\n'), result.cend());
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
124 return true;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
125 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
126
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
127 bool EnumerateOpenProcesses(process_proc_t process_proc) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
128 bool success = false;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
129
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
130 for (const auto& dir : std::filesystem::directory_iterator{PROC_LOCATION}) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
131 Process proc;
337
a7d4e5107531 dep/animone: REFACTOR ALL THE THINGS
Paper <paper@paper.us.eu.org>
parents: 310
diff changeset
132 proc.platform = ExecutablePlatform::Posix;
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
133
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
134 try {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
135 proc.pid = util::StringToInt(dir.path().stem());
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
136 success = true;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
137 } catch (std::invalid_argument const& ex) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
138 continue;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
139 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
140
337
a7d4e5107531 dep/animone: REFACTOR ALL THE THINGS
Paper <paper@paper.us.eu.org>
parents: 310
diff changeset
141 if (!GetProcessName(proc.pid, proc.comm))
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
142 continue;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
143
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
144 if (!process_proc(proc))
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
145 return false;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
146 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
147
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
148 return success;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
149 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
150
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
151 bool EnumerateOpenFiles(const std::set<pid_t>& pids, open_file_proc_t open_file_proc) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
152 if (!open_file_proc)
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
153 return false;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
154
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
155 for (const auto& pid : pids) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
156 const std::filesystem::path path = std::filesystem::path(PROC_LOCATION) / std::to_string(pid) / "fd";
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
157
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
158 for (const auto& dir : std::filesystem::directory_iterator{path}) {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
159 if (!AreFlagsOk(pid, util::StringToInt(dir.path().stem())))
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
160 continue;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
161
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
162 std::string name;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
163 if (!GetFilenameFromFd(dir.path(), name))
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
164 continue;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
165
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
166 if (!IsRegularFile(name))
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
167 continue;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
168
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
169 if (IsSystemFile(name))
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
170 continue;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
171
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
172 if (!open_file_proc({pid, name}))
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
173 return false;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
174 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
175 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
176 return true;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
177 }
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
178
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 270
diff changeset
179 } // namespace animia::internal::proc