Hello,

  I have clients running an installation script. The script is ran as root
(to be able to create the target directory and install the init script) and
reads /etc/inittab to get the default runlevel.  I've had one customer claim
that the script _deleted his inittab file_. Which we would have put under
user error.. until we had 2 other, unrelated machines, with wiped inittab
files and where the script had been used in the past. We have absolutely no
proof our script is related to the inittab file problem.

  So we have:

  - 3 emptied /etc/inittab files (file still exists, but has 0 length). Same
as if we'd open with mode '>' and closed it without writing.
  - 3 different machines: 1 HP-UX 11iv2 (PA-RISC), 1 Linux (Fedora Core 2 /
x86), 1 Linux (custom from scratch kernel/distro under VMWare)
  - The HPUX is at Company A, the 2 Linux boxes are at an unrelated Company
B. No shared admins to account for the same typo / custom admin script
  - Perl 5.8 on each (5.8.3 activestate build 809 on the HPUX)

  We can't reproduce the "bug" anywhere after 25,000 iterations. 3 different
setups with the same symptoms makes us think it can't just be coincidence,
but if we can't reproduce it it doesn't help... So I thought of posting the
related code to see if anything looks suspicious.. It's snipped from the
total source, but everything related to the inittab file is there.. The only
thing we could think of is a weird race condition from the usage of open
(?), but since we can't reproduce the darn effect we have no idea what to
look for..

  So any pointers appreciated.. If we can't find anything to 'fix' we'll
have a hard time getting that customer's trust back...

  Martin

#--------------8<---Snip!-------------------------------
require 5.6.0;

use strict;

use Config;
use Getopt::Std;
use File::Basename;
use File::Spec::Functions ':ALL';
use File::Copy;
use File::Path;
use File::Find;

use constant INIT_TAB_FILE => '/etc/inittab';
my $levels = undef;

sub error($) {
    my $msg = shift;
    ilog($msg);
    warn "Error: $msg\n";
    exit 1;
}

sub ilog($) {
    my $msg = shift;
    open(my $fh, '>>', catfile('/tmp', 'install.log'));
    print $fh "$msg\n";
    close($fh);
}


### much snipped

my $init_tab_file = INIT_TAB_FILE;

open(my $fh, '<', $init_tab_file) or error("Failed to open file
'$init_tab_file' --> $!");;

while (<$fh>) {
     $levels = $1 if /^[^#][^:]*:(\d):initdefault:/
}

close($fh);

error("Cannot find 'initdefault' definition in file '$init_tab_file'")
unless defined($levels);

print "Default runlevel: $levels\n";
_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to