From bea24c8d27809cafc29ed60851072150bfbfc194 Mon Sep 17 00:00:00 2001 From: Raito Bezarius Date: Wed, 11 Jun 2025 15:53:04 +0200 Subject: [PATCH] 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 --- lix/libutil/cgroup.cc | 7 ++++++- lix/libutil/cgroup.hh | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/lix/libutil/cgroup.cc b/lix/libutil/cgroup.cc index 5ecc96092..920c6ec69 100644 --- a/lix/libutil/cgroup.cc +++ b/lix/libutil/cgroup.cc @@ -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(cgroup_).string()); - stateRecord.reset(cgroupFile, false); + stateRecord.emplace(cgroupFile, false); } void AutoDestroyCgroup::adoptProcess(int pid) diff --git a/lix/libutil/cgroup.hh b/lix/libutil/cgroup.hh index 4833017a9..de735813c 100644 --- a/lix/libutil/cgroup.hh +++ b/lix/libutil/cgroup.hh @@ -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 stateRecord; /* * Cleanse all previous instances of this cgroup where the deletion process