Sys-Export
view release on metacpan or search on metacpan
lib/Sys/Export/Unix/WriteFS.pm view on Meta::CPAN
sub _apply_stat($self, $abs_path, $stat) {
my ($mode, $uid, $gid, $atime, $mtime)= (lstat $abs_path)[2,4,5,8,9]
or croak "Failed to stat file just created at '$abs_path': $!";
my $change_uid= defined $stat->{uid} && $stat->{uid} != $uid;
my $change_gid= defined $stat->{gid} && $stat->{gid} != $gid;
if ($change_uid || $change_gid) {
# only UID 0 can change UID, and only GID 0 or GID in supplemental groups can change GID.
$uid= -1 unless $change_uid && $> == 0;
$gid= -1 unless $change_gid && ($) == 0 || grep $stat->{gid}, split / /, $) );
# Only attempt change if able
POSIX::lchown($uid, $gid, $abs_path) or croak "lchown($uid, $gid, $abs_path): $!"
if $uid >= 0 || $gid >= 0;
}
my @delayed;
# Don't change permission bits on symlinks
if (!S_ISLNK($mode) && ($mode & 0xFFF) != ($stat->{mode} & 0xFFF)) {
# If changing permissions on a directory to something that removes our ability
# to write to it, delay this change until the end.
if (S_ISDIR($mode) && !(($stat->{mode} & 0222) && ($stat->{mode} & 0111))) {
t/81-qemu-initrd.t view on Meta::CPAN
# This is the script that runs inside docker to perform the export into the initrd
my ($uid, $gid)= ($<, $(+0);
mkfile("$tmp/export.pl", <<~END_PL, 0755);
#! /usr/bin/perl
use v5.26;
use warnings;
use lib "/opt/sys-export/lib";
use Sys::Export::CPIO;
use Sys::Export -src => '/', -dst => Sys::Export::CPIO->new("/opt/export/initrd.cpio");
chown $uid, $gid, "/opt/export/initrd.cpio";
add qw( proc sys dev tmp run var usr
bin/busybox bin/sh bin/date bin/cat bin/mount
),
[ file755 => 'init', { data_path => "/opt/export/init.sh" } ];
finish;
exit 0;
END_PL
# This is the script that is used as 'init' within the initrd, and generates a string that we
# look for in the kernel output.
( run in 0.896 second using v1.01-cache-2.11-cpan-5511b514fd6 )