1 # Copyright (c) 2010-2012 Zmanda, Inc. All Rights Reserved.
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94085, USA, or: http://www.zmanda.com
20 package Amanda::Interactivity::stdin;
24 use POSIX qw( :errno_h );
26 @ISA = qw( Amanda::Interactivity );
30 use Amanda::Debug qw( debug );
32 use Amanda::MainLoop qw( :GIOCondition );
36 Amanda::Interactivity::stdin -- Interactivity class to read user request from stdin
40 Amanda::Interactivity class to write user request on stdout and read reply
51 return bless ($self, $class);
57 if ($self->{'input_src'}) {
58 $self->{'input_src'}->remove();
59 $self->{'input_src'} = undef;
68 my $message = $params{'message'};
69 my $label = $params{'label'};
70 my $err = $params{'err'};
71 my $chg_name = $params{'chg_name'};
75 my $n_read = POSIX::read(0, $b, 1);
76 if (!defined $n_read) {
77 return if ($! == EINTR);
79 return $params{'request_cb'}->(
80 Amanda::Changer::Error->new('fatal',
81 message => "Fail to read from stdin"));
82 } elsif ($n_read == 0) {
84 return $params{'request_cb'}->(
85 Amanda::Changer::Error->new('fatal',
86 message => "Aborted by user"));
94 return $params{'request_cb'}->(undef, $line);
100 print "Insert volume labeled '$label' in $chg_name\n";
101 print "and press <enter> enter, or ^D to abort.\n";
103 $self->{'input_src'} = Amanda::MainLoop::fd_source(0, $G_IO_IN|$G_IO_HUP|$G_IO_ERR);
104 $self->{'input_src'}->set_callback($data_in);