Merge "libprocessgroup: Add control of printing log in WriteFileAction"
This commit is contained in:
commit
feefc674eb
2 changed files with 10 additions and 5 deletions
|
|
@ -273,7 +273,7 @@ bool WriteFileAction::ExecuteForProcess(uid_t uid, pid_t pid) const {
|
||||||
value = StringReplace(value, "<pid>", std::to_string(pid), true);
|
value = StringReplace(value, "<pid>", std::to_string(pid), true);
|
||||||
|
|
||||||
if (!WriteStringToFile(value, filepath)) {
|
if (!WriteStringToFile(value, filepath)) {
|
||||||
PLOG(ERROR) << "Failed to write '" << value << "' to " << filepath;
|
if (logfailures_) PLOG(ERROR) << "Failed to write '" << value << "' to " << filepath;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -290,7 +290,7 @@ bool WriteFileAction::ExecuteForTask(int tid) const {
|
||||||
value = StringReplace(value, "<pid>", std::to_string(tid), true);
|
value = StringReplace(value, "<pid>", std::to_string(tid), true);
|
||||||
|
|
||||||
if (!WriteStringToFile(value, filepath)) {
|
if (!WriteStringToFile(value, filepath)) {
|
||||||
PLOG(ERROR) << "Failed to write '" << value << "' to " << filepath;
|
if (logfailures_) PLOG(ERROR) << "Failed to write '" << value << "' to " << filepath;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -516,7 +516,10 @@ bool TaskProfiles::Load(const CgroupMap& cg_map, const std::string& file_name) {
|
||||||
std::string attr_filepath = params_val["FilePath"].asString();
|
std::string attr_filepath = params_val["FilePath"].asString();
|
||||||
std::string attr_value = params_val["Value"].asString();
|
std::string attr_value = params_val["Value"].asString();
|
||||||
if (!attr_filepath.empty() && !attr_value.empty()) {
|
if (!attr_filepath.empty() && !attr_value.empty()) {
|
||||||
profile->Add(std::make_unique<WriteFileAction>(attr_filepath, attr_value));
|
const Json::Value& logfailures = params_val["LogFailures"];
|
||||||
|
bool attr_logfailures = logfailures.isNull() || logfailures.asBool();
|
||||||
|
profile->Add(std::make_unique<WriteFileAction>(attr_filepath, attr_value,
|
||||||
|
attr_logfailures));
|
||||||
} else if (attr_filepath.empty()) {
|
} else if (attr_filepath.empty()) {
|
||||||
LOG(WARNING) << "WriteFile: invalid parameter: "
|
LOG(WARNING) << "WriteFile: invalid parameter: "
|
||||||
<< "empty filepath";
|
<< "empty filepath";
|
||||||
|
|
|
||||||
|
|
@ -142,14 +142,16 @@ class SetCgroupAction : public ProfileAction {
|
||||||
// Write to file action
|
// Write to file action
|
||||||
class WriteFileAction : public ProfileAction {
|
class WriteFileAction : public ProfileAction {
|
||||||
public:
|
public:
|
||||||
WriteFileAction(const std::string& filepath, const std::string& value) noexcept
|
WriteFileAction(const std::string& filepath, const std::string& value,
|
||||||
: filepath_(filepath), value_(value) {}
|
bool logfailures) noexcept
|
||||||
|
: filepath_(filepath), value_(value), logfailures_(logfailures) {}
|
||||||
|
|
||||||
virtual bool ExecuteForProcess(uid_t uid, pid_t pid) const;
|
virtual bool ExecuteForProcess(uid_t uid, pid_t pid) const;
|
||||||
virtual bool ExecuteForTask(int tid) const;
|
virtual bool ExecuteForTask(int tid) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string filepath_, value_;
|
std::string filepath_, value_;
|
||||||
|
bool logfailures_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class TaskProfile {
|
class TaskProfile {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue