Skip to content

Commit

Permalink
clusterd: Refactor lmtime setting
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
donald committed Jun 13, 2018
1 parent 98bb305 commit 5a917d5
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions clusterd/clusterd
Original file line number Diff line number Diff line change
Expand Up @@ -797,13 +797,32 @@ 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
$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

$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
Expand All @@ -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)=@_;
Expand Down

0 comments on commit 5a917d5

Please sign in to comment.