libutil/cgroup: destroy state record at destroy time
If state records are not destroyed at destroy time, this might confuse a new build that thinks there's a remnant of a cgroup when actually it was destroyed. This fixes a bunch of inoffensive and noisy warnings about cgroups being deleted by someone else. Reported-by: Ramses <@rvdp:infosec.exchange> Change-Id: Ib3d33f4ecd6143f33e032c5107b288b4ecabaee1 Signed-off-by: Raito Bezarius <raito@lix.systems>
This commit is contained in:
@@ -311,6 +311,8 @@ void AutoDestroyCgroup::destroy()
|
||||
},
|
||||
cgroup_
|
||||
);
|
||||
|
||||
stateRecord.reset();
|
||||
}
|
||||
|
||||
AutoDestroyCgroup::~AutoDestroyCgroup()
|
||||
@@ -326,6 +328,9 @@ void AutoDestroyCgroup::cleansePreviousInstancesAndRecordOurself(
|
||||
const std::filesystem::path & cgroupRecordsDir
|
||||
)
|
||||
{
|
||||
assert(
|
||||
!stateRecord && "`stateRecord` cannot be created before the cleansing process takes place"
|
||||
);
|
||||
createDirs(cgroupRecordsDir);
|
||||
|
||||
auto cgroupFile = cgroupRecordsDir / name_;
|
||||
@@ -337,7 +342,7 @@ void AutoDestroyCgroup::cleansePreviousInstancesAndRecordOurself(
|
||||
}
|
||||
|
||||
writeFile(cgroupFile, std::get<std::filesystem::path>(cgroup_).string());
|
||||
stateRecord.reset(cgroupFile, false);
|
||||
stateRecord.emplace(cgroupFile, false);
|
||||
}
|
||||
|
||||
void AutoDestroyCgroup::adoptProcess(int pid)
|
||||
|
||||
@@ -138,8 +138,10 @@ private:
|
||||
* Path to the state record of this cgroup's existence.
|
||||
* This is used when the deletion process is interrupted
|
||||
* for the next run.
|
||||
*
|
||||
* This might be deleted earlier, in which case, this is left to none.
|
||||
*/
|
||||
AutoDelete stateRecord;
|
||||
std::optional<AutoDelete> stateRecord;
|
||||
|
||||
/*
|
||||
* Cleanse all previous instances of this cgroup where the deletion process
|
||||
|
||||
Reference in New Issue
Block a user