libprocessgroup: Make a log message more detailed

For log messages like the following it is not possible to derive why
this message has been logged:

E libprocessgroup: AddTidToCgroup failed to write '3949'; fd=55: Operation not supported on transport endpoint

Hence include the cgroup path and the tid type in the log message.

Change-Id: I057711fe576b82f6454456b7284186ddeece33c3
Signed-off-by: Bart Van Assche <bvanassche@google.com>
This commit is contained in:
Bart Van Assche 2023-11-13 15:19:43 -08:00
parent 191af79538
commit df98534e19
2 changed files with 8 additions and 6 deletions

View file

@ -316,7 +316,7 @@ SetCgroupAction::SetCgroupAction(const CgroupController& c, const std::string& p
FdCacheHelper::Init(controller_.GetProcsFilePath(path_, 0, 0), fd_[ProfileAction::RCT_PROCESS]);
}
bool SetCgroupAction::AddTidToCgroup(int tid, int fd, const char* controller_name) {
bool SetCgroupAction::AddTidToCgroup(int tid, int fd, ResourceCacheType cache_type) const {
if (tid <= 0) {
return true;
}
@ -332,6 +332,7 @@ bool SetCgroupAction::AddTidToCgroup(int tid, int fd, const char* controller_nam
return true;
}
const char* controller_name = controller()->name();
// ENOSPC is returned when cpuset cgroup that we are joining has no online cpus
if (errno == ENOSPC && !strcmp(controller_name, "cpuset")) {
// This is an abnormal case happening only in testing, so report it only once
@ -345,7 +346,8 @@ bool SetCgroupAction::AddTidToCgroup(int tid, int fd, const char* controller_nam
<< "' into cpuset because all cpus in that cpuset are offline";
empty_cpuset_reported = true;
} else {
PLOG(ERROR) << "AddTidToCgroup failed to write '" << value << "'; fd=" << fd;
PLOG(ERROR) << "AddTidToCgroup failed to write '" << value << "'; path=" << path_ << "; "
<< (cache_type == RCT_TASK ? "task" : "process");
}
return false;
@ -356,7 +358,7 @@ ProfileAction::CacheUseResult SetCgroupAction::UseCachedFd(ResourceCacheType cac
std::lock_guard<std::mutex> lock(fd_mutex_);
if (FdCacheHelper::IsCached(fd_[cache_type])) {
// fd is cached, reuse it
if (!AddTidToCgroup(id, fd_[cache_type], controller()->name())) {
if (!AddTidToCgroup(id, fd_[cache_type], cache_type)) {
LOG(ERROR) << "Failed to add task into cgroup";
return ProfileAction::FAIL;
}
@ -391,7 +393,7 @@ bool SetCgroupAction::ExecuteForProcess(uid_t uid, pid_t pid) const {
PLOG(WARNING) << Name() << "::" << __func__ << ": failed to open " << procs_path;
return false;
}
if (!AddTidToCgroup(pid, tmp_fd, controller()->name())) {
if (!AddTidToCgroup(pid, tmp_fd, RCT_PROCESS)) {
LOG(ERROR) << "Failed to add task into cgroup";
return false;
}
@ -412,7 +414,7 @@ bool SetCgroupAction::ExecuteForTask(int tid) const {
PLOG(WARNING) << Name() << "::" << __func__ << ": failed to open " << tasks_path;
return false;
}
if (!AddTidToCgroup(tid, tmp_fd, controller()->name())) {
if (!AddTidToCgroup(tid, tmp_fd, RCT_TASK)) {
LOG(ERROR) << "Failed to add task into cgroup";
return false;
}

View file

@ -160,7 +160,7 @@ class SetCgroupAction : public ProfileAction {
android::base::unique_fd fd_[ProfileAction::RCT_COUNT];
mutable std::mutex fd_mutex_;
static bool AddTidToCgroup(int tid, int fd, const char* controller_name);
bool AddTidToCgroup(int tid, int fd, ResourceCacheType cache_type) const;
CacheUseResult UseCachedFd(ResourceCacheType cache_type, int id) const;
};