-sub fetchownfile (\@$$) {
- my ($ary_ref,$fn_str,$lock_str) = @_;
- die "$configfile:$.: lockfile name for $fn_str not".
- " defined (use lockpasswd/lockgroup)\n" unless length $lock_str;
- if ($lock_str ne '/dev/null' && !$no_act) {
- $lock_str= "$fn_str$lock_str" unless $lock_str =~ m,^/,;
- link $fn_str,$lock_str or die "cannot lock $fn_str by creating $lock_str: $!\n";
- push @unlocks,$lock_str;
+sub lockstyle_ ($$) {
+ my ($fn,$lock) = @_;
+
+ die "$configfile:$.: locking mechanism for $fn not".
+ " defined (use lockpasswd/lockgroup)\n";
+}
+
+sub abslock (@) {
+ my ($fn,$lock) = @_;
+
+ $fn= "/etc/$fn";
+ $lock= "$fn$lock" unless $lock =~ m,^/,;
+ return ($fn,$lock);
+}
+
+sub lock_none ($$) { return (abslock(@_))[0]; }
+sub unlock_none ($$) { }
+
+sub lock_link ($$) {
+ my ($fn,$lock) = abslock(@_);
+ link $fn,$lock or die "cannot lock $fn by creating $lock: $!\n";
+ return $fn;
+}
+sub unlock_link ($$) {
+ my ($fn,$lock) = abslock(@_);
+ unlink $lock or warn "unable to unlock by removing $lock: $!\n";
+}
+
+sub lock_runvia ($$) {
+ my ($fn,$lock) = @_;
+ my ($evn);
+ $evn= "SYNC_ACCOUNTS_RUNVIA_LOCKEDGOT_$fn";
+ return $ENV{$evn} if exists $ENV{$evn};
+
+ @na= map {
+ s/\W/ sprintf("%%%02x", unpack("C", $&)) /ge;
+ $_;
+ } ($fn,@orgargv);
+ $ENV{'SYNC_ACCOUNTS_RUNVIA_INFO'}= join(":", @na);
+ $ENV{'EDITOR'}= $0;
+ delete $ENV{'VISUAL'};
+ exec $lock; die "cannot lock $fn by executing $lock: $!\n";
+}
+sub unlock_runvia ($$) { }
+
+sub fetchownfile (\@$$$$) {
+ my ($ary_ref,$fn_str,$nfields,$style,$lock_arg) = @_;
+ my ($fn_use, $record, $fn_emsg);
+ $fn_emsg= $fn_str;
+ if (!$no_act) {
+ $fn_use= &{ "lock_$style" } ($fn_str, $lock_arg);
+ push @unlocks, [ $fn_str, $style, $lock_arg ];
+ $savebackto{$fn_str}= $fn_use;
+ } else {
+ $fn_use= $fn_emsg= "/etc/".$file{$fn_str,$PW_format};