From 7948e0e2d267015796ba3de1cf8bfb2f4c348478 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Tue, 30 Dec 2025 11:58:20 +0100 Subject: [PATCH] Make TestPidOf1 unit test more robust The test expects to find PID 1 by searching for "init" or "systemd". While some LXC container is running: - PID 1 runs systemd (not traditional init) - Another process (e.g., PID 41150) may have "init" in its cmdline This causes pid_of("init") to return PID 41150 instead of PID 1, and the test would fail because PID 1 is not in the result. The fix checks if PID 1 is found after the "init" search, and if not, falls back to searching for "systemd" to find PID 1. --- test/test_filefunc.cpp | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diff --git a/test/test_filefunc.cpp b/test/test_filefunc.cpp index f3fa0c5..583de35 100644 --- a/test/test_filefunc.cpp +++ b/test/test_filefunc.cpp @@ -313,17 +313,17 @@ BOOST_AUTO_TEST_CASE(TestPidOf1) bool res= pid_of("init", pid_list); BOOST_CHECK_EQUAL( true, res); - if (pid_list.empty()) + // Check if PID 1 was found. If not, try systemd. + std::vector< pid_t >::const_iterator pos1 = + std::find( pid_list.begin(), pid_list.end(), 1); + + if (pos1 == pid_list.end()) { res= pid_of("systemd", pid_list); BOOST_CHECK_EQUAL( true, res); + pos1 = std::find( pid_list.begin(), pid_list.end(), 1); } - BOOST_CHECK_EQUAL( false, pid_list.empty() ); - - std::vector< pid_t >::const_iterator pos1 = - std::find( pid_list.begin(), pid_list.end(), 1); - BOOST_CHECK( pos1 != pid_list.end() ); } // eo TestPidOf1() -- 1.7.1