]> git.proxmox.com Git - pve-common.git/commitdiff
swap raw syscall numbers with syscall.ph for easier porting
authorThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 10 May 2017 13:03:45 +0000 (15:03 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Wed, 24 May 2017 09:24:34 +0000 (11:24 +0200)
Raw syscall numbers were not platform independent, so replace them
with the helpers provided from the syscall.ph perl bits helper.

This makes reading the code easier as a nice side effect.

As syscall.ph is not an ordinary module and makes problems when it is
required by multiple modules we make a own module PVE::Syscall which
loads it and allows to export the necessary constants in a sane way.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
src/Makefile
src/PVE/Syscall.pm [new file with mode: 0644]
src/PVE/Tools.pm

index 05344f5723698dca371c0fcfe6f38e7b3ebad104..044d23cfd809fd578193014f1afcce9e5d5e178a 100644 (file)
@@ -23,6 +23,7 @@ LIB_SOURCES=                  \
        AtomicFile.pm           \
        INotify.pm              \
        Tools.pm                \
        AtomicFile.pm           \
        INotify.pm              \
        Tools.pm                \
+       Syscall.pm              \
        Exception.pm
 
 all:
        Exception.pm
 
 all:
diff --git a/src/PVE/Syscall.pm b/src/PVE/Syscall.pm
new file mode 100644 (file)
index 0000000..87db66a
--- /dev/null
@@ -0,0 +1,22 @@
+package PVE::Syscall;
+
+my %syscalls;
+BEGIN {
+    die "syscall.ph can only be required once!\n" if $INC{'syscall.ph'};
+    require("syscall.ph");
+    %syscalls = (
+       unshare => &SYS_unshare,
+       setns => &SYS_setns,
+       syncfs => &SYS_syncfs,
+       openat => &SYS_openat,
+       close => &SYS_close,
+       mkdirat => &SYS_mkdirat,
+       faccessat => &SYS_faccessat,
+    );
+};
+
+use constant \%syscalls;
+
+use base 'Exporter';
+
+our @EXPORT_OK   = keys(%syscalls);
index f84855d2b9c8d8f983de8e5d729fdc4a7d9bdc49..dd9cd0f8e5f0e4d0aed19ba3bb52a2cce4c2c723 100644 (file)
@@ -26,6 +26,7 @@ use Net::DBus qw(dbus_uint32 dbus_uint64);
 use Net::DBus::Callback;
 use Net::DBus::Reactor;
 use Scalar::Util 'weaken';
 use Net::DBus::Callback;
 use Net::DBus::Reactor;
 use Scalar::Util 'weaken';
+use PVE::Syscall;
 
 # avoid warning when parsing long hex values with hex()
 no warnings 'portable'; # Support for 64-bit ints required
 
 # avoid warning when parsing long hex values with hex()
 no warnings 'portable'; # Support for 64-bit ints required
@@ -1248,17 +1249,17 @@ sub parse_host_and_port {
 
 sub unshare($) {
     my ($flags) = @_;
 
 sub unshare($) {
     my ($flags) = @_;
-    return 0 == syscall(272, $flags);
+    return 0 == syscall(PVE::Syscall::unshare, $flags);
 }
 
 sub setns($$) {
     my ($fileno, $nstype) = @_;
 }
 
 sub setns($$) {
     my ($fileno, $nstype) = @_;
-    return 0 == syscall(308, $fileno, $nstype);
+    return 0 == syscall(PVE::Syscall::setns, $fileno, $nstype);
 }
 
 sub syncfs($) {
     my ($fileno) = @_;
 }
 
 sub syncfs($) {
     my ($fileno) = @_;
-    return 0 == syscall(306, $fileno);
+    return 0 == syscall(PVE::Syscall::syncfs, $fileno);
 }
 
 sub sync_mountpoint {
 }
 
 sub sync_mountpoint {
@@ -1390,7 +1391,7 @@ sub validate_ssh_public_keys {
 
 sub openat($$$;$) {
     my ($dirfd, $pathname, $flags, $mode) = @_;
 
 sub openat($$$;$) {
     my ($dirfd, $pathname, $flags, $mode) = @_;
-    my $fd = syscall(257, $dirfd, $pathname, $flags, $mode//0);
+    my $fd = syscall(PVE::Syscall::openat, $dirfd, $pathname, $flags, $mode//0);
     return undef if $fd < 0;
     # sysopen() doesn't deal with numeric file descriptors apparently
     # so we need to convert to a mode string for IO::Handle->new_from_fd
     return undef if $fd < 0;
     # sysopen() doesn't deal with numeric file descriptors apparently
     # so we need to convert to a mode string for IO::Handle->new_from_fd
@@ -1398,14 +1399,14 @@ sub openat($$$;$) {
     my $handle = IO::Handle->new_from_fd($fd, $flagstr);
     return $handle if $handle;
     my $err = $!; # save error before closing the raw fd
     my $handle = IO::Handle->new_from_fd($fd, $flagstr);
     return $handle if $handle;
     my $err = $!; # save error before closing the raw fd
-    syscall(3, $fd); # close
+    syscall(PVE::Syscall::close, $fd); # close
     $! = $err;
     return undef;
 }
 
 sub mkdirat($$$) {
     my ($dirfd, $name, $mode) = @_;
     $! = $err;
     return undef;
 }
 
 sub mkdirat($$$) {
     my ($dirfd, $name, $mode) = @_;
-    return syscall(258, $dirfd, $name, $mode) == 0;
+    return syscall(PVE::Syscall::mkdirat, $dirfd, $name, $mode) == 0;
 }
 
 # NOTE: This calls the dbus main loop and must not be used when another dbus
 }
 
 # NOTE: This calls the dbus main loop and must not be used when another dbus