| 1 | package Sys::Export::Linux; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Export subsets of a Linux system, including GNU libc special cases | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 3 | our $VERSION = '0.006'; # VERSION | |||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use v5.26; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use experimental qw( signatures ); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use parent 'Sys::Export::Unix'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use Cwd 'abs_path'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Sys::Export 'filedata'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Sys::Export::LogAny '$log'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 1 | ▶ | sub _build__trace_deps { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build__trace_deps: called CC=10 SCAR=36.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | my $self= shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | ▶ | if ($self->_can_run_in_src) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Seems Solaris has an 'strace' but it isn't compatible enough to pass tests. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | ▶ | $^O eq 'linux' or croak "Only Linux strace is supported"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # Are we going to attempt chrooting? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | ▶ | if ($self->src_abs ne '/') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | $self->{cmd_path_chroot} //= do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$self->{"cmd_path_chroot"} //= do {
chomp(my $chroot = `which chroot`);
-x $chroot or croak("chroot command not available or not executable");
$self->{"_log_trace"}->("chroot binary at $chroot") if $self->{"_log_trace"};
$chroot
}
MC/DC0%0/2
$self->{"cmd_path_chroot"} //= do {
chomp(my $chroot = `which chroot`);
-x $chroot or croak("chroot command not available or not executable");
$self->{"_log_trace"}->("chroot binary at $chroot") if $self->{"_log_trace"};
$chroot
}
$self->{"cmd_path_chroot"}
do {
chomp(my $chroot = `which chroot`);
-x $chroot or croak("chroot command not available or not executable");
$self->{"_log_trace"}->("chroot binary at $chroot") if $self->{"_log_trace"};
$chroot
}
Truth table0%0/3
A //= B
A= $self->{"cmd_path_chroot"}B= do {
chomp(my $chroot = `which chroot`);
-x $chroot or croak("chroot command not available or not executable");
$self->{"_log_trace"}->("chroot binary at $chroot") if $self->{"_log_trace"};
$chroot
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | chomp(my $chroot= `which chroot`); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | -x $chroot or croak "chroot command not available or not executable"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | $self->{_log_trace}->("chroot binary at $chroot") if $self->{_log_trace}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | $chroot; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | $self->{cmd_path_strace} //= do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$self->{"cmd_path_strace"} //= do {
chomp(my $strace = `which strace`);
-x $strace or croak("strace command not available or not executable");
$self->{"_log_trace"}->("strace binary at $strace") if $self->{"_log_trace"};
$strace
}
MC/DC0%0/2
$self->{"cmd_path_strace"} //= do {
chomp(my $strace = `which strace`);
-x $strace or croak("strace command not available or not executable");
$self->{"_log_trace"}->("strace binary at $strace") if $self->{"_log_trace"};
$strace
}
$self->{"cmd_path_strace"}
do {
chomp(my $strace = `which strace`);
-x $strace or croak("strace command not available or not executable");
$self->{"_log_trace"}->("strace binary at $strace") if $self->{"_log_trace"};
$strace
}
Truth table33%1/3
A //= B
A= $self->{"cmd_path_strace"}B= do {
chomp(my $strace = `which strace`);
-x $strace or croak("strace command not available or not executable");
$self->{"_log_trace"}->("strace binary at $strace") if $self->{"_log_trace"};
$strace
}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | chomp(my $strace= `which strace`); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | ▶ | -x $strace or croak "strace command not available or not executable"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 0 | ▶ | $self->{_log_trace}->("strace binary at $strace") if $self->{_log_trace}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $strace; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | return $self->can('_trace_deps_linux_strace'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $self->next::method(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | sub _trace_deps_linux_strace($self, @argv) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_trace_deps_linux_strace: not called CC=21 SCAR=61.4
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # Are we going to attempt chrooting? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | unshift @argv, $self->{cmd_path_chroot}, $self->src_abs | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | unless $self->src_abs eq '/'; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | # Tell strace to write to a pipe, while redirecting command output to /dev/null | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | open my $devnull, '+<', '/dev/null' or croak "open(/dev/null): $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | pipe(my $r, my $w) // croak "pipe: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
pipe(my $r, my $w) // croak("pipe: $!")
MC/DC0%0/1
pipe(my $r, my $w) // croak("pipe: $!")
pipe(my $r, my $w)
Truth table0%0/2
A
A= pipe(my $r, my $w)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | pipe(my $err_r, my $err_w) // croak "pipe: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
pipe(my $err_r, my $err_w) // croak("pipe: $!")
MC/DC0%0/1
pipe(my $err_r, my $err_w) // croak("pipe: $!")
pipe(my $err_r, my $err_w)
Truth table0%0/2
A
A= pipe(my $err_r, my $err_w)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | my $pid= fork // croak "fork: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
fork // croak("fork: $!")
MC/DC0%0/1
fork // croak("fork: $!")
fork
Truth table0%0/2
A
A= fork
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | if (!$pid) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | close $r; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | close $err_r; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | eval { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | chdir $self->src_abs or die "chdir: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ▶ | POSIX::dup2(fileno $devnull, 0) or die "dup2(->0): $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | POSIX::dup2(fileno $devnull, 1) or die "dup2(->1): $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | POSIX::dup2(fileno $devnull, 2) or die "dup2(->2): $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | ▶ | POSIX::dup2(fileno $w, 3) or die "dup2(->3): $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $^F= 3; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | unshift @argv, $self->{cmd_path_strace}, -o => "/proc/self/fd/3", -e => 'trace=open,openat'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | exec @argv | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | or die "exec(@argv): $!"; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | $err_w->print($@); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | $err_w->close; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | POSIX::_exit(2); # forcibly exit rather than bubble up the stack | |||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | close $w; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | close $err_w; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my %deps; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | my $err= do { local $/; <$err_r> }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | if (length $err) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | waitpid($pid, 0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | die $err; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | ▶ | $self->{_log_trace}->("Reading strace output") if $self->{_log_trace}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | while (<$r>) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | ▶ | $self->{_log_trace}->($_) if $self->{_log_trace}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | $deps{$1}= 1 if /^open(?:at)?\(.*?"(.*?)",.*?= [0-9]/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | $self->{_log_trace}->("Done reading strace") if $self->{_log_trace}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | waitpid($pid,0); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my $wstat= $?; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | $self->{_log_trace}->("Command exited with $wstat") if $self->{_log_trace}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | croak "straced command failed: wstat = $wstat" | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | if $wstat; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | return \%deps; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 14 | ▶ | sub parse_ld_so_conf($self, $conf_path= 'etc/ld.so.conf') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_ld_so_conf: called CC=8 SCAR=20.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 14 | my $data= filedata($self->src_abs . $conf_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 14 | my @libs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 14 | for (split /\n/, $$data) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 46 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 46 | ▶ | next if /^\s*(#|\z)/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 32 | ▶ | if (/^\s*include (\S+)/) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | my $pattern= $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # relative paths are relative to the config file's parent directory | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 6 | ▶ | my $prefix= $pattern =~ s{^/}{}? '' : ($conf_path =~ s{[^/]+\z}{}r); | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | push @libs, $self->parse_ld_so_conf($_) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 6 | for $self->src_glob($prefix.$pattern); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | elsif (m{^/}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 26 | push @libs, substr($_, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $log->warn("parse_ld_so_conf: unknown syntax at '$_'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 14 | return @libs; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 4 | ▶ | sub _build_src_lib_path($self) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_src_lib_path: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 4 | my $paths= $self->next::method(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # ld.so.conf may or may not be used on this host | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 4 | ▶ | if (defined $self->_src_abs_path('etc/ld.so.conf')) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 3 | ▶ | eval { $paths= $self->_distinct_abs_directories(1, @$paths, $self->parse_ld_so_conf) } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | or $self->log->warn("Failed to parse ld.so.conf: $@"); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 4 | return $paths; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 2 | ▶ | sub parse_nsswitch_conf($self, $conf_path= 'etc/nsswitch.conf') { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_nsswitch_conf: called CC=5 SCAR=16.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 2 | my $data= filedata($self->src_abs . $conf_path); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 2 | my @db_conf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 2 | for (split /\n/, $$data) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 32 | chomp; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 32 | ▶ | next if /^\s*(#|\z)/; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 26 | ▶ | if (m{^\s*([^\s:]+)\s*:\s*(\S.+)}) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 26 | push @db_conf, $1 => [ split /\s+/, $2 ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $log->warn("parse_nsswitch_conf: unknown syntax at '$_'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | return @db_conf; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 1 | ▶ | sub add_nsswitch_libs($self, @module_names) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_nsswitch_libs: called CC=8 SCAR=21.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | ▶ | if (!@module_names) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 1 | my %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 1 | for ($self->parse_nsswitch_conf) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 26 | ▶ | next unless ref eq 'ARRAY'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 13 | ++$seen{$_} for @$_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 1 | @module_names= sort keys %seen; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 1 | my @libpath= $self->src_lib_path_list; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 1 | ns_module: for (@module_names) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | 3 | my $pattern= "libnss_$_.*"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 3 | for my $libdir (@libpath) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | 3 | $log->tracef("Look for %s in %s", $pattern, $libdir); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 3 | ▶ | if (my @match= $self->src_glob("$libdir/$pattern")) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 3 | $self->add(@match); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 3 | next ns_module; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | $log->warn("glibc nss module not found: $_"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 1 | ▶ | sub add_passwd($self, %options) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_passwd: called CC=6 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # If the dst_userdb hasn't been created, create it by filtering the src_userdb by which | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # group and user ids have been seen during the export. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | my $db= $self->dst_userdb // Sys::Export::Unix::UserDB->new( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | 1 | ▶ | auto_import => ($self->{src_userdb} //= $self->_build_src_userdb), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition16%1/6
$self->dst_userdb // "Sys::Export::Unix::UserDB"->new("auto_import", $self->{"src_userdb"} //= $self->_build_src_userdb)
$self->{"src_userdb"} //= $self->_build_src_userdb
MC/DC0%0/2
$self->dst_userdb // "Sys::Export::Unix::UserDB"->new("auto_import", $self->{"src_userdb"} //= $self->_build_src_userdb)
$self->dst_userdb
"Sys::Export::Unix::UserDB"->new("auto_import", $self->{"src_userdb"} //= $self->_build_src_userdb)
MC/DC0%0/2
$self->{"src_userdb"} //= $self->_build_src_userdb
$self->{"src_userdb"}
$self->_build_src_userdb
Truth table33%1/3
A // B
A= $self->dst_userdbB= "Sys::Export::Unix::UserDB"->new("auto_import", $self->{"src_userdb"} //= $self->_build_src_userdb)
Truth table0%0/3
A //= B
A= $self->{"src_userdb"}B= $self->_build_src_userdb
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 1 | $db->group($_) for keys $self->dst_gid_used->%*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | 1 | $db->user($_) for keys $self->dst_uid_used->%*; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | $db->save(\my %contents); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 1 | ▶ | my $etc_path= $options{etc_path} // 'etc'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$options{"etc_path"} // "etc"
MC/DC0%0/1
$options{"etc_path"} // "etc"
$options{"etc_path"}
Truth table50%1/2
A
A= $options{"etc_path"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 1 | $self->add([ dir755 => "$etc_path", { uid => 0, gid => 0 }]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | $self->add([ file644 => "$etc_path/passwd", $contents{passwd}, { uid => 0, gid => 0 }]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | $self->add([ file600 => "$etc_path/shadow", $contents{shadow}, { uid => 0, gid => 0 }]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 1 | $self->add([ file644 => "$etc_path/group", $contents{group}, { uid => 0, gid => 0 }]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | sub add_localtime($self, $tz_name) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_localtime: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | ▶ | if (exists $self->{dst_path_set}{"usr/share/zoneinfo/$tz_name"} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
Condition0%0/6
exists $self->{"dst_path_set"}{"usr/share/zoneinfo/$tz_name"} or $self->_dst->can("dst_abs") and -f $self->_dst->dst_abs . $tz_name
$self->_dst->can("dst_abs") and -f $self->_dst->dst_abs . $tz_name
MC/DC0%0/3
exists $self->{"dst_path_set"}{"usr/share/zoneinfo/$tz_name"} or $self->_dst->can("dst_abs") and -f $self->_dst->dst_abs . $tz_name
exists $self->{"dst_path_set"}{"usr/share/zoneinfo/$tz_name"}
$self->_dst->can("dst_abs")
-f $self->_dst->dst_abs . $tz_name
Truth table0%0/4
A or B and C
A= exists $self->{"dst_path_set"}{"usr/share/zoneinfo/$tz_name"}B= $self->_dst->can("dst_abs")C= -f $self->_dst->dst_abs . $tz_name
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | || ($self->_dst->can('dst_abs') && -f $self->_dst->dst_abs . $tz_name) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | # zoneinfo is exported, and includes this timezone, so symlink to it | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $self->add([ sym => "etc/localtime" => "../usr/share/zoneinfo/$tz_name" ]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | elsif (defined (my $src_path= $self->_src_abs_path("usr/share/zoneinfo/$tz_name"))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | 0 | $self->add([ file644 => 'etc/localtime', { data_path => $self->src_abs . $src_path } ]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | elsif (defined (my $path= abs_path("/usr/share/zoneinfo/$tz_name"))) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $self->add([ file644 => 'etc/localtime', { data_path => $path } ]); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | croak "Can't find 'usr/share/zoneinfo/$tz_name' in destination, source, or host filesystem"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | # Avoiding dependency on namespace::clean | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | 3 | delete @{Sys::Export::Linux::}{qw( croak carp confess abs_path filedata )}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||