diff --git c/MANIFEST w/MANIFEST index 04ec4d0..c5ec244 100644 --- c/MANIFEST +++ w/MANIFEST @@ -9,6 +9,7 @@ t/smaps64 t/01.t t/02.t t/03.t +t/04.t lib/Linux/Smaps.pm mk_README.sh perl-Linux-Smaps.spec diff --git c/lib/Linux/Smaps.pm w/lib/Linux/Smaps.pm index 6ef4b03..91e2b31 100644 --- c/lib/Linux/Smaps.pm +++ w/lib/Linux/Smaps.pm @@ -220,6 +220,10 @@ sub update { return; } } + if ($!) { + $I->[M_lasterror]="read failed: $!"; + return; + } close $f; diff --git c/t/04.t w/t/04.t new file mode 100644 index 0000000..b1a458b --- /dev/null +++ w/t/04.t @@ -0,0 +1,20 @@ +use strict; +use Test::More; +use Linux::Smaps; + +my $init_pid = 1; + +my $init_exists = kill 0 => $init_pid; +if ($init_exists) { + plan skip_all => 'Probably running test suite as root, skipping this test...'; + exit 0; +} elsif (!$!{EPERM}) { + plan skip_all => "Unexpected: pid=$init_pid does not exist, skipping this test..."; + exit 0; +} + +plan tests => 2; + +my $s = eval { Linux::Smaps->new($init_pid) }; +like $@, qr{read failed}, "Permission denied to read process with pid $init_pid"; +ok !$s, "No object constructed";