From 88a4fda7d8ad26e2db363eb7c0d985ebedfba738 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 14 Jan 2011 16:01:47 +0000 Subject: [PATCH] * Don't daemonise vde_switch so that it's cleaned up automatically. This is useful for interactive use. svn path=/nixos/trunk/; revision=25570 --- lib/test-driver/test-driver.pl | 23 ++++++++++++++++++++--- lib/testing.nix | 2 +- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/lib/test-driver/test-driver.pl b/lib/test-driver/test-driver.pl index 841017ea0a33..bdb3f40ca6cb 100644 --- a/lib/test-driver/test-driver.pl +++ b/lib/test-driver/test-driver.pl @@ -4,8 +4,10 @@ use strict; use Machine; use Term::ReadLine; use IO::File; +use IO::Pty; use Logger; use Cwd; +use POSIX qw(_exit dup2); $SIG{PIPE} = 'IGNORE'; # because Unix domain sockets may die unexpectedly @@ -18,12 +20,27 @@ my $log = new Logger; my %vlans; foreach my $vlan (split / /, $ENV{VLANS} || "") { next if defined $vlans{$vlan}; + # Start vde_switch as a child process. We don't run it in daemon + # mode because we want the child process to be cleaned up when we + # die. Since we have to make sure that the control socket is + # ready, we send a dummy command to vde_switch (via stdin) and + # wait for a reply. Note that vde_switch requires stdin to be a + # TTY, so we create one. $log->log("starting VDE switch for network $vlan"); my $socket = Cwd::abs_path "./vde$vlan.ctl"; - system("vde_switch -d -s $socket") == 0 - or die "cannot start vde_switch"; + my $pty = new IO::Pty; + my ($stdoutR, $stdoutW); pipe $stdoutR, $stdoutW; + my $pid = fork(); die "cannot fork" unless defined $pid; + if ($pid == 0) { + dup2(fileno($pty->slave), 0); + dup2(fileno($stdoutW), 1); + exec "vde_switch -s $socket" or _exit(1); + } + close $stdoutW; + print $pty "version\n"; + readline $pty or die "cannot start vde_switch"; $ENV{"QEMU_VDE_SOCKET_$vlan"} = $socket; - $vlans{$vlan} = 1; + $vlans{$vlan} = $pty; } diff --git a/lib/testing.nix b/lib/testing.nix index 999d27883e2e..0869ff7c8bec 100644 --- a/lib/testing.nix +++ b/lib/testing.nix @@ -28,7 +28,7 @@ rec { wrapProgram $out/bin/nixos-test-driver \ --prefix PATH : "${pkgs.qemu_kvm}/bin:${pkgs.vde2}/bin:${imagemagick}/bin:${coreutils}/bin" \ - --prefix PERL5LIB : "${lib.makePerlPath [ perlPackages.TermReadLineGnu perlPackages.XMLWriter ]}:$out/lib/perl5/site_perl" + --prefix PERL5LIB : "${lib.makePerlPath [ perlPackages.TermReadLineGnu perlPackages.XMLWriter perlPackages.IOTty ]}:$out/lib/perl5/site_perl" ''; };