nbdkit/0006-exitwhen-Check-nbdkit-...

55 lines
1.5 KiB
Diff

From 015c1abe341484a61afe31b765c4d8d2fece0fe6 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 25 Jun 2022 16:35:22 +0100
Subject: [PATCH] exitwhen: Check nbdkit doesn't exit before the pipe is closed
Enhance the existing test with a check that nbdkit does not exit
before the pipe is closed.
(cherry picked from commit 278b95f931044bd9f2aeb316ccfa00308beacc8d)
---
tests/test-exitwhen-pipe-closed.c | 15 +++++++++++++--
1 file changed, 13 insertions(+), 2 deletions(-)
diff --git a/tests/test-exitwhen-pipe-closed.c b/tests/test-exitwhen-pipe-closed.c
index 50f28bde..8949932e 100644
--- a/tests/test-exitwhen-pipe-closed.c
+++ b/tests/test-exitwhen-pipe-closed.c
@@ -35,6 +35,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
+#include <signal.h>
int
main (int argc, char *argv[])
@@ -74,13 +75,23 @@ main (int argc, char *argv[])
perror ("execvp");
_exit (EXIT_FAILURE);
}
+ free (param);
- /* Close the read side of the pipe. */
+ /* Close the read side of the pipe (this does NOT cause nbdkit to exit). */
close (fd[0]);
+ /* Wait a bit. */
+ sleep (2);
+
+ /* nbdkit should still be running. */
+ if (kill (pid, 0) != 0) {
+ fprintf (stderr, "FAIL: %s: nbdkit exited before pipe was closed\n",
+ argv[0]);
+ exit (EXIT_FAILURE);
+ }
+
/* The test here is simply that nbdkit exits because we exit and our
* side of the pipe is closed.
*/
- free (param);
exit (EXIT_SUCCESS);
}
--
2.31.1