From 7ff06658a899afdc3a3445b66a88cb67ddc00fed Mon Sep 17 00:00:00 2001 From: Pascal Terjan Date: Sun, 26 Nov 2023 21:38:04 +0000 Subject: iurt: Fix / of the chroot belonging to the user instead of root --- NEWS | 1 + iurt_root_command | 12 +++++++++--- lib/Iurt/Chroot.pm | 19 +++++++++---------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/NEWS b/NEWS index de39941..2ab56eb 100644 --- a/NEWS +++ b/NEWS @@ -1,6 +1,7 @@ - iurt: Sort packages.arch.log - rebuild_perl_iurt: set --target to correctly build for armv7hl on aarch64 machines +- iurt: Fix / of the chroot belonging to the user instead of root 0.8.2.2 - ulri: Fix a crash after build failures diff --git a/iurt_root_command b/iurt_root_command index 87b5c5e..e64b1f7 100755 --- a/iurt_root_command +++ b/iurt_root_command @@ -45,7 +45,7 @@ $run{todo} = []; # [ "", $program_name, 0, "[--verbose ] [--modprobe ] - [--mkdir [--parents] ... ]", + [--mkdir [--parents] [--mode ] ... ]", "$program_name is a perl script to execute commands which need root privilege, it helps probram which needs occasional root privileges for some commands.", sub { $arg or usage($program_name, \@params) }, String::Escape::elide(join(' ', "Running $program_name", @ARGV), 120) ], @@ -77,7 +77,7 @@ $run{todo} = []; \&ln, "Linking files" ], [ "", "mkdir", [ - ["", "mkdir", -1, "[--parents] ... ", "mkdir create the given path", + ["", "mkdir", -1, "[--parents] [--mode ] ... ", "mkdir create the given path", sub { my ($tmp, @arg) = @_; $tmp->[0] ||= {}; @@ -87,7 +87,10 @@ $run{todo} = []; ["p", "parents", 0, "", "Also create needed parents directories", sub { my ($tmp) = @_; $tmp->[0]{parents} = 1; 1 }, "Set the parents flag"], - ], "[--parents] ... ", + ["m", "mode", 1, "", + "Set the given mode on created directories", + sub { my ($tmp, $arg) = @_; $tmp->[0]{mode} = $arg; 1 }, "Set the mode flag"], + ], "[--parents] [--mode ] ... ", "mkdir create the given path", \&mkdir, "Creating the path" ], @@ -244,6 +247,9 @@ sub mkdir { } else { mkdir $path; } + if ($opt->{mode}) { + chmod $opt->{mode}, $path; + } } 1; } diff --git a/lib/Iurt/Chroot.pm b/lib/Iurt/Chroot.pm index 34520d1..4949828 100644 --- a/lib/Iurt/Chroot.pm +++ b/lib/Iurt/Chroot.pm @@ -272,12 +272,13 @@ sub check_mounted { } sub check_chroot_need_update { - my ($tmp_chroot, $run) = @_; + my ($tmp_chroot, $run, $config) = @_; - my $tmp_urpmi = mktemp("$tmp_chroot/tmp.XXXXXX"); + sudo($config, '--mkdir', "-m", 01777, "$tmp_chroot/tmp"); + my $tmp_urpmi = mktemp("$tmp_chroot/tmp/tmp.XXXXXX"); mkdir_p("$tmp_urpmi/tmp"); my @installed_pkgs = grep { !/^gpg-pubkey/ } chomp_(cat_("$tmp_chroot/var/log/qa")); - my @available_pkgs = chomp_(`urpmq --urpmi-root $tmp_urpmi --use-distrib $run->{urpmi}{distrib_url} --list -f 2>/dev/null`); + my @available_pkgs = chomp_(`urpmq --urpmi-root $tmp_urpmi --use-distrib $run->{urpmi}{distrib_url} --list -f`); my @removed_pkgs = difference2(\@installed_pkgs, \@available_pkgs); rm_rf($tmp_urpmi); @@ -325,14 +326,15 @@ sub create_build_chroot_tar { plog('NOTIFY', "creating chroot"); - mkdir_p($tmp_chroot); + # Create this directory as root as it will be / of the chroot + sudo($config, "--mkdir", "-p", "$tmp_chroot"); if (!-f $chroot_tar) { plog("rebuild chroot tarball"); $rebuild = 1; } elsif (!$run->{fixed_media}) { plog('DEBUG', "decompressing /var/log/qa from $chroot_tar in $tmp_chroot"); sudo($config, '--untar', $chroot_tar, $tmp_chroot, "./var/log/qa"); - $rebuild = check_chroot_need_update($tmp_chroot, $run); + $rebuild = check_chroot_need_update($tmp_chroot, $run, $config); } if ($rebuild) { @@ -343,15 +345,12 @@ sub create_build_chroot_tar { return; } sudo($config, "--tar", $chroot_tar, $tmp_chroot); - # This rename may fail if for example tmp chroots are in another FS - # This does not matter as it will then be rm + untar - rename $tmp_chroot, $chroot; } if (!-d $chroot) { plog('DEBUG', "recreate chroot $chroot"); plog('NOTIFY', "recreate chroot"); - mkdir_p $chroot; + sudo($config, "--mkdir", "-p", "$tmp_chroot"); sudo($config, '--untar', $chroot_tar, $chroot); plog('NOTIFY', "chroot recreated in $chroot_tar (live in $chroot)"); } @@ -367,7 +366,7 @@ sub create_build_chroot_btrfs { plog('NOTIFY', "creating btrfs chroot"); # TODO: Handle $run{fixed_media} - if (check_chroot_need_update($chroot_ref, $run)) { + if (check_chroot_need_update($chroot_ref, $run, $config)) { sudo($config, '--btrfs_delete', $chroot_ref); if (!sudo($config, '--btrfs_create', $chroot_ref)) { plog('ERROR', "creating btrfs subvolume failed."); -- cgit v1.2.1