@@ -56,23 +56,25 @@ struct ProcessInfo {
56
56
};
57
57
58
58
// Parse the contents of /proc/<tid>/status into |process_info|.
59
- bool GetProcessInfo (pid_t tid, ProcessInfo* process_info);
59
+ bool GetProcessInfo (pid_t tid, ProcessInfo* process_info, std::string* error = nullptr );
60
60
61
61
// Parse the contents of <fd>/status into |process_info|.
62
62
// |fd| should be an fd pointing at a /proc/<pid> directory.
63
- bool GetProcessInfoFromProcPidFd (int fd, ProcessInfo* process_info);
63
+ bool GetProcessInfoFromProcPidFd (int fd, ProcessInfo* process_info, std::string* error = nullptr );
64
64
65
65
// Fetch the list of threads from a given process's /proc/<pid> directory.
66
66
// |fd| should be an fd pointing at a /proc/<pid> directory.
67
67
template <typename Collection>
68
- auto GetProcessTidsFromProcPidFd (int fd, Collection* out) ->
68
+ auto GetProcessTidsFromProcPidFd (int fd, Collection* out, std::string* error = nullptr ) ->
69
69
typename std::enable_if<sizeof(typename Collection::value_type) >= sizeof(pid_t ), bool>::type {
70
70
out->clear ();
71
71
72
72
int task_fd = openat (fd, " task" , O_DIRECTORY | O_RDONLY | O_CLOEXEC);
73
73
std::unique_ptr<DIR, int (*)(DIR*)> dir (fdopendir (task_fd), closedir);
74
74
if (!dir) {
75
- PLOG (ERROR) << " failed to open task directory" ;
75
+ if (error != nullptr ) {
76
+ *error = " failed to open task directory" ;
77
+ }
76
78
return false ;
77
79
}
78
80
@@ -81,7 +83,9 @@ auto GetProcessTidsFromProcPidFd(int fd, Collection* out) ->
81
83
if (strcmp (dent->d_name , " ." ) != 0 && strcmp (dent->d_name , " .." ) != 0 ) {
82
84
pid_t tid;
83
85
if (!android::base::ParseInt (dent->d_name , &tid, 1 , std::numeric_limits<pid_t >::max ())) {
84
- LOG (ERROR) << " failed to parse task id: " << dent->d_name ;
86
+ if (error != nullptr ) {
87
+ *error = std::string (" failed to parse task id: " ) + dent->d_name ;
88
+ }
85
89
return false ;
86
90
}
87
91
@@ -93,21 +97,25 @@ auto GetProcessTidsFromProcPidFd(int fd, Collection* out) ->
93
97
}
94
98
95
99
template <typename Collection>
96
- auto GetProcessTids (pid_t pid, Collection* out) ->
100
+ auto GetProcessTids (pid_t pid, Collection* out, std::string* error = nullptr ) ->
97
101
typename std::enable_if<sizeof(typename Collection::value_type) >= sizeof(pid_t ), bool>::type {
98
102
char task_path[PATH_MAX];
99
103
if (snprintf (task_path, PATH_MAX, " /proc/%d" , pid) >= PATH_MAX) {
100
- LOG (ERROR) << " task path overflow (pid = " << pid << " )" ;
104
+ if (error != nullptr ) {
105
+ *error = " task path overflow (pid = " + std::to_string (pid) + " )" ;
106
+ }
101
107
return false ;
102
108
}
103
109
104
110
android::base::unique_fd fd (open (task_path, O_DIRECTORY | O_RDONLY | O_CLOEXEC));
105
111
if (fd == -1 ) {
106
- PLOG (ERROR) << " failed to open " << task_path;
112
+ if (error != nullptr ) {
113
+ *error = std::string (" failed to open " ) + task_path;
114
+ }
107
115
return false ;
108
116
}
109
117
110
- return GetProcessTidsFromProcPidFd (fd.get (), out);
118
+ return GetProcessTidsFromProcPidFd (fd.get (), out, error );
111
119
}
112
120
113
121
#endif
0 commit comments