In the tests, don't start agetty on /dev/ttyS0

Running agetty on ttyS0 interferes with the backdoor, which uses ttyS0
as its standard error.  After agetty starts, writes to the stderr file
descriptor will return EIO (though doing "exec 2>/proc/self/fd/2" will
miracuously fix this).

http://hydra.nixos.org/build/3252782
This commit is contained in:
Eelco Dolstra 2012-10-29 21:01:36 +01:00
parent 4764848314
commit 1a82024dd8
4 changed files with 42 additions and 9 deletions

View File

@ -6,6 +6,17 @@ rec {
unitOptions = { unitOptions = {
enable = mkOption {
default = true;
types = types.bool;
description = ''
If set to false, this unit will be a symlink to
/dev/null. This is primarily useful to prevent specific
template instances (e.g. <literal>serial-getty@ttyS0</literal>)
from being started.
'';
};
description = mkOption { description = mkOption {
default = ""; default = "";
types = types.uniq types.string; types = types.uniq types.string;

View File

@ -10,7 +10,14 @@ let
systemd = pkgs.systemd; systemd = pkgs.systemd;
makeUnit = name: unit: makeUnit = name: unit:
pkgs.writeTextFile { name = "unit"; inherit (unit) text; destination = "/${name}"; }; pkgs.runCommand "unit" { inherit (unit) text; }
(if unit.enable then ''
mkdir -p $out
echo -n "$text" > $out/${name}
'' else ''
mkdir -p $out
ln -s /dev/null $out/${name}
'');
upstreamUnits = upstreamUnits =
[ # Targets. [ # Targets.
@ -205,7 +212,7 @@ let
as)); as));
targetToUnit = name: def: targetToUnit = name: def:
{ inherit (def) wantedBy; { inherit (def) wantedBy enable;
text = text =
'' ''
[Unit] [Unit]
@ -214,7 +221,7 @@ let
}; };
serviceToUnit = name: def: serviceToUnit = name: def:
{ inherit (def) wantedBy; { inherit (def) wantedBy enable;
text = text =
'' ''
[Unit] [Unit]
@ -258,7 +265,7 @@ let
}; };
socketToUnit = name: def: socketToUnit = name: def:
{ inherit (def) wantedBy; { inherit (def) wantedBy enable;
text = text =
'' ''
[Unit] [Unit]
@ -333,6 +340,16 @@ in
types = types.uniq types.string; types = types.uniq types.string;
description = "Text of this systemd unit."; description = "Text of this systemd unit.";
}; };
enable = mkOption {
default = true;
types = types.bool;
description = ''
If set to false, this unit will be a symlink to
/dev/null. This is primarily useful to prevent specific
template instances (e.g. <literal>serial-getty@ttyS0</literal>)
from being started.
'';
};
wantedBy = mkOption { wantedBy = mkOption {
default = []; default = [];
types = types.listOf types.string; types = types.listOf types.string;

View File

@ -13,9 +13,8 @@ let kernel = config.boot.kernelPackages.kernel; in
boot.systemd.services.backdoor = boot.systemd.services.backdoor =
{ wantedBy = [ "multi-user.target" ]; { wantedBy = [ "multi-user.target" ];
requires = [ "dev-hvc0.device" ]; requires = [ "dev-hvc0.device" "dev-ttyS0.device" ];
after = [ "dev-hvc0.device" ]; after = [ "dev-hvc0.device" "dev-ttyS0.device" ];
script = script =
'' ''
export USER=root export USER=root
@ -27,10 +26,15 @@ let kernel = config.boot.kernelPackages.kernel; in
echo "connecting to host..." >&2 echo "connecting to host..." >&2
stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion stty -F /dev/hvc0 raw -echo # prevent nl -> cr/nl conversion
echo echo
PS1= /bin/sh PS1= exec /bin/sh
''; '';
}; };
# Prevent agetty from being instantiated on ttyS0, since it
# interferes with the backdoor (writes to ttyS0 will randomly fail
# with EIO).
boot.systemd.services."serial-getty@ttyS0".enable = false;
boot.initrd.postDeviceCommands = boot.initrd.postDeviceCommands =
'' ''
# Using acpi_pm as a clock source causes the guest clock to # Using acpi_pm as a clock source causes the guest clock to

View File

@ -40,6 +40,7 @@
startAll; startAll;
# The router should have access to the server. # The router should have access to the server.
$server->waitForUnit("network.target");
$server->waitForUnit("httpd"); $server->waitForUnit("httpd");
$router->waitForUnit("network.target"); $router->waitForUnit("network.target");
$router->succeed("curl --fail http://server/ >&2"); $router->succeed("curl --fail http://server/ >&2");
@ -68,7 +69,7 @@
$client->fail("ping -c 1 server >&2"); $client->fail("ping -c 1 server >&2");
# And make sure that restarting the NAT job works. # And make sure that restarting the NAT job works.
$router->succeed("start nat"); $router->succeed("systemctl start nat");
$client->succeed("curl --fail http://server/ >&2"); $client->succeed("curl --fail http://server/ >&2");
$client->succeed("ping -c 1 server >&2"); $client->succeed("ping -c 1 server >&2");
''; '';