selftest: Close STDIN_PIPE's write end for skipped daemons
authorVolker Lendecke <vl@samba.org>
Tue, 28 Jan 2020 13:41:11 +0000 (14:41 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 29 Jan 2020 09:36:27 +0000 (09:36 +0000)
Without this, any environment that skips any daemon will not shut down
properly. If a copy of a pipe's write end remains, closing one of them
won't cause the read end to be readable, i.e. the daemons waiting for
that won't exit properly.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
selftest/target/Samba.pm

index 9319f301327e811f160b46ddcaeb0a9992507e1c..216c13f11c1b86bd59dae0be5c548a23a6b378a0 100644 (file)
@@ -664,6 +664,11 @@ sub fork_and_exec
                set_env_for_process($daemon_ctx->{NAME}, $env_vars,
                                    $daemon_ctx->{ENV_VARS});
 
+               # we close the child's write-end of the pipe and redirect the read-end
+               # to its stdin. That way the daemon will receive an EOF on stdin when
+               # parent selftest process closes its write-end.
+               close($env_vars->{STDIN_PIPE});
+
                # not all s3 daemons run in all testenvs (e.g. fileserver doesn't
                # run winbindd). In which case, the child process just sleeps
                if (defined($daemon_ctx->{SKIP_DAEMON})) {
@@ -678,10 +683,6 @@ sub fork_and_exec
 
                $ENV{MAKE_TEST_BINARY} = $daemon_ctx->{BINARY_PATH};
 
-               # we close the child's write-end of the pipe and redirect the read-end
-               # to its stdin. That way the daemon will receive an EOF on stdin when
-               # parent selftest process closes its write-end.
-               close($env_vars->{STDIN_PIPE});
                open STDIN, ">&", $STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
 
                # if using kernel namespaces, prepend the command so the process runs in