From 589affa7c90d4f032b554162350625fd5aefb75b Mon Sep 17 00:00:00 2001 From: Donald Buczek Date: Fri, 1 Jul 2016 17:10:02 +0200 Subject: [PATCH] add lchown() , lmitime() --- clusterd | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/clusterd b/clusterd index 5a0d3a7..5335d89 100755 --- a/clusterd +++ b/clusterd @@ -511,6 +511,54 @@ sub udp_rx_amdtardata { system '/sbin/make-automaps'; } +our ($machine,$SYS_lchown,$SYS_mknod,$lmtime_sub); +chomp($machine=`uname -m`); +if ($machine eq 'i686') { + $SYS_lchown=198; # __NR_lchown32 in /usr/include/asm/unistd.h + $SYS_mknod=14; # __NR_mknod +} elsif ($machine eq 'x86_64') { + $SYS_lchown=94; # __NR_lchown in /usr/include/asm-x86_64/unistd.h + $SYS_mknod=133; # __NR_mknod +} elsif ($machine eq 'alpha') { + $SYS_lchown=208; # SYS_lchown in /usr/include/syscall.h + $SYS_mknod=14; # SYS_mknod +} elsif ($machine eq 'amd64') { + $SYS_lchown=254; # SYS_lchown in /usr/include/syscall.h + $SYS_mknod=14; # SYS_mknod +} else { + 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)=@_; + $SYS_lchown or return; + syscall($SYS_lchown,$path,$uid+0,$gid+0)==0 or return warn "$path: failed to lchown: $!\n"; +} + +sub lmtime { + my ($mtime,$path)=@_; + $lmtime_sub or return; + $lmtime_sub->($path,$mtime); +} + sub udp_rx_filedata { # set rx_filedata_done as a side effect