File: //proc/self/root/scripts.20110531.215904.25158/patch_errno
#!/usr/bin/perl
# cpanel - patch_errno Copyright(c) 2010 cPanel, Inc.
# All rights Reserved.
# copyright@cpanel.net http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited
BEGIN { unshift @INC, '/usr/local/cpanel'; }
use Cpanel::SafeFile ();
use Cpanel::SafeRun::Simple ();
use Cpanel::LoadFile ();
use Cpanel::Logger ();
eval 'local $SIG{__DIE__}; use Errno;';
my $module_path = $INC{'Errno.pm'};
my $logger = Cpanel::Logger->new();
my $errno_txt = Cpanel::LoadFile::loadfile($module_path);
if ( $errno_txt !~ /use Config/ ) { exit; }
print "Removing useless Config Dep from Errno.\n";
my $mod_fh = Cpanel::SafeFile::safeopen( \*ER, '+<', $module_path );
if ( !$mod_fh ) {
die print "Could not edit $module_path \n";
}
my @EN = <ER>;
seek( ER, 0, 0 );
my $inconfig = 0;
foreach (@EN) {
next if (/^use Config/);
if ( !$inconfig && /\$Config/ ) {
$inconfig = 1;
next;
}
elsif ( $inconfig && /\$Config/ ) {
$inconfig = 0;
next;
}
elsif ($inconfig) {
next;
}
else {
print ER $_;
}
}
truncate( ER, tell(ER) );
Cpanel::SafeFile::safeclose( \*ER, $mod_fh );
my $is_ok = Cpanel::SafeRun::Simple::saferun( ( -e '/usr/local/cpanel/scripts/check_errno' ? '/usr/local/cpanel/scripts/check_errno' : '/scripts/check_errno' ) );
chomp($is_ok);
if ( !$is_ok || $is_ok ne 'ok' ) {
print "Patching Failed, restoring previous Errno!\n";
my $mod_fh2 = Cpanel::SafeFile::safeopen( \*ER, '>', $module_path );
if ( !$mod_fh2 ) {
$logger->die("Could not write to $module_path");
}
else {
print ER $errno_txt;
Cpanel::SafeFile::safeclose( \*ER, $mod_fh2 );
}
}
my $is_ok = Cpanel::SafeRun::Simple::saferun( ( -e '/usr/local/cpanel/scripts/check_errno' ? '/usr/local/cpanel/scripts/check_errno' : '/scripts/check_errno' ) );
chomp($is_ok);
if ( !$is_ok || $is_ok ne 'ok' ) {
system '/scripts/perlinstaller', '--force', 'Errno';
}