sub _restoreTerm () {
# In case the user hits Ctrl-C
print "\nControl-C\n";
-
+
ReadMode 'normal';
-
+
exit;
} # _restoreTerm
$errorlog ||= $NULL;
my $file;
-
+
# Redirect STDIN to $NULL
open STDIN, '<', $NULL
or error "Can't read $NULL ($!)", 1;
or error "Can't write to $errorlog ($!)", 1;
# Change the current directory to /
- my $ROOT = $ARCH eq "windows" ? "C:\\" : "/";
+ my $ROOT = $ARCHITECTURE eq "windows" ? "C:\\" : "/";
chdir $ROOT
or error "Can't chdir to $ROOT ($!), 1";
# Now the parent exits
exit if $pid;
-
+
# Write pidfile if specified
if ($pidfile) {
$pidfile = File::Spec->rel2abs ($pidfile);
or warning "Unable to open pidfile $pidfile for writing - $!";
print $file "$$\n";
-
+
close $file;
} # if
-
+
# Set process to be session leader
setsid ()
or error "Can't start a new session ($!)", 1;
-
+
return;
} # EnterDaemonMode
=cut
- # Save $SIG{CHLD} so we can set it to 'DEFAULT' and then restore it later.
- # Helps when you are doing process handling.
- my $sigchld = $SIG{CHLD};
-
local $SIG{CHLD} = 'DEFAULT';
my @output = `$cmd`;
my $status = $?;
-
- local $SIG{CHLD} = $sigchld;
chomp @output;
$prompt ||= 'Password';
-
+
my $password;
-
+
local $| = 1;
-
+
print "$prompt:";
-
+
$SIG{INT} = \&_restoreTerm;
-
+
ReadMode 'cbreak';
while () {
my $key;
-
+
while (not defined ($key = ReadKey -1)) { }
if ($key =~ /(\r|\n)/) {
} # if
print '*';
-
+
$password .= $key;
} # while
-
+
ReadMode 'restore'; # Reset tty mode before exiting.
$SIG{INT} = 'DEFAULT';
-
+
return $password;
} # GetPassword
# TODO: Make it work on Windows...
return if $^O =~ /win/i;
-
+
open my $loadAvg, '/proc/loadavg'
or croak "Unable to open /proc/loadavg\n";
-
+
my $load = <$loadAvg>;
-
+
close $loadAvg;
-
+
my @loadAvgs = split /\s/, $load;
-
+
if (wantarray) {
return @loadAvgs;
} else {
if ($existingPipe) {
close $existingPipe;
-
+
open $existingPipe, '|-', $to
or error "Unable to open pipe - $!", 1;
-
+
return $existingPipe;
} else {
open $pipe, '|-', $to
$pipeToStop ||= $pipe;
close $pipeToStop if $pipeToStop;
-
+
return;
} # StopPipe
sub RedirectOutput ($$@) {
my ($to, $mode, @output) = @_;
-
+
=pod
=head2 RedirectOutput ($to, @ouput)
chomp;
print $out "$_\n";
} # foreach
-
+
return;
} # RedirectOutput
open my $file, '<', $filename
or error "Unable to open $filename ($!)", 1;
-
+
if (wantarray) {
local $/ = "\n";
my @lines = <$file>;
-
+
close $file
or error "Unable to close $filename ($!)", 1;
-
+
my @cleansed_lines;
-
+
foreach (@lines) {
chomp;
chop if /\r/;
push @cleansed_lines, $_ if !/^#/; # Discard comment lines
} # foreach
-
+
return @cleansed_lines;
} else {
local $/ = undef;
-
+
return <$file>;
} # if
} # ReadFile
=cut
my $msg = "$FindBin::Script Run Statistics:";
-
+
if ($log and ref $log eq 'Logger') {
$total->{errors} = $log->{errors};
$total->{warnings} = $log->{warnings};
} # if
-
+
if (keys %$total) {
# Display statistics (if any)
if ($log) {
foreach (sort keys %$total) {
$msg = $total->{$_} . "\t $_";
-
+
if ($log) {
$log->msg ($total->{$_} . "\t $_");
} else {
} # if
} # foreach
} # if
-
+
return;
} # Stats