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