diff options
Diffstat (limited to 'iurt2')
-rwxr-xr-x | iurt2 | 66 |
1 files changed, 39 insertions, 27 deletions
@@ -172,7 +172,7 @@ $run{todo} = [ ]; die "FATAL $program_name: $_ does not seems to be a SRPM\n" } if (check_arch($_, $run{my_arch})) { - print {$run{LOG}} "$program_name: force build for $2 (from $1)\n"; + plog("force build for $2 (from $1)"); push @{$run{todo}}, [ $path, $srpm, 1 ] } else { print {$run{LOG}} "ERROR $program_name: $_ could not be build on $run{my_arch}, ignored.\n" @@ -237,7 +237,7 @@ print "$program_name version $VERSION\n"; my $todo = parseCommandLine($program_name, \@ARGV, \@params); @ARGV and usage($program_name, \@params, "@ARGV, too many arguments"); foreach my $t (@$todo) { - print {$run{LOG}} "$program_name: $t->[2]\n" if $run{verbose} > 5; + plog(6, "$t->[2]"); &{$t->[0]}(@{$t->[1]}) or print {$run{LOG}} "ERROR: $t->[2]\n"; } @@ -248,7 +248,7 @@ my $real_arch = `uname -m`; chomp $real_arch; my $HOME = $ENV{HOME}; my $configfile = "$HOME/.iurt.$run{distro_tag}.conf"; -print {$run{LOG}} "$program_name: loading config file $configfile\n" if $run{verbose} > 1; +plog(2, "loading config file $configfile"); my $config; if (-f $configfile) { $config = do $configfile or die "FATAL $program_name: syntax error in $configfile"; @@ -336,9 +336,9 @@ if ($config->{local_spool}) { } else { $local_spool = "$config->{local_upload}/iurt/$run{distro_tag}/$run{my_arch}/$run{media}/" } -print {$run{LOG}} "$program_name: using $local_spool as local spooler\n" if $run{verbose} > 4; +plog(5, "using $local_spool as local spooler"); if (!-d "$local_spool/log") { - print {$run{LOG}} "$program_name: creating local spool $local_spool\n" if $run{verbose} > 4; + plog(5, "creating local spool $local_spool"); mkdir_p("$local_spool/log") or die "FATAL $program_name: could not create local spool dir $local_spool ($!)" } $run{local_spool} = $local_spool; @@ -346,7 +346,7 @@ $run{local_spool} = $local_spool; my $cache; my $clear_cache = 1; if (-f $cachefile && $run{use_cache}) { - print {$run{LOG}} "$program_name: loading cache file $cachefile\n" if $run{verbose} > 1; + plog(2, "loading cache file $cachefile"); $cache = do $cachefile or print "FATAL $program_name: could not load cache $cachefile ($!)\n"; if (!$cache) { opendir my $cache_dir, $config->{cache_home}; @@ -358,7 +358,7 @@ if (-f $cachefile && $run{use_cache}) { $cachefile = "$config->{cache_home}/$file" } } - print {$run{LOG}} "$program_name: loading alternate cache file $cachefile\n"; + plog("loading alternate cache file $cachefile"); $cache = do $cachefile or print "FATAL $program_name: could not load cache $cachefile ($!)\n" } $clear_cache = 0 if $cache @@ -382,7 +382,7 @@ $run{to_compile} = $to_compile; dump_cache_par(\%run); -print {$run{LOG}} "$program_name: will try to compile $to_compile packages\n" if $run{verbose} > 1; +plog(2, "will try to compile $to_compile packages"); my ($fulldate, $daydate) = get_date(); if ($run{use_cache}) { @@ -393,10 +393,10 @@ if ($run{use_cache}) { $run{run} = "0.$fulldate" } $run{daydate} = $daydate; -print {$run{LOG}} "$program_name: using $run{run} as chroot extension\n" if $run{verbose} > 4; +plog(5, "using $run{run} as chroot extension"); $run{user} = $ENV{SUDO_USER} || $ENV{USER}; $run{uid} = getpwnam $run{user}; -print {$run{LOG}} "$program_name: using local user $run{user}, id $run{uid}\n" if $run{verbose} > 3; +plog(3, "using local user $run{user}, id $run{uid}"); my $luser = $run{user} || 'builder'; check_sudo_access() or die "FATAL $program_name: you need to have sudo access to run $program_name"; @@ -404,7 +404,7 @@ check_sudo_access() or die "FATAL $program_name: you need to have sudo access to my $debug_tag = '_debug' if $run{debug}; $run{debug_tag} = $debug_tag; if ($run{unionfs}) { - print {$run{LOG}} "$program_name: adding unionfs module\n" if $run{verbose} > 0; + plog(1, "adding unionfs module"); sudo(\%run, $config, "--modprobe", "unionfs") or $run{unionfs} = 0; if ($run{unionfs}) { $run{unionfs_dir} = "$config->{local_home}/iurt_unionfs$debug_tag/"; @@ -436,7 +436,7 @@ $run{chroot_tmp} = $chroot_tmp; # now exit if there is nothing to do and it was just a cleaning pass if ($run{no_compile} || !@{$run{todo}} && !$run{debug} && !$run{shell} && !$run{rebuild}) { send_status_mail(\%run, $config, $cache) if ($run{status_mail}); - print {$run{LOG}} "$program_name: no package to compile :(\n"; + plog("no package to compile :("); unlink "$run{pidfile_home}/$run{pidfile}" if $run{pidfile}; exit } @@ -449,7 +449,7 @@ if ($run{chroot} || !-d "$chroot/dev") { check_build_chroot($chroot, $chroot_tar, \%run, $config) or die "FATAL $program_name: could not prepare initial chroot" } -print {$run{LOG}} "$program_name: running with pid $$\n"; +plog("running with pid $$"); $run{prefix} = get_prefix($luser); my $df = df $home; @@ -465,7 +465,7 @@ if ($run{shell}) { $urpmi->install_packages('chroot', $chroot_tmp, $local_spool, \%pack_provide, 'configure', "[ADMIN] installation of urpmi and sudo failed in the chroot $run{my_arch}", { check => 1, maintainer => $config->{admin} }, 'urpmi', 'sudo') or die "FATAL $program_name: could not add urpmi and sudo in the chroot"; add_sudoers(\%run, $chroot_tmp, $luser); if ($run{shell}) { - print {$run{LOG}} "$program_name: dumping to a chrooted shell into $chroot_tmp\n"; + plog("dumping to a chrooted shell into $chroot_tmp"); exec "$sudo chroot $chroot_tmp /bin/su $luser -c bash"; die "FATAL $program_name: could not exec chroot to $chroot_tmp ($!)" } @@ -486,7 +486,7 @@ if ($run{dkms} && $run{dkms_todo}) { my $s = sub { if ($run{main}) { - print {$run{LOG}} "$program_name: dumping cache...\n"; + plog("dumping cache..."); dump_cache_par(\%run); $Data::Dumper::Indent = 0; $Data::Dumper::Terse = 1; @@ -522,7 +522,7 @@ do { if ($run{debug}) { $run{debug}++ == 2 and exit } $done++; mkdir "$local_spool/log/$srpm"; - print {$run{LOG}} "$program_name: packages $srpm [$done/$to_compile]\n"; + plog("packages $srpm [$done/$to_compile]"); # FIXME unfortunately urpmi stalls quite often my $retry = 0; # @@ -550,7 +550,7 @@ do { } #($maintainer, $cc) = ($config->{admin},''); - print {$run{LOG}} "$program_name: adding local user $luser into $chroot_tmp...\n" if $run{verbose}; + plog(1, "adding local user $luser into $chroot_tmp..."); add_local_user($chroot_tmp, \%run, $config, $luser, $run{uid}) or next; my $old_srpm = $srpm; @@ -562,7 +562,7 @@ do { next } - print {$run{LOG}} "$program_name: installing build dependencies of $srpm...\n" if $run{verbose}; + plog(1, "installing build dependencies of $srpm..."); my $path_srpm = "$chroot_tmp/home/$luser/rpm/SRPMS/"; # # on x86_64 the rpm database is getting corrupted and sometimes rpm do not found anymore @@ -602,12 +602,12 @@ do { callback => sub { my ($opt, $output) = @_; if ($run{stop}) { - print {$run{LOG}} "$program_name: dumping to a chrooted shell into $chroot_tmp (pid $$)\n"; + plog("dumping to a chrooted shell into $chroot_tmp (pid $$)"); # exec does not work because it seems stdin and out are shared between children system("$sudo chroot $chroot_tmp /bin/su $luser -c bash"); exit } - print {$run{LOG}} "$program_name: calling callback for $opt->{hash}\n" if $run{verbose} > 4; + plog(5, "calling callback for $opt->{hash}"); if ($run{unionfs_tmp} && $output =~ /no space left on device/i) { print {$run{LOG}} "ERROR $program_name: running out of space to compile $srpm in unionfs mode, will recompile it in normal mode\n"; $cache->{no_unionfs}{$srpm} = 1; @@ -619,7 +619,7 @@ do { } elsif ($output =~ /bin\/ld: cannot find -l(\S*)|configure.*error.* (?:-l([^\s]+)|([^\s]+) includes)/) { my $missing = $1; my @rpm = find_provides(\%run, \%pack_provide, $missing); - print {$run{LOG}} "$program_name: likely @rpm ($missing-devel) needed to rebuilt $srpm is not in build_requires\n" if $run{verbose} > 4; + plog(5, "likely @rpm ($missing-devel) needed to rebuilt $srpm is not in build_requires"); if ($maintainer ne 'NOT_FOUND') { $opt->{mail} = $maintainer; #$opt->{mail} .= ", other_maint"; @@ -689,15 +689,15 @@ do { $run{status}{$srpm} = 'ok'; delete $cache->{failure}{$srpm} if defined $cache->{failure}{$srpm}; if ($run{debug}) { - print {$run{LOG}} "$program_name: debug mode, skip other packages\n"; + plog("debug mode, skip other packages"); exit } elsif ($run{group}) { $rebuild = 1; - print {$run{LOG}} "$program_name: group mode, keep packages for local media\n"; + plog("group mode, keep packages for local media"); $run{done}{$srpm} = $done; $urpmi->add_to_local_media($chroot_tmp, $srpm, $luser); } else { - print {$run{LOG}} "$program_name: build successful, copying packages to $local_spool.\n"; + plog("build successful, copying packages to $local_spool."); system("cp $chroot_tmp/home/$luser/rpm/RPMS/*/*.rpm $local_spool &>/dev/null") and print {$run{LOG}} "ERROR: could not copy rpm files from $chroot_tmp/home/$luser/rpm/RPMS/ to $local_spool ($!)\n"; if ($run{copy_srpm}) { # replace the old srpm @@ -716,7 +716,7 @@ do { clean_chroot($chroot_tmp, $chroot_tar, \%run, $config, 1) if !$run{debug}; -print {$run{LOG}} "$program_name: reprocess generated packages queue\n" if $run{verbose}; +plog(1, "reprocess generated packages queue"); process_queue($config, \%run, \@wrong_rpm); dump_cache_par(\%run); @@ -740,7 +740,7 @@ if ($config->{rsync_to} && !$run{no_rsync}) { } # one last try to clean -print {$run{LOG}} "$program_name: try to clean remaining unionfs\n" if $run{verbose}; +plog(1, "try to clean remaining unionfs"); if ($run{unionfs}) { my ($dir) = $run{unionfs_dir} =~ /(.*)\/[^\/]+\/?/; remove_chroot(\%run, $dir, \&clean_all_unionfs) @@ -817,7 +817,7 @@ sub process_queue { foreach my $rpm (readdir $rpmdir) { my ($rarch, $srpm) = $urpmi->update_srpm($dir, $rpm, $wrong_rpm); $rarch or next; - print {$run{LOG}} "$program_name: $rpm\n"; + plog("$rpm"); next if !$run->{upload}; # recheck if the package has not been uploaded in the meantime my $rpms_dir = "$config->{repository}/$run->{distro}/$run->{my_arch}/media/$run->{media}/"; @@ -1177,3 +1177,15 @@ sub check_sudo_access { 0 } +# Print messages to log file. If two parameters are given, the first +# one is the log level. +# +sub plog { + if ($#_) { + print {$run{LOG}} "$program_name: $_[1]\n" + if ($_[0] >= $run{verbose}); + } else { + print {$run{LOG}} "$program_name: $_[0]\n"; + } +} + |