view release on metacpan or search on metacpan
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
my $class = shift;
# globally scoped hash, populated with defaults as requested by the caller
%std_opts = (
'fatal' => { type => BOOLEAN, optional => 1, default => 1 },
'debug' => { type => BOOLEAN, optional => 1, default => 1 },
'quiet' => { type => BOOLEAN, optional => 1, default => 0 },
'test_ok' => { type => BOOLEAN, optional => 1 },
);
my %p = validate( @_,
{ toaster=> { type => OBJECT, optional => 1 },
%std_opts,
}
);
my $toaster = $p{toaster};
my $self = {
debug => $p{debug},
fatal => $p{fatal},
};
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
$log = $self->{log} = $self;
$log->audit( $class . sprintf( " loaded by %s, %s, %s", caller ) );
return $self;
}
sub ask {
my $self = shift;
my $question = shift;
my %p = validate(
@_,
{ default => { type => SCALAR|UNDEF, optional => 1 },
timeout => { type => SCALAR, optional => 1 },
password => { type => BOOLEAN, optional => 1, default => 0 },
test_ok => { type => BOOLEAN, optional => 1 },
}
);
my $pass = $p{password};
my $default = $p{default};
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
return $response if $response; # if they typed something, return it
return $default if $default; # return the default, if available
return ''; # return empty handed
}
sub audit {
my $self = shift;
my $mess = shift;
my %p = validate( @_, { %std_opts } );
if ($mess) {
push @{ $log->{audit} }, $mess;
print "$mess\n" if $self->{debug} || $p{debug};
}
return \$log->{audit};
}
sub archive_file {
my $self = shift;
my $file = shift or return $log->error("missing filename in request");
my %p = validate( @_,
{ 'sudo' => { type => BOOLEAN, optional => 1, default => 1 },
'mode' => { type => SCALAR, optional => 1 },
destdir => { type => SCALAR, optional => 1 },
%std_opts,
}
);
my %args = $self->get_std_args( %p );
return $log->error( "file ($file) is missing!", %args )
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
if ( $sudo && $cp ) {
return $self->syscmd( "$sudo $cp $file $archive",fatal=>0 );
}
$log->error( "archive_file: sudo or cp was missing, could not escalate.",fatal=>0);
return;
};
sub chmod {
my $self = shift;
my %p = validate(
@_,
{ 'file' => { type => SCALAR, optional => 1, },
'file_or_dir' => { type => SCALAR, optional => 1, },
'dir' => { type => SCALAR, optional => 1, },
'mode' => { type => SCALAR, optional => 0, },
'sudo' => { type => BOOLEAN, optional => 1, default => 0 },
%std_opts,
}
);
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
# note the conversion of ($mode) to an octal value. Very important!
CORE::chmod( oct($mode), $file ) or
return $log->error( "couldn't chmod $file: $!", %args);
$log->audit("chmod $mode $file");
}
sub chown {
my $self = shift;
my $file = shift;
my %p = validate( @_,
{ 'uid' => { type => SCALAR },
'gid' => { type => SCALAR },
'sudo' => { type => BOOLEAN, optional => 1 },
%std_opts,
}
);
my %args = $self->get_std_args( %p );
my ( $uid, $gid, $sudo ) = ( $p{uid}, $p{gid}, $p{sudo} );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
chown( $nuid, $ngid, $file )
or return $log->error( "couldn't chown $file: $!",%args);
return 1;
}
sub chown_system {
my $self = shift;
my $dir = shift;
my %p = validate( @_,
{ 'user' => { type => SCALAR, optional => 0, },
'group' => { type => SCALAR, optional => 1, },
'recurse' => { type => BOOLEAN, optional => 1, },
%std_opts,
}
);
my ( $user, $group, $recurse ) = ( $p{user}, $p{group}, $p{recurse} );
my %args = $self->get_std_args( %p );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
$mess .= "Recursively " if $recurse;
$mess .= "changed $dir to be owned by $user";
$log->audit( $mess );
return 1;
}
sub clean_tmp_dir {
my $self = shift;
my $dir = shift or die "missing dir name";
my %p = validate( @_, { %std_opts } );
my %args = $self->get_std_args( %p );
my $before = cwd; # remember where we started
return $log->error( "couldn't chdir to $dir: $!", %args) if !chdir $dir;
foreach ( $self->get_dir_files( $dir ) ) {
next unless $_;
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
}
}
chdir $before;
return 1;
}
sub cwd_source_dir {
my $self = shift;
my $dir = shift or die "missing dir in request\n";
my %p = validate( @_,
{ 'src' => { type => SCALAR, optional => 1, },
'sudo' => { type => BOOLEAN, optional => 1, },
%std_opts,
}
);
my ( $src, $sudo, ) = ( $p{src}, $p{sudo}, );
my %args = $self->get_std_args( %p );
return $log->error( "Something (other than a directory) is at $dir and " .
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
}
}
}
chdir $dir or return $log->error( "failed to cd to $dir: $!", %args);
return 1;
}
sub dump_audit {
my $self = shift;
my %p = validate( @_, { %std_opts } );
my $audit = $log->{audit} or return;
return if ! $log->{last_audit};
return if $log->{last_audit} == scalar @$audit; # nothing new
if ( $p{quiet} ) { # hide/mask unreported messages
$log->{last_audit} = scalar @$audit;
$log->{last_error} = scalar @{ $log->{errors}};
return 1;
};
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
my ( $dir ) = @_;
mkpath( $dir, 0, oct('0755') )
or return $log->error( "mkdir $dir failed: $!");
$log->audit( "created $dir");
return 1;
}
sub error {
my $self = shift;
my $message = shift;
my %p = validate( @_,
{ location => { type => SCALAR, optional => 1, },
%std_opts,
},
);
my $location = $p{location};
my $debug = $p{debug};
my $fatal = $p{fatal};
if ( $message ) {
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
$self->dump_errors();
}
exit 1 if $fatal;
return;
}
sub extract_archive {
my $self = shift;
my $archive = shift or die "missing archive name";
my %p = validate( @_, { %std_opts } );
my %args = $self->get_std_args( %p );
my $r;
if ( !-e $archive ) {
if ( -e "$archive.tar.gz" ) { $archive = "$archive.tar.gz" }
elsif ( -e "$archive.tgz" ) { $archive = "$archive.tgz" }
elsif ( -e "$archive.tar.bz2" ) { $archive = "$archive.tar.bz2" }
else {
return $log->error( "file $archive is missing!", %args );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
$self->syscmd( "$bin -c $archive | $tar -xf -" ) or return;
$log->audit( "extracted $archive" );
return 1;
}
sub file_delete {
my $self = shift;
my $file = shift or die "missing file argument";
my %p = validate( @_,
{ 'sudo' => { type => BOOLEAN, optional => 1, default => 0 },
%std_opts,
}
);
my %args = $self->get_std_args( %p );
return $log->error( "$file does not exist", %args ) if !-e $file;
if ( -w $file ) {
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
}
$self->syscmd( $rm_command, %args )
or return $log->error( $err, %args );
return -e $file ? 0 : 1;
}
sub file_is_newer {
my $self = shift;
my %p = validate( @_,
{ f1 => { type => SCALAR },
f2 => { type => SCALAR },
%std_opts,
}
);
my ( $file1, $file2 ) = ( $p{f1}, $p{f2} );
# get file attributes via stat
# (dev,ino,mode,nlink,uid,gid,rdev,size,atime,mtime,ctime,blksize,blocks)
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
#
# if ( stat($f1)[9] > stat($f2)[9] )
#
# but that forces the reader to read the man page for stat
# to see what's happening
}
sub file_read {
my $self = shift;
my $file = shift or return $log->error("missing filename in request");
my %p = validate(
@_,
{ 'max_lines' => { type => SCALAR, optional => 1 },
'max_length' => { type => SCALAR, optional => 1 },
%std_opts
}
);
my ( $max_lines, $max_length ) = ( $p{max_lines}, $p{max_length} );
my %args = $self->get_std_args( %p );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
push @lines, $line;
$i++;
}
chomp @lines;
close $FILE;
return @lines;
}
sub file_mode {
my $self = shift;
my %p = validate( @_,
{ 'file' => { type => SCALAR },
%std_opts
}
);
my $file = $p{file};
my %args = $self->get_std_args( %p );
return $log->error( "file '$file' does not exist!", %args)
if !-e $file;
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
# my $st = stat($file);
# my $mode = sprintf "%lo", $st->mode & 07777;
$log->audit( "file $file has mode: $mode" );
return $mode;
}
sub file_write {
my $self = shift;
my $file = shift or return $log->error("missing filename in request");
my %p = validate(
@_,
{ 'lines' => { type => ARRAYREF },
'append' => { type => BOOLEAN, optional => 1, default => 0 },
'mode' => { type => SCALAR, optional => 1 },
%std_opts
}
);
my $append = $p{append};
my $lines = $p{lines};
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
# set file permissions mode if requested
$self->chmod( file => $file, mode => $p{mode}, %args )
or return if $p{mode};
return 1;
}
sub files_diff {
my $self = shift;
my %p = validate(
@_,
{ f1 => { type => SCALAR },
f2 => { type => SCALAR },
type => { type => SCALAR, optional => 1, default => 'text' },
%std_opts,
}
);
my ( $f1, $f2, $type ) = ( $p{f1}, $p{f2}, $p{type} );
my %args = $log->get_std_args(%p);
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
$self->file_write( "$f.md5", lines => [$sum], %$args ) if $changed;
}
return if $md5sums[0] eq $md5sums[1];
return 1;
}
sub find_bin {
my $self = shift;
my $bin = shift or die "missing argument to find_bin\n";
my %p = validate( @_,
{ 'dir' => { type => SCALAR, optional => 1, },
%std_opts,
},
);
my $prefix = "/usr/local";
my %args = $log->get_std_args(%p);
if ( $bin =~ /^\// && -x $bin ) { # we got a full path
$log->audit( "find_bin: found $bin", %args );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
$log->audit( "find_bin: found $found", %args);
return $found;
}
return $log->error( "find_bin: could not find $bin", %args);
}
sub find_config {
my $self = shift;
my $file = shift or die "missing file name";
my %p = validate( @_,
{ etcdir => { type => SCALAR | UNDEF, optional => 1, },
%std_opts,
}
);
#my @caller = caller;
#warn sprintf( "find_config loaded by %s, %s, %s\n", @caller );
$log->audit("find_config: searching for $file");
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
# warn about files that exist but aren't readable
if ( -e "$dir/$file" ) {
$log->error( "$dir/$file is not readable", fatal => 0);
};
return $self->find_readable( $file, @_ );
}
sub fstab_list {
my $self = shift;
my %p = validate( @_, { %std_opts, } );
if ( $OSNAME eq "darwin" ) {
return ['fstab not used on Darwin!'];
}
my $fstab = "/etc/fstab";
if ( !-e $fstab ) {
print "fstab_list: FAILURE: $fstab does not exist!\n" if $p{debug};
return;
}
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
'unzip' => $unzip,
'urllist' => [ 'http://www.perl.com/CPAN/', 'ftp://cpan.cs.utah.edu/pub/CPAN/', 'ftp://mirrors.kernel.org/pub/CPAN', 'ftp://osl.uoregon.edu/CPAN/', 'http://cpan.yahoo.com/' ],
'wget' => $wget,
};
}
sub get_dir_files {
my $self = shift;
my $dir = shift or die "missing dir name";
my %p = validate( @_, { %std_opts } );
my %args = $self->get_std_args( %p );
my @files;
return $log->error( "dir $dir is not a directory!", %args)
if ! -d $dir;
opendir D, $dir or return $log->error( "couldn't open $dir: $!", %args );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
# Purpose : get a list of IP addresses on local interfaces
# Returns : an arrayref of IP addresses
# Parameters : only - can be one of: first, last
# : exclude_locahost (all 127.0 addresses)
# : exclude_internals (192.168, 10., 169., 172.)
# : exclude_ipv6
# Comments : exclude options are boolean and enabled by default.
# tested on Mac OS X and FreeBSD
my $self = shift;
my %p = validate(
@_,
{ 'only' => { type => SCALAR, optional => 1, default => 0 },
'exclude_localhost' =>
{ type => BOOLEAN, optional => 1, default => 1 },
'exclude_internals' =>
{ type => BOOLEAN, optional => 1, default => 1 },
'exclude_ipv6' =>
{ type => BOOLEAN, optional => 1, default => 1 },
%std_opts,
}
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
my %args;
foreach ( qw/ debug fatal test_ok quiet / ) {
next if ! defined $p{$_};
$args{$_} = $p{$_};
};
return %args;
};
sub get_the_date {
my $self = shift;
my %p = validate(
@_,
{ 'bump' => { type => SCALAR, optional => 1, },
%std_opts
}
);
my $bump = $p{bump} || 0;
my %args = $self->get_std_args( %p );
my $time = time;
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
my $dd = sprintf( "%02i", $fields[3] ); # day of month
my $mm = sprintf( "%02i", $fields[4] + 1 ); # month
my $yy = ( $fields[5] + 1900 ); # year
$log->audit( "$mess, $yy/$mm/$dd $hh:$mn", %args );
return $dd, $mm, $yy, undef, $hh, $mn, $ss;
}
sub get_mounted_drives {
my $self = shift;
my %p = validate( @_, { %std_opts } );
my %args = $log->get_std_args( %p );
my $mount = $self->find_bin( 'mount', %args );
-x $mount or return $log->error( "I couldn't find mount!", %args );
$ENV{PATH} = "";
my %hash;
foreach (`$mount`) {
my ( $d, $m ) = $_ =~ /^(.*) on (.*) \(/;
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
$log->audit( "adding: $m \t $d" ) if $p{debug};
$hash{$m} = $d;
}
}
return \%hash;
}
sub get_url {
my $self = shift;
my $url = shift;
my %p = validate(
@_,
{ dir => { type => SCALAR, optional => 1 },
timeout => { type => SCALAR, optional => 1 },
%std_opts,
}
);
my $dir = $p{dir};
my %args = $log->get_std_args( %p );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
};
};
return if ! -e $file_path;
return $response;
}
sub get_url_system {
my $self = shift;
my $url = shift;
my %p = validate(
@_,
{ dir => { type => SCALAR, optional => 1 },
timeout => { type => SCALAR, optional => 1, },
%std_opts,
}
);
my $dir = $p{dir};
my $debug = $p{debug};
my %args = $log->get_std_args( %p );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
## no critic ( ProhibitStringyEval )
eval "use $name" . ($ver ? " $ver;" : ";");
## use critic
!$EVAL_ERROR;
};
sub install_if_changed {
my $self = shift;
my %p = validate(
@_,
{ newfile => { type => SCALAR, optional => 0, },
existing=> { type => SCALAR, optional => 0, },
mode => { type => SCALAR, optional => 1, },
uid => { type => SCALAR, optional => 1, },
gid => { type => SCALAR, optional => 1, },
sudo => { type => BOOLEAN, optional => 1, default => 0 },
notify => { type => BOOLEAN, optional => 1, },
email => { type => SCALAR, optional => 1, default => 'postmaster' },
clean => { type => BOOLEAN, optional => 1, default => 1 },
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
$msg->to($email);
my $email_message = $msg->open;
print $email_message "This message is to notify you that $existing has been altered. The difference between the new file and the old one is:\n\n$diffie";
$email_message->close;
};
sub install_from_source {
my $self = shift;
my %p = validate(
@_,
{ 'site' => { type => SCALAR, optional => 0, },
'url' => { type => SCALAR, optional => 0, },
'package' => { type => SCALAR, optional => 0, },
'targets' => { type => ARRAYREF, optional => 1, },
'patches' => { type => ARRAYREF, optional => 1, },
'patch_url' => { type => SCALAR, optional => 1, },
'patch_args' => { type => SCALAR, optional => 1, },
'source_dir' => { type => SCALAR, optional => 1, },
'source_sub_dir' => { type => SCALAR, optional => 1, },
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
if ( $portdir && -d $portdir && chdir $portdir ) {
$log->audit( "installing $module from ports ($portdir)" );
system "make clean && make install clean";
return 1;
}
return;
}
sub install_module_from_src {
my $self = shift;
my %p = validate( @_, {
module => { type=>SCALAR, optional=>0, },
archive => { type=>SCALAR, optional=>0, },
site => { type=>SCALAR, optional=>0, },
url => { type=>SCALAR, optional=>0, },
src => { type=>SCALAR, optional=>1, default=>'/usr/local/src' },
targets => { type=>ARRAYREF,optional=>1, },
%std_opts,
},
);
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
else { $ps .= ' axww'; };
my @procs = `$ps`;
chomp @procs;
return scalar grep {/$process/i} @procs;
}
sub is_readable {
my $self = shift;
my $file = shift or die "missing file or dir name\n";
my %p = validate( @_, { %std_opts } );
my %args = ( debug => $p{debug}, fatal => $p{fatal} );
-e $file or return $log->error( "$file does not exist.", %args);
-r $file or return $log->error( "$file is not readable by you ("
. getpwuid($>)
. "). You need to fix this, using chown or chmod.", %args);
return 1;
}
sub is_writable {
my $self = shift;
my $file = shift or die "missing file or dir name\n";
my %p = validate( @_, { %std_opts } );
my %args = $self->get_std_args( %p );
my $nl = "\n";
$nl = "<br>" if ( $ENV{GATEWAY_INTERFACE} );
if ( !-e $file ) {
my ( $base, $path, $suffix ) = fileparse($file);
return $log->error( "is_writable: $path not writable by "
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
}
return $log->error( " $file not writable by " . getpwuid($>) . "$nl$nl", %args ) if ! -w $file;
$log->audit( "$file is writable" );
return 1;
}
sub logfile_append {
my $self = shift;
my %p = validate(
@_,
{ 'file' => { type => SCALAR, optional => 0, },
'lines' => { type => ARRAYREF, optional => 0, },
'prog' => { type => BOOLEAN, optional => 1, default => 0, },
%std_opts,
},
);
my ( $file, $lines ) = ( $p{file}, $p{lines} );
my %args = $self->get_std_args( %p );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
return 1;
}
sub mail_toaster {
my $self = shift;
$self->install_module( 'Mail::Toaster' );
}
sub mkdir_system {
my $self = shift;
my %p = validate(
@_,
{ 'dir' => { type => SCALAR, optional => 0, },
'mode' => { type => SCALAR, optional => 1, },
'sudo' => { type => BOOLEAN, optional => 1, default => 0 },
%std_opts,
}
);
my ( $dir, $mode ) = ( $p{dir}, $p{mode} );
my %args = $self->get_std_args( %p );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
# matches from the last / char +1 to the end of string
my $curdir = substr( $dir, $rindex );
return $updir, $curdir;
}
sub check_pidfile {
my $self = shift;
my $file = shift;
my %p = validate( @_, { %std_opts } );
my %args = $self->get_std_args( %p );
return $log->error( "missing filename", %args) if ! $file;
return $log->error( "$file is not a regular file", %args)
if ( -e $file && !-f $file );
# test if file & enclosing directory is writable, revert to /tmp if not
$self->is_writable( $file, %args)
or do {
my ( $base, $path, $suffix ) = fileparse($file);
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
else {
$log->audit( "check_pidfile: $file is $age seconds old, ignoring.", %args);
}
return $file;
}
sub parse_config {
my $self = shift;
my $file = shift or die "missing file name";
my %p = validate( @_, {
etcdir => { type=>SCALAR, optional=>1, },
%std_opts,
},
);
my %args = $self->get_std_args( %p );
if ( ! -f $file ) { $file = $self->find_config( $file, %p ); };
if ( ! $file || ! -r $file ) {
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
next if ! $key;
$hash{$key} = $val;
}
return \%hash;
}
sub parse_line {
my $self = shift;
my $line = shift;
my %p = validate( @_, {
strip => { type => BOOLEAN, optional=>1, default=>1 },
},
);
my $strip = $p{strip};
# this regexp must match and return these patterns
# localhost1 = localhost, disk, da0, disk_da0
# hosts = localhost lab.simerson.net seattle.simerson.net
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
return ( $key, $val );
}
sub provision_unix {
my $self = shift;
$self->install_module( 'Provision::Unix' );
}
sub regexp_test {
my $self = shift;
my %p = validate(
@_,
{ 'exp' => { type => SCALAR },
'string' => { type => SCALAR },
'pbp' => { type => BOOLEAN, optional => 1, default => 0 },
%std_opts,
},
);
my $debug = $p{debug};
my ( $exp, $string, $pbp ) = ( $p{exp}, $p{string}, $p{pbp} );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
print "\t Matched: |$`<$&>$'|\n" if $debug;
return $1;
}
print "\t No match.\n" if $debug;
return;
}
sub sources_get {
my $self = shift;
my %p = validate(
@_,
{ 'package' => { type => SCALAR, optional => 0 },
site => { type => SCALAR, optional => 0 },
path => { type => SCALAR, optional => 1 },
%std_opts,
},
);
my ( $package, $site, $path ) = ( $p{package}, $p{site}, $p{path} );
my %args = $self->get_std_args( %p );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
$log->audit( " oops, is not [b|g]zipped data!");
$self->file_delete( $tarball, %args);
}
return $log->error( "unable to get $package", %args );
}
sub source_warning {
my $self = shift;
my %p = validate(
@_,
{ 'package' => { type => SCALAR, },
'clean' => { type => BOOLEAN, optional => 1, default => 1 },
'src' => {
type => SCALAR,
optional => 1,
default => "/usr/local/src"
},
'timeout' => { type => SCALAR, optional => 1, default => 60 },
%std_opts,
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
$log->audit( " wd: " . cwd );
$log->audit( " deleting $src/$package");
return $log->error( "failed to delete $package: $OS_ERROR", %args )
if ! rmtree "$src/$package";
return 1;
}
sub sudo {
my $self = shift;
my %p = validate( @_, { %std_opts } );
# if we are running as root via $<
if ( $REAL_USER_ID == 0 ) {
$log->audit( "sudo: you are root, sudo isn't necessary.");
return ''; # return an empty string, purposefully
}
my $sudo;
my $path_to_sudo = $self->find_bin( 'sudo', fatal => 0 );
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
print "sudo install failed!";
return '';
}
return "$path_to_sudo -p 'Password for %u@%h:'";
}
sub syscmd {
my $self = shift;
my $cmd = shift or die "missing command!\n";
my %p = validate(
@_,
{ 'timeout' => { type => SCALAR, optional => 1 },
%std_opts,
},
);
my %args = $log->get_std_args( %p );
$log->audit("syscmd: $cmd");
lib/Apache/Logmonster/Utility.pm view on Meta::CPAN
printf "child died with signal %d, %s coredump\n", ( $? & 127 ),
( $? & 128 ) ? 'with' : 'without';
}
return $log->error( "$err: $r", location => join( ", ", @$caller ), %$args );
};
sub yes_or_no {
my $self = shift;
my $question = shift;
my %p = validate(
@_,
{ 'timeout' => { type => SCALAR, optional => 1 },
'force' => { type => BOOLEAN, optional => 1, default => 0 },
%std_opts
},
);
# for 'make test' testing
return 1 if $question eq "test";