File Coverage

consoles/amtSol.pm
Criterion Covered Total %
statement 21 71 29.5
total 21 71 29.5


line stmt code
1   # Copyright 2012-2020 SUSE LLC
2   # SPDX-License-Identifier: GPL-2.0-or-later
3    
4    
5   use Mojo::Base 'consoles::console', -signatures;
6 2 use autodie ':all';
  2  
  2  
7 2 require IPC::System::Simple;
  2  
  2  
8   use POSIX '_exit';
9 2 use bmwqemu;
  2  
  2  
10 2 use IO::Pipe;
  2  
  2  
11 2  
  2  
  2  
12   $self->{serial_pipe} = IO::Pipe->new();
13 0  
  0  
  0  
14 0 setpgrp 0, 0;
15   $self->{serialpid} = fork();
16 0  
17 0 if ($self->{serialpid}) {
18   $self->{serial_pipe}->writer();
19 0 bmwqemu::diag "started amtterm $self->{serialpid}";
20 0 return;
21 0 }
22 0  
23   local $SIG{TERM} = 'DEFAULT';
24    
25 0 # a child was born
26   $self->{serial_pipe}->reader();
27    
28 0 my @cmd = ('/usr/sbin/amtterm');
29   push(@cmd, ('-u', 'admin', '-p', $bmwqemu::vars{AMT_PASSWORD}));
30 0 push(@cmd, ($bmwqemu::vars{AMT_HOSTNAME}));
31 0  
32 0 my $amt_console;
33   $self->{consolepid} = open($amt_console, '-|', @cmd);
34 0 $amt_console->blocking(0);
35 0  
36 0 my $s = IO::Select->new();
37   $s->add($amt_console);
38 0 $s->add($self->{serial_pipe});
39 0  
40 0 # Start serial grab
41   while (1) {
42   my @ready = $s->can_read;
43 0 for my $fh (@ready) {
44 0 if ($fh == $amt_console) {
45 0 my $line = <$amt_console>;
46 0 if (!$line) {
47 0 # impi_console is dead, restart it
48 0 $amt_console->close;
49   $s->remove($amt_console);
50 0 my $ret = waitpid($self->{consolepid}, 0);
51 0 bmwqemu::diag "SOL failed, reconnecting [$ret]\n";
52 0 sleep 1;
53 0 $self->{consolepid} = open($amt_console, '-|', @cmd);
54 0 $amt_console->blocking(0);
55 0 $s->add($amt_console);
56 0 next;
57 0 }
58 0 open(my $serial, '>>', $self->{args}->{serialfile});
59   print $serial $line;
60 0 close($serial);
61 0 }
62 0 else {
63   kill(TERM => $self->{consolepid});
64   $amt_console->close;
65 0 waitpid($self->{consolepid}, 0);
66 0 _exit(0);
67 0 }
68 0 }
69   }
70   _exit(0);
71   }
72 0  
73   return unless $self->{serialpid};
74   $self->{serial_pipe}->print("GO!\n");
75 1 $self->{serial_pipe}->close;
  1  
  1  
76 1 bmwqemu::diag "waiting for termination of amtterm $self->{serialpid}";
77 0 my $ret = waitpid($self->{serialpid}, 0);
78 0 $self->{serialpid} = undef;
79 0 return $ret;
80 0 }
81 0  
82 0 # we have no screen
83    
84   1;