target_kernkind_console_inittab is supposed to edit inittab to make
sure that there is a getty running on hvc0.
However:
- It is not idempotent; if run more than once it can produce duplicate
entries `1:' and `xc:'.
- It works by copying and editing the entry `1:' but it might be that
there is already another console entry for hvc0 for some other
reason.
If we end up with multiple entries for hvc0, we can have two copies of
getty fighting, and if you manage to log in, one of them will be
fighting with your shell.
Guard the script with a grep, which looks for inittab entries
mentioning the intended console. This makes makes it do nothing if
nothing is needed (and therefore it also makes it idempotent).
Signed-off-by: Ian Jackson <Ian.Jackson@eu.citrix.com>
Acked-by: Ian Campbell <ian.campbell@citrix.com>
if (defined $console && length $console) {
target_cmd_root($ho, <<END);
set -ex
- perl -i~ -ne "
+ egrep '^[0-9a-zA-Z].*getty.* $console\$' $inittabpath \\
+ || perl -i~ -ne "
next if m/^xc:/;
print \\\$_ or die \\\$!;
next unless s/^1:/xc:/;