# test for another instance of the queued already running
my ( $pid, $delayed_dirs, $adelayedcore );
-if ( open( PIDFILE, "<$conf::pidfile" ) ) {
+if ( open( PIDFILE, "<", $conf::pidfile ) ) {
chomp( $pid = <PIDFILE> );
close(PIDFILE);
if ( !$pid ) {
sub check_incoming_writable();
sub rm(@);
sub md5sum($);
-sub is_debian_file($);
-sub get_maintainer($);
-sub debian_file_stem($);
sub msg($@);
sub debug(@);
sub init_mail(;$);
$SIG{"HUP"} = "IGNORE";
# open logfile, make it unbuffered
-open( LOG, ">>$conf::logfile" )
+open( LOG, ">>", $conf::logfile )
or die "Cannot open my logfile $conf::logfile: $!\n";
chmod( 0644, $conf::logfile )
or die "Cannot set modes of $conf::logfile: $!\n";
$SIG{"HUP"} = \&close_log;
# redirect stdin, ... to /dev/null
-open( STDIN, "</dev/null" )
+open( STDIN, "<", "/dev/null" )
or die "$main::progname: Can't redirect stdin to /dev/null: $!\n";
-open( STDOUT, ">&LOG" )
+open( STDOUT, ">&", \*LOG )
or die "$main::progname: Can't redirect stdout to $conf::logfile: $!\n";
-open( STDERR, ">&LOG" )
+open( STDERR, ">&", \*LOG )
or die "$main::progname: Can't redirect stderr to $conf::logfile: $!\n";
# ok, from this point usually no "die" anymore, stderr is gone!
}
# write the pid file
-open( PIDFILE, ">$conf::pidfile" )
+open( PIDFILE, ">", $conf::pidfile )
or msg( "log", "Can't open $conf::pidfile: $!\n" );
printf PIDFILE "%5d\n", $$;
close(PIDFILE);
# look for *.commands and *.dak-commands files but not in delayed queues
if ( $adelay == -1 ) {
foreach $file (<*.commands>) {
+ next unless $file =~ /$re_file_safe/;
init_mail($file);
block_signals();
process_commands($file);
finish_mail();
} ## end foreach $file (<*.commands>)
foreach $file (<*.dak-commands>) {
+ next unless $file =~ /$re_file_safe/;
init_mail($file);
block_signals();
process_dak_commands($file);
@changes = grep /\.changes$/, @files;
push( @keep_files, @changes ); # .changes files aren't stray
foreach $file (@changes) {
+ next unless $file =~ /$re_file_safe/;
init_mail($file);
# wrap in an eval to allow jumpbacks to here with die in case
my ( $maint, $pattern, @job_files );
if ( $file =~ /^junk-for-writable-test/
|| $file !~ m,$conf::valid_files,
+ || $file !~ /$re_file_safe/
|| $age >= $conf::stray_remove_timeout )
{
msg( "log",
"Deleted stray file ${main::current_incoming_short}/$file\n" )
if rm($file);
- } elsif (
- $age > $conf::no_changes_timeout
- && is_debian_file($file)
- &&
-
- # not already reported
- !( $stats[ST_MODE] & S_ISGID )
- && ( $pattern = debian_file_stem($file) )
- && ( @job_files = glob($pattern) )
- &&
-
- # If a .changes is in the list, it has the same stem as the
- # found file (probably a .orig.tar.gz). Don't report in this
- # case.
- !( grep( /\.changes$/, @job_files ) )
- )
- {
- $maint = get_maintainer($file);
-
- # Don't send a mail if this looks like the recompilation of a
- # package for a non-i386 arch. For those, the maintainer field is
- # useless :-(
- if ( !grep( /(\.dsc|_(i386|all)\.deb)$/, @job_files ) ) {
- msg( "log", "Found an upload without .changes and with no ",
- ".dsc file\n" );
- msg( "log",
- "Not sending a report, because probably ",
- "recompilation job\n" );
- } elsif ($maint) {
- init_mail();
- $main::mail_addr = $maint;
- $main::mail_addr = $1 if $main::mail_addr =~ /<([^>]*)>/;
- $main::mail_subject =
- "Incomplete upload found in " . "Debian upload queue";
- msg(
- "mail",
- "Probably you are the uploader of the following "
- . "file(s) in\n"
- );
- msg( "mail", "the Debian upload queue directory:\n " );
- msg( "mail", join( "\n ", @job_files ), "\n" );
- msg(
- "mail",
- "This looks like an upload, but a .changes file "
- . "is missing, so the job\n"
- );
- msg( "mail", "cannot be processed.\n\n" );
- msg(
- "mail",
- "If no .changes file arrives within ",
- print_time( $conf::stray_remove_timeout - $age ),
- ", the files will be deleted.\n\n"
- );
- msg(
- "mail",
- "If you didn't upload those files, please just "
- . "ignore this message.\n"
- );
- finish_mail();
- msg(
- "log",
- "Sending problem report for an upload without a "
- . ".changes\n"
- );
- msg( "log", "Maintainer: $maint\n" );
- } else {
- msg(
- "log",
- "Found an upload without .changes, but can't "
- . "find a maintainer address\n"
- );
- } ## end else [ if ( !grep( /(\.dsc|_(i386|all)\.deb)$/...
- msg( "log", "Files: @job_files\n" );
-
- # remember we already have sent a mail regarding this file
- foreach (@job_files) {
- my @st = stat($_);
- next if !@st; # file may have disappeared in the meantime
- chmod +( $st[ST_MODE] |= S_ISGID ), $_;
- }
} else {
debug(
"found stray file ${main::current_incoming_short}/$file, deleting in ",
my (@filenames);
# parse the .changes file
- open( CHANGES, "<$changes" )
+ open( CHANGES, "<", $changes )
or die "$changes: $!\n";
outer_loop: while (<CHANGES>) {
if (/^Files:/i) {
msg( "log", "processing ${main::current_incoming_short}/$changes\n" );
# parse the .changes file
- open( CHANGES, "<$changes" )
+ open( CHANGES, "<", $changes )
or die "Cannot open ${main::current_incoming_short}/$changes: $!\n";
$pgplines = 0;
$extralines = 0;
$failure_file = $changes . ".failures";
$retries = $last_retry = 0;
if ( -f $failure_file ) {
- open( FAILS, "<$failure_file" )
+ open( FAILS, "<", $failure_file )
or die "Cannot open $main::current_incoming_short/$failure_file: $!\n";
my $line = <FAILS>;
close(FAILS);
rm( $changes, @filenames, $failure_file );
} else {
$last_retry = time;
- if ( open( FAILS, ">$failure_file" ) ) {
+ if ( open( FAILS, ">", $failure_file ) ) {
print FAILS "$retries $last_retry\n";
close(FAILS);
chmod( 0600, $failure_file )
msg( "log", "processing $main::current_incoming_short/$commands\n" );
# parse the .commands file
- if ( !open( COMMANDS, "<$commands" ) ) {
+ if ( !open( COMMANDS, "<", $commands ) ) {
msg( "log", "Cannot open $main::current_incoming_short/$commands: $!\n" );
return;
}
# open the FIFO for writing; this blocks until someone (probably ftpd)
# opens it for reading
- open( STATFIFO, ">$conf::statusfile" )
+ open( STATFIFO, ">", $conf::statusfile )
or die "Cannot open $conf::statusfile\n";
select(STATFIFO);
return if !$conf::statusfile;
- open( STATFILE, ">$conf::statusfile" )
+ open( STATFILE, ">", $conf::statusfile )
or ( msg( "log", "Could not open $conf::statusfile: $!\n" ), return );
my $oldsel = select(STATFILE);
my $file = "junk-for-writable-test-" . format_time();
$file =~ s/[ :.]/-/g;
local (*F);
- open( F, ">$file" );
+ open( F, ">", $file );
close(F);
my $rv;
( $rv, $msg ) = ftp_cmd( "put", $file );
#
sub md5sum($) {
my $file = shift;
+ my $md5 = Digest::MD5->new;
open my $fh, "<", $file or return "";
- my $md5 = $md5->addfile($fh);
+ $md5->addfile($fh);
close $fh;
return $md5->hexdigest;
} ## end sub md5sum($)
-#
-# check if a file probably belongs to a Debian upload
-#
-sub is_debian_file($) {
- my $file = shift;
- return $file =~ /\.(deb|dsc|(diff|tar)\.gz)$/
- && $file !~ /\.orig\.tar\.gz/;
-}
-
-#
-# try to extract maintainer email address from some a non-.changes file
-# return "" if not possible
-#
-sub get_maintainer($) {
- my $file = shift;
- my $maintainer = "";
- local (*F);
-
- if ( $file =~ /\.diff\.gz$/ ) {
-
- # parse a diff
- open( F, "$conf::gzip -dc '$file' 2>/dev/null |" ) or return "";
- while (<F>) {
-
- # look for header line of a file */debian/control
- last if m,^\+\+\+\s+[^/]+/debian/control(\s+|$),;
- }
- while (<F>) {
- last if /^---/; # end of control file patch, no Maintainer: found
- # inside control file patch look for Maintainer: field
- $maintainer = $1, last if /^\+Maintainer:\s*(.*)$/i;
- }
- while (<F>) { } # read to end of file to avoid broken pipe
- close(F) or return "";
- } elsif ( $file =~ /\.(deb|dsc|tar\.gz)$/ ) {
- if ( $file =~ /\.deb$/ && $conf::ar ) {
-
- # extract control.tar.gz from .deb with ar, then let tar extract
- # the control file itself
- open( F,
- "($conf::ar p '$file' control.tar.gz | "
- . "$conf::tar -xOf - "
- . "--use-compress-program $conf::gzip "
- . "control) 2>/dev/null |"
- ) or return "";
- } elsif ( $file =~ /\.dsc$/ ) {
-
- # just do a plain grep
- debug("get_maint: .dsc, no cmd");
- open( F, "<$file" ) or return "";
- } elsif ( $file =~ /\.tar\.gz$/ ) {
-
- # let tar extract a file */debian/control
- open( F,
- "$conf::tar -xOf '$file' "
- . "--use-compress-program $conf::gzip "
- . "\\*/debian/control 2>&1 |"
- ) or return "";
- } else {
- return "";
- }
- while (<F>) {
- $maintainer = $1, last if /^Maintainer:\s*(.*)$/i;
- }
- close(F) or return "";
- } ## end elsif ( $file =~ /\.(deb|dsc|tar\.gz)$/)
-
- return $maintainer;
-} ## end sub get_maintainer($)
-
-#
-# return a pattern that matches all files that probably belong to one job
-#
-sub debian_file_stem($) {
- my $file = shift;
- my ( $pkg, $version );
-
- # strip file suffix
- $file =~ s,\.(deb|dsc|changes|(orig\.)?tar\.gz|diff\.gz)$,,;
-
- # if not is *_* (name_version), can't derive a stem and return just
- # the file's name
- return $file if !( $file =~ /^([^_]+)_([^_]+)/ );
- ( $pkg, $version ) = ( $1, $2 );
-
- # strip Debian revision from version
- $version =~ s/^(.*)-[\d.+-]+$/$1/;
-
- return "${pkg}_${version}*";
-} ## end sub debian_file_stem($)
-
#
# output a messages to several destinations
#
close(STDOUT);
close(STDERR);
- open( LOG, ">>$conf::logfile" )
+ open( LOG, ">>", $conf::logfile )
or die "Cannot open my logfile $conf::logfile: $!\n";
chmod( 0644, $conf::logfile )
or msg( "log", "Cannot set modes of $conf::logfile: $!\n" );
select( ( select(LOG), $| = 1 )[0] );
- open( STDOUT, ">&LOG" )
+ open( STDOUT, ">&", \*LOG )
or msg( "log",
"$main::progname: Can't redirect stdout to " . "$conf::logfile: $!\n" );
- open( STDERR, ">&LOG" )
+ open( STDERR, ">&", \*LOG )
or msg( "log",
"$main::progname: Can't redirect stderr to " . "$conf::logfile: $!\n" );
msg( "log", "Restart after SIGHUP\n" );