selftest: added a pipe on stdin in s3 child processes
authorAndrew Tridgell <tridge@samba.org>
Tue, 3 Jan 2012 05:48:29 +0000 (16:48 +1100)
committerAndrew Tridgell <tridge@samba.org>
Thu, 9 Feb 2012 04:41:49 +0000 (15:41 +1100)
this adds a pipe for STDIN in smbd, nmbd and winbindd when run in
selftest. This allows those processes to detect when they should exit
by looking for EOF on stdin.

selftest/target/Samba3.pm

index a3ddb1880e3eb2573de6ae073dce077a65e10892..f200914fb47b6aba085ad9536370f7c47d85b6e2 100755 (executable)
@@ -485,6 +485,11 @@ sub read_pid($$)
 sub check_or_start($$$$$) {
        my ($self, $env_vars, $nmbd, $winbindd, $smbd) = @_;
 
+       # use a pipe for stdin in the child processes. This allows
+       # those processes to monitor the pipe for EOF to ensure they
+       # exit when the test script exits
+       pipe(STDIN_READER, STDIN_WRITER);
+
        unlink($env_vars->{NMBD_TEST_LOG});
        print "STARTING NMBD...";
        my $pid = fork();
@@ -526,6 +531,9 @@ sub check_or_start($$$$$) {
                        @preargs = split(/ /, $ENV{NMBD_VALGRIND});
                }
 
+               close(STDIN_WRITER);
+               open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
+
                exec(@preargs, Samba::bindir_path($self, "nmbd"), "-F", "--no-process-group", "--log-stdout", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start nmbd: $!");
        }
        write_pid($env_vars, "nmbd", $pid);
@@ -574,6 +582,9 @@ sub check_or_start($$$$$) {
 
                print "Starting winbindd with config $env_vars->{SERVERCONFFILE}\n";
 
+               close(STDIN_WRITER);
+               open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
+
                exec(@preargs, Samba::bindir_path($self, "winbindd"), "-F", "--no-process-group", "--stdout", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start winbindd: $!");
        }
        write_pid($env_vars, "winbindd", $pid);
@@ -617,11 +628,17 @@ sub check_or_start($$$$$) {
                if(defined($ENV{SMBD_VALGRIND})) {
                        @preargs = split(/ /,$ENV{SMBD_VALGRIND});
                }
+
+               close(STDIN_WRITER);
+               open STDIN, ">&", \*STDIN_READER or die "can't dup STDIN_READER to STDIN: $!";
+
                exec(@preargs, Samba::bindir_path($self, "smbd"), "-F", "--no-process-group", "--log-stdout", "-s", $env_vars->{SERVERCONFFILE}, @optargs) or die("Unable to start smbd: $!");
        }
        write_pid($env_vars, "smbd", $pid);
        print "DONE\n";
 
+       close(STDIN_READER);
+
        return 0;
 }