From 5a917d54e1bbae94b6d13da33930e1e31fa287df Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Wed, 13 Jun 2018 14:32:20 +0200 Subject: [PATCH] clusterd: Refactor lmtime setting Refactor the code, so that the mltime specific settings are done from inside the machine type switch. This makes it easier to add another machine type which can set the time of a symlink. --- clusterd/clusterd | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/clusterd/clusterd b/clusterd/clusterd index 32009bc..586e1e8 100755 --- a/clusterd/clusterd +++ b/clusterd/clusterd @@ -797,6 +797,19 @@ sub udp_rx_amdtardata { } our ($machine,$SYS_lchown,$SYS_mknod,$lmtime_sub); +our ($SYS_utimensat,$AT_FDCWD,$UTIME_OMIT,$AT_SYMLINK_NOFOLLOW); + +sub lmtime_unsupported { + my ($path,$mtime)=@_; + warn "$path: don't known how to change symlink mtime on target architecture\n"; +} +sub lmtime_utimensat { + my ($path,$mtime)=@_; + my $tsa=pack 'qqqq',0,$UTIME_OMIT,$mtime,0; + syscall($SYS_utimensat,$AT_FDCWD,$path,$tsa,$AT_SYMLINK_NOFOLLOW)==0 or return warn "$path: failed to lmtime: $!\n"; +} +$lmtime_sub=\&lmtime_unsupported; + chomp($machine=`uname -m`); if ($machine eq 'i686') { $SYS_lchown=198; # __NR_lchown32 in /usr/include/asm/unistd.h @@ -804,6 +817,12 @@ if ($machine eq 'i686') { } elsif ($machine eq 'x86_64') { $SYS_lchown=94; # __NR_lchown in /usr/include/asm-x86_64/unistd.h $SYS_mknod=133; # __NR_mknod + + $SYS_utimensat=280; # /usr/include/asm/unistd_64.h + $AT_FDCWD=-100; # /usr/include/fcntl.h + $UTIME_OMIT=(1<<30)-2; # /usr/include/bits/stat.h + $AT_SYMLINK_NOFOLLOW=0x100; # /usr/include/fcntl.h + $lmtime_sub=\&lmtime_utimensat; } elsif ($machine eq 'alpha') { $SYS_lchown=208; # SYS_lchown in /usr/include/syscall.h $SYS_mknod=14; # SYS_mknod @@ -814,23 +833,6 @@ if ($machine eq 'i686') { warn "unknown machine type $machine: symlink ownership can't be set.\n"; warn "unknown machine type $machine: named pipes,character and block devices can't be created\n"; } -if ($machine eq 'x86_64') { - our $SYS_utimensat=280; # /usr/include/asm/unistd_64.h - our $AT_FDCWD=-100; # /usr/include/fcntl.h - our $UTIME_OMIT=(1<<30)-2; # /usr/include/bits/stat.h - our $AT_SYMLINK_NOFOLLOW=0x100; # /usr/include/fcntl.h - - $lmtime_sub=sub { - my ($path,$mtime)=@_; - my $tsa=pack 'qqqq',0,$UTIME_OMIT,$mtime,0; - syscall($SYS_utimensat,$AT_FDCWD,$path,$tsa,$AT_SYMLINK_NOFOLLOW)==0 or return warn "$path: failed to lmtime: $!\n"; - } -} else { - $lmtime_sub=sub { - my ($path,$mtime)=@_; - warn "$path: don't known how to change symlink mtime on target architecture\n"; - } -} sub lchown { my ($uid,$gid,$path)=@_;