) {
chomp;
if (/^$sep$service\s+\w+\s+/ and /$pattern/) {
&printv("Processing service \`$service' ... enabled\n");
$_ =~ s/^$sep//;
$nlines_enabled += 1;
}
print $ICWRITE "$_\n";
}
close(ICREAD);
close($ICWRITE) || die "Error closing $new_inetdcf: $!\n";
if ($nlines_enabled > 0) {
move("$new_inetdcf","$inetdcf") ||
die "Error installing $new_inetdcf to $inetdcf: $!\n";
chmod(0644, "$inetdcf");
&wakeup_inetd(0,$init_svc_count);
&printv("Number of service entries enabled: $nlines_enabled\n");
} else {
&printv("No service entries were enabled\n");
unlink("$new_inetdcf") || die "Error removing $new_inetdcf: $!\n";
}
return(1);
}
sub wakeup_inetd {
my($removal,$init_svc_count) = @_;
my($pid);
my($action);
$called_wakeup_inetd = 1;
if ($removal) {
$action = 'force-reload';
} elsif ( defined($init_svc_count) and $init_svc_count == 0 ) {
$action = 'start';
} else {
$action = 'restart';
}
$fake_invocation = defined($ENV{"UPDATE_INETD_FAKE_IT"});
if (open(P,"/var/run/inetd.pid")) {
$pid=;
chomp($pid);
if (open(C,sprintf("/proc/%d/stat",$pid))) {
$_=;
if (m/^\d+ \((rl|inetutils-)?inetd\)/) {
&printv("About to send SIGHUP to inetd (pid: $pid)\n");
unless ($fake_invocation) {
kill(1,$pid);
}
} else {
print STDERR "/var/run/inetd.pid does not have a valid pid!";
print STDERR "Please investigate and restart inetd manually.";
}
close(C);
}
close(P);
} else {
$_ = glob "/etc/init.d/*inetd";
if (m/\/etc\/init\.d\/(.*inetd)/ or $fake_invocation) {
&printv("About to $action inetd via invoke-rc.d\n");
my $service = $1;
unless ($fake_invocation) {
# If we were called by a shell script that also uses
# debconf, the pipe to the debconf frontend is fd 3 as
# well as fd 1 (stdout). Ensure that fd 3 is not
# inherited by invoke-rc.d and inetd, as that will
# cause debconf to hang (bug #589487). Don't let them
# confuse debconf via stdout either.
system("invoke-rc.d $service $action >/dev/null 3>&-");
}
}
}
return(1);
}
sub scan_entries {
my ($service, $pattern) = @_;
unless (defined($service)) { $service = '[^#\s]+'; }
unless (defined($pattern)) { $pattern = ''; }
my $counter = 0;
open(ICREAD, "$inetdcf");
SLOOP: while () {
$counter++ if (/^$service\s+/ and /$pattern/);
}
close(ICREAD);
return($counter);
}
sub printv {
print STDERR @_ if (defined($verbose));
}
1;