From: Razvan Becheriu Date: Wed, 17 Sep 2025 18:57:45 +0000 (+0300) Subject: [#4074] fixed valgrind warnings in process unit tests X-Git-Tag: Kea-3.1.2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ad7f5c35a4d950bbc9aeb250550eb378ac1950e5;p=thirdparty%2Fkea.git [#4074] fixed valgrind warnings in process unit tests --- diff --git a/src/lib/process/tests/daemon_unittest.cc b/src/lib/process/tests/daemon_unittest.cc index 0cfbf4c776..c899f79d40 100644 --- a/src/lib/process/tests/daemon_unittest.cc +++ b/src/lib/process/tests/daemon_unittest.cc @@ -6,6 +6,7 @@ #include +#include #include #include #include @@ -18,6 +19,7 @@ #include using namespace isc; +using namespace isc::asiolink; using namespace isc::process; using namespace isc::data; @@ -256,26 +258,10 @@ TEST_F(DaemonTest, createPIDFile) { TEST_F(DaemonTest, createPIDFileOverwrite) { DaemonImpl instance; - // We're going to use fork to generate a PID we KNOW is dead. - int pid = fork(); - ASSERT_GE(pid, 0); - - if (pid == 0) { - char name[] = TEST_SCRIPT_SH; - char* argv[] = { name, 0 }; - char* envp[] = { 0 }; - execve(name, argv, envp); - _exit(0); - } - - // Back in the parent test, we need to wait for the child to die - // As with debugging waitpid() can be interrupted ignore EINTR. - int stat; - int ret; - do { - ret = waitpid(pid, &stat, 0); - } while ((ret == -1) && (errno == EINTR)); - ASSERT_EQ(ret, pid); + // We're going to generate a PID we KNOW is dead. + ProcessSpawn process(ProcessSpawn::SYNC, TEST_SCRIPT_SH); + pid_t pid = 0; + ASSERT_NO_THROW(pid = process.spawn()); // Ok, so we should now have a PID that we know to be dead. // Let's use it to create a PID file. diff --git a/src/lib/process/tests/process_test.sh.in b/src/lib/process/tests/process_test.sh.in old mode 100644 new mode 100755