diff mbox series

[2/4] qtest: kill orphaned qtest QEMU processes on FreeBSD

Message ID 20230912184130.3056054-3-berrange@redhat.com
State New
Headers show
Series ci: fix hang of FreeBSD CI jobs | expand

Commit Message

Daniel P. Berrangé Sept. 12, 2023, 6:41 p.m. UTC
On Linux we use PR_SET_PDEATHSIG to kill orphaned QEMU processes
if we fail to call qtest_quit(), or the test program aborts/segvs.
This prevents meson from hanging forever due to the orphaned
process keeping stdout open.

On FreeBSD we can achieve the same using PROC_PDEATHSIG_CTL, which
gives us the equivalent protection against hangs.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 tests/qtest/libqtest.c | 7 +++++++
 1 file changed, 7 insertions(+)

Comments

Richard Henderson Sept. 12, 2023, 7:05 p.m. UTC | #1
On 9/12/23 11:41, Daniel P. Berrangé wrote:
> On Linux we use PR_SET_PDEATHSIG to kill orphaned QEMU processes
> if we fail to call qtest_quit(), or the test program aborts/segvs.
> This prevents meson from hanging forever due to the orphaned
> process keeping stdout open.
> 
> On FreeBSD we can achieve the same using PROC_PDEATHSIG_CTL, which
> gives us the equivalent protection against hangs.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   tests/qtest/libqtest.c | 7 +++++++
>   1 file changed, 7 insertions(+)
> 
> diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
> index 34b9c14b75..b1eba71ffe 100644
> --- a/tests/qtest/libqtest.c
> +++ b/tests/qtest/libqtest.c
> @@ -24,6 +24,9 @@
>   #ifdef __linux__
>   #include <sys/prctl.h>
>   #endif /* __linux__ */
> +#ifdef __FreeBSD__
> +#include <sys/procctl.h>
> +#endif /* __FreeBSD__ */
>   
>   #include "libqtest.h"
>   #include "libqmp.h"
> @@ -414,6 +417,10 @@ static QTestState *G_GNUC_PRINTF(1, 2) qtest_spawn_qemu(const char *fmt, ...)
>            */
>           prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
>   #endif /* __linux__ */
> +#ifdef __FreeBSD__
> +        int sig = SIGKILL;
> +        procctl(P_PID, getpid(), PROC_PDEATHSIG_CTL, &sig);

We could use 0 for "current process", but this works too.

Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
diff mbox series

Patch

diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c
index 34b9c14b75..b1eba71ffe 100644
--- a/tests/qtest/libqtest.c
+++ b/tests/qtest/libqtest.c
@@ -24,6 +24,9 @@ 
 #ifdef __linux__
 #include <sys/prctl.h>
 #endif /* __linux__ */
+#ifdef __FreeBSD__
+#include <sys/procctl.h>
+#endif /* __FreeBSD__ */
 
 #include "libqtest.h"
 #include "libqmp.h"
@@ -414,6 +417,10 @@  static QTestState *G_GNUC_PRINTF(1, 2) qtest_spawn_qemu(const char *fmt, ...)
          */
         prctl(PR_SET_PDEATHSIG, SIGKILL, 0, 0, 0);
 #endif /* __linux__ */
+#ifdef __FreeBSD__
+        int sig = SIGKILL;
+        procctl(P_PID, getpid(), PROC_PDEATHSIG_CTL, &sig);
+#endif /* __FreeBSD__ */
         if (!g_setenv("QEMU_AUDIO_DRV", "none", true)) {
             exit(1);
         }