diff options
author | Florent Villard <warly@mandriva.com> | 2006-08-17 07:15:22 +0000 |
---|---|---|
committer | Florent Villard <warly@mandriva.com> | 2006-08-17 07:15:22 +0000 |
commit | 2406589d2b25a44797e1ec7aed6092be35f8600a (patch) | |
tree | e0afd8e893c34bbf4bc61e31c1d2edb702fb5e84 | |
parent | 790d2219715e7a8026b4a18addbd08afb34ff51f (diff) | |
download | iurt-2406589d2b25a44797e1ec7aed6092be35f8600a.tar iurt-2406589d2b25a44797e1ec7aed6092be35f8600a.tar.gz iurt-2406589d2b25a44797e1ec7aed6092be35f8600a.tar.bz2 iurt-2406589d2b25a44797e1ec7aed6092be35f8600a.tar.xz iurt-2406589d2b25a44797e1ec7aed6092be35f8600a.zip |
now running environment is also given to clean_all_unionfs
-rwxr-xr-x | iurt2 | 195 |
1 files changed, 18 insertions, 177 deletions
@@ -31,15 +31,15 @@ # use strict; use RPM4::Header; -use Iurt::Config qw(config_usage get_date config_init dump_cache_par); +use Iurt::Config qw(config_usage get_date get_prefix config_init dump_cache_par get_maint get_date get_prefix); use Data::Dumper; use URPM; use Iurt::DKMS; use Iurt::Urpmi; -use Iurt::Chroot qw(clean_chroot dump_rpmmacros add_local_user create_temp_chroot remove_chroot); -use Iurt::Process qw(perform_command clean); +use Iurt::Chroot qw(clean_chroot dump_rpmmacros add_local_user create_temp_chroot remove_chroot clean_all_chroot_tmp clean_unionfs clean_chroot_tmp); +use Iurt::Process qw(perform_command clean kill_for_good); +use Iurt::Mail qw(sendmail); use File::NCopy qw(copy); -use MIME::Words qw(encode_mimewords); # I did not manage to make locks work over the network #use File::lockf; use Mkcd::Commandline qw(parseCommandLine usage); @@ -390,7 +390,7 @@ if ($run{unionfs}) { } if ($run{unionfs}) { $run{unionfs_dir} = "$config->{local_home}/iurt_unionfs$debug_tag/"; - remove_chroot(\%run, \&clean_all_unionfs); + remove_chroot(\%run, $run{unionfs_dir}, \&clean_all_unionfs); $run{unionfs_dir} = "$run{unionfs_dir}/$run{user}/"; -d $run{unionfs_dir} or mkdir $run{unionfs_dir} } @@ -422,6 +422,7 @@ if ($run{no_compile} || !@{$run{todo}} && !$run{debug} && !$run{shell} && !$run{ exit } print {$run{LOG}} "$program_name: running with pid $$\n"; +$run{prefix} = get_prefix($luser); my $df = df $home; if ($df->{per} == 100) { @@ -468,7 +469,9 @@ if (!dump_rpmmacros(\%run, $config, "$chroot/home/builder/.rpmmacros")) { dump_rpmmacros(\%run, $config, "$chroot/home/builder/.rpmmacros") or die "FATAL $program_name: could not dump rpm macros to $chroot/home/builder/.rpmmacros" } -$done += $dkms->dkms_compile($local_spool, $done); +if ($run{dkms}) { + $done += $dkms->dkms_compile($local_spool, $done); +} # The next loop should be moved in a module someday @@ -519,7 +522,7 @@ do { my ($u_id, $chroot_tmp) = create_temp_chroot(\%run, $config, $cache, $union_id, $chroot_tmp, $chroot_tar, $srpm) or next; $union_id = $u_id; - $urpmi->urpmi_command($chroot, $luser); + $urpmi->urpmi_command($chroot_tmp, $luser); my ($srpm_name) = $srpm =~ /(.*)-[^-]+-[^-]+\.src\.rpm$/ or next; my ($maintainer, $cc); if (!$run{warn}) { @@ -658,7 +661,8 @@ do { opendir my $rpmfh, "$chroot_tmp/home/$luser/rpm/RPMS/$bindir"; push @packages, map { "/home/$luser/rpm/RPMS/$bindir/$_" } grep { /\.rpm$/ } readdir $rpmfh; } - $urpmi->install_packages($srpm, $local_spool, @packages) or next; + # We should fail here, but rpm is currently segfaulting when trying to install packages + $urpmi->install_packages($local_spool, $srpm, 'binary_test', "[REBUILD] binaries packages generated from $srpm do not install correctly", @packages) ;# or next; $run{status}{$srpm} = 'ok'; delete $cache->{failure}{$srpm} if defined $cache->{failure}{$srpm}; @@ -719,7 +723,7 @@ unlink "$run{pidfile_home}/$run{pidfile}" if $run{pidfile}; exit; sub clean_all_unionfs { - my ($unionfs_dir) = @_; + my ($run, $unionfs_dir) = @_; print {$run{LOG}} "Cleaning old unionfs remaining dir in $unionfs_dir\n" if $run{verbose} > 1; my $dir; if (!opendir $dir, $unionfs_dir) { @@ -733,98 +737,6 @@ sub clean_all_unionfs { closedir $dir } -sub clean_all_chroot_tmp { - my ($chroot_dir, $prefix) = @_; - print {$run{LOG}} "Cleaning old chroot remaining dir in $chroot_dir\n" if $run{verbose}; - my $dir; - if (!opendir $dir, $chroot_dir) { - print "ERROR $program_name: could not open $chroot_dir ($!)"; - return - } - foreach (readdir $dir) { - /$prefix.*$/ or next; - clean_chroot_tmp($chroot_dir, $_); - } - closedir $dir -} - -sub clean_mnt { - my ($run, $mount_point, $verbose) = @_; - return clean($run, $mount_point, "/sbin/fuser", "sudo /sbin/fuser -k", $verbose); -} - -sub clean_unionfs { - my ($unionfs_dir, $run, $r, $union_id) = @_; - -d "$unionfs_dir/unionfs.$r.$union_id" or return $union_id; - print {$run->{LOG}} "Cleaning $unionfs_dir/unionfs.$r.$union_id\n" if $run->{verbose} > 1; - my $nok = 1; - my $path = "$unionfs_dir/unionfs.$r.$union_id"; - while ($nok) { - $nok = 0; - foreach my $fs ([ 'proc', 'proc'],[ 'dev/pts', 'devpts']) { - my ($dir, $type) = @$fs; - if (-d "$path/$dir" && check_mounted("$path/$dir", $type)) { - print {$run->{LOG}} "$program_name clean_unionfs: umounting $path/$dir\n" if $run->{verbose} > 2; - if (system("sudo umount $path/$dir &>/dev/null")) { - print {$run->{LOG}} "ERROR $program_name: could not umount $path/$dir\n"; - return $union_id + 1 - } - } - } - foreach my $t ("unionfs",'tmpfs') { - # unfortunately quite oftem the unionfs is busy and could not be unmounted - my $d = "$unionfs_dir/$t.$r.$union_id"; - my $last; - if (-d $d && check_mounted($d, $t)) { - $nok = 1; - system("sudo /sbin/fuser -k $d &> /dev/null"); - print {$run->{LOG}} "$program_name: umounting $d\n" if $run->{verbose} > 2; - if (system(qq{sudo umount $d &> /dev/null})) { - print {$run->{LOG}} "WARNING $program_name: could not umount $d ($!)\n" if $run->{verbose} > 1; - return $union_id + 1; - } - } - } - } - foreach my $t ("unionfs",'tmpfs') { - my $d = "$unionfs_dir/$t.$r.$union_id"; - print {$run->{LOG}} "$program_name: removing $d\n" if $run->{verbose} > 1; - if (system(qq{sudo rm -rf $d})) { - print {$run->{LOG}} "ERROR $program_name: removing $d failed ($!)\n"; - return $union_id + 1 - } - } - $union_id -} - -sub clean_chroot_tmp { - my ($chroot_dir, $dir) = @_; - my $d = "$chroot_dir/$dir"; - foreach my $m ( 'proc', 'dev/pts') { - if (system("sudo umount $d/$m &>/dev/null") && $run{verbose} > 1) { - print {$run{LOG}} "ERROR $program_name: could not umount /$m in $d/\n" - } - } - print {$run{LOG}} "$program_name: cleaning $d\n" if $run{verbose}; - system("sudo /sbin/fuser -k $d &> /dev/null"); - print {$run{LOG}} "$program_name: removing $d\n" if $run{verbose}; - system(qq{sudo rm -rf $d}); -} - -sub check_mounted { - my ($mount_point, $type) = @_; - my $mount; - if (!open $mount, '/proc/mounts') { - print 'ERROR $program_name: could not open /proc/mounts'; - return - } - $mount_point =~ s,//+,/,g; - while (<$mount>) { - return 1 if /^\w+ $mount_point $type / - } - 0 -} - sub check_needed { my ($srpm, $cache, $provides) = @_; if (!defined $cache->{needed}{$srpm} && !ref $cache->{needed}{$srpm}) { return 1 } @@ -875,8 +787,9 @@ sub process_queue { return if !$run->{upload} && $quiet; my $dir = "$config->{local_upload}/iurt/$run->{distro_tag}/$run->{my_arch}/$run->{media}/"; opendir my $rpmdir, $dir or return; + my $urpmi = $run->{urpmi}; foreach my $rpm (readdir $rpmdir) { - my ($rarch, $srpm) = update_srpm($dir, $rpm, $wrong_rpm); + my ($rarch, $srpm) = $urpmi->update_srpm($dir, $rpm, $wrong_rpm); $rarch or next; print {$run{LOG}} "$program_name: $rpm\n"; next if !$run->{upload}; @@ -899,37 +812,6 @@ sub process_queue { closedir $rpmdir; } -sub update_srpm { - my ($dir, $rpm, $wrong_rpm) = @_; - my ($arch) = $rpm =~ /([^\.]+)\.rpm$/ or return 0; - my $srpm = $cache->{rpm_srpm}{$rpm}; - if (!$srpm) { - my $hdr = RPM4::Header->new("$dir/$rpm"); - $hdr or return 0; - $srpm = $hdr->queryformat('%{SOURCERPM}'); - $cache->{rpm_srpm}{$rpm} = $srpm - } - $srpm = fix_srpm_name($srpm, $rpm, $wrong_rpm); - $arch, $srpm -} - -sub sendmail { - my ($to, $cc, $subject, $text, $from, $debug) = @_; - do { print "Cannot find sender-email-address [$to]\n"; return } unless defined($to); - $from ||= $config->{packager}; - my $MAIL; - if (!$debug) { open $MAIL, "| /usr/sbin/sendmail -t" or return } else { open $MAIL, ">&STDOUT" or return } - my $sender = encode_mimewords($to); - my $subject = encode_mimewords($subject); - print $MAIL "To: $sender\n"; - if ($cc) { $cc = encode_mimewords($cc); print $MAIL "Cc: $cc\n" } - print $MAIL "From: $from\n"; - print $MAIL "Subject: $subject\n"; - print $MAIL "\n"; - print $MAIL $text; - close($MAIL) -} - sub check_arch { my ($hdr) = @_; my (@exclusive_arch) = $hdr->queryformat('%{EXCLUSIVEARCH}'); @@ -949,35 +831,6 @@ sub check_version { 0 } -sub fix_srpm_name { - my ($srpm, $rpm, $wrong_rpm) = @_; - my $old_srpm = $srpm; - if ($srpm =~ s/^lib64/lib/){ - push @$wrong_rpm, [ $old_srpm, $rpm ]; - $cache->{rpm_srpm}{$rpm} = $srpm - } - $srpm -} - -sub kill_for_good { - my ($pid) = @_; - use POSIX ":sys_wait_h"; - kill 14, $pid; - sleep 1; - waitpid(-1, WNOHANG); - if (getpgrp $pid != -1) { - kill 15, $pid; - sleep 1; - waitpid(-1, WNOHANG); - if (getpgrp $pid != -1) { - print STDERR "WARNING $program_name: have to kill -9 pid $pid\n"; - kill 9, $pid; - sleep 1; - waitpid(-1, WNOHANG); - } - } -} - sub check_chroot { my ($chroot, $chroot_tar, $run, $opt) = @_; print {$run{LOG}} "$program_name: checking basesystem tar\n" if $run{verbose}; @@ -1098,8 +951,9 @@ sub check_media { my $rpms_dir = "$config->{repository}/$run->{distro}/$run->{my_arch}/media/$run->{media}/$subdir/"; print {$run->{LOG}} "$program_name: checking current packages in $rpms_dir\n"; opendir my $rpmdir, $rpms_dir or die "Could not open $rpms_dir: $!"; + my $urpmi = $run->{urpmi}; foreach my $rpm (readdir $rpmdir) { - my ($rarch, $srpm) = update_srpm($rpms_dir, $rpm, $wrong_rpm); + my ($rarch, $srpm) = $urpmi->update_srpm($rpms_dir, $rpm, $wrong_rpm); $rarch or next; $cache->{queue}{$srpm} = 1; $run{status}{$srpm} = 'ok'; @@ -1358,20 +1212,7 @@ sub send_status_mail { } } print "$text\n"; - sendmail($run->{status_mail}, '' , "Iurt report for $run->{my_arch}/$run->{media}", "$text", 0, 0, 0) -} - -sub get_maint { - my ($run, $srpm) = @_; - my ($srpm_name) = $srpm =~ /(.*)-[^-]+-[^-]+\.[^.]+$/; - $srpm_name ||= $srpm; - if ($run{maint}{$srpm}) { - return $run{maint}{$srpm}, $srpm_name - } - my $maint = `rpmmon -s -p "$srpm_name"`; - chomp $maint; - $run{maint}{$srpm} = $maint; - $maint, $srpm_name + sendmail($run->{status_mail}, '' , "Iurt report for $run->{my_arch}/$run->{media}", "$text", 0, "Iurt", 0) } sub find_provides { |