Since a successful stat() call does not reset $!, unconditionally
checking it afterward can cause a false error when $! was set earlier.
This causes device passthrough to always fail with "Device $path does
not exist" for privileged containers with an ostype that doesn't have a
matching config in /usr/share/lxc/config/<ostype>.common.conf.
Fix this by checking $! only when stat() actually fails. Also switch to
the $!{ENOENT} syntax, allowing the POSIX ENOENT import to be dropped.
Signed-off-by: Filip Schauer <[email protected]>
---
src/PVE/LXC/Tools.pm | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/src/PVE/LXC/Tools.pm b/src/PVE/LXC/Tools.pm
index 40dd270..ce2467e 100644
--- a/src/PVE/LXC/Tools.pm
+++ b/src/PVE/LXC/Tools.pm
@@ -4,7 +4,7 @@ package PVE::LXC::Tools;
use strict;
use warnings;
-use POSIX qw(ENOENT S_ISBLK S_ISCHR);
+use POSIX qw(S_ISBLK S_ISCHR);
use PVE::SafeSyslog;
@@ -159,9 +159,8 @@ sub get_device_mode_and_rdev($) {
die "Path is not defined\n" if !defined($path);
- my ($mode, $rdev) = (stat($path))[2, 6];
- die "Device $path does not exist\n" if $! == ENOENT;
- die "Error accessing device $path\n" if !defined($mode) || !defined($rdev);
+ my ($mode, $rdev) = (stat($path))[2, 6]
+ or die($!{ENOENT} ? "Device $path does not exist\n" : "Error accessing
device $path: $!\n");
die "$path is not a device\n" if !S_ISBLK($mode) && !S_ISCHR($mode);
return ($mode, $rdev);
--
2.47.3