diff options
author | ivan <ivan> | 2003-09-25 10:28:13 +0000 |
---|---|---|
committer | ivan <ivan> | 2003-09-25 10:28:13 +0000 |
commit | 9679b64218a5bb0b148d07582589dd8ef0de7567 (patch) | |
tree | 3268918b7dafe2ec864a0d17004f86b6d488966d /fs_selfservice/FS-SelfService/freeside-selfservice-clientd | |
parent | daeb70ea28f8a3e0db500f8a0e107221f4542d30 (diff) |
freebsd portability fix
Diffstat (limited to 'fs_selfservice/FS-SelfService/freeside-selfservice-clientd')
-rw-r--r-- | fs_selfservice/FS-SelfService/freeside-selfservice-clientd | 33 |
1 files changed, 30 insertions, 3 deletions
diff --git a/fs_selfservice/FS-SelfService/freeside-selfservice-clientd b/fs_selfservice/FS-SelfService/freeside-selfservice-clientd index f13dd42d7..438d472c9 100644 --- a/fs_selfservice/FS-SelfService/freeside-selfservice-clientd +++ b/fs_selfservice/FS-SelfService/freeside-selfservice-clientd @@ -5,7 +5,7 @@ # This is run REMOTELY over ssh by freeside-selfservice-server use strict; -use subs qw(spawn logmsg); +use subs qw(spawn logmsg lock_write unlock_write); use Fcntl qw(:flock); use POSIX qw(:sys_wait_h); use Socket; @@ -25,6 +25,8 @@ my $pid_file = "$socket.pid"; my $log_file = "/usr/local/freeside/selfservice.log"; +my $lock_file = "/usr/local/freeside/selfservice.writelock"; + #my $me = '[client]'; $|=1; @@ -35,6 +37,9 @@ $SIG{__WARN__} = \&_logmsg; #warn "$me Reading init data\n" if $Debug; #my $signup_init = +warn "Creating $lock_file\n" if $Debug; +open(LOCKFILE,">$lock_file") or die "can't open $lock_file: $!"; + warn "Creating $socket\n" if $Debug; my $uaddr = sockaddr_un($socket); my $proto = getprotobyname('tcp'); @@ -138,11 +143,19 @@ while (1) { #handle some commands weirdly? $packet->{_token}=$$; + warn "[child-$$] locking write stream" if $Debug > 1; + lock_write; + warn "[child-$$] sending packet to remote server" if $Debug > 1; - flock(STDOUT, LOCK_EX) or die "FATAL: can't lock write stream: $!"; nstore_fd($packet, \*STDOUT) or die "FATAL: can't send response: $!"; + + warn "[child-$$] flushing write stream" if $Debug > 1; STDOUT->flush or die "FATAL: can't flush: $!"; - flock(STDOUT, LOCK_UN) or die "FATAL: can't release write lock: $!"; + + warn "[child-$$] releasing write lock" if $Debug > 1; + unlock_write; + + warn "[child-$$] closing write stream" if $Debug > 1; close STDOUT or die "FATAL: can't close write stream: $!"; #??! warn "[child-$$] waiting for response from parent" if $Debug > 1; @@ -224,3 +237,17 @@ sub _logmsg { flock($log, LOCK_UN); close $log; } + +sub lock_write { + #broken on freebsd? + #flock(STDOUT, LOCK_EX) or die "FATAL: can't lock write stream: $!"; + + flock(LOCKFILE, LOCK_EX) or die "FATAL: can't lock $lock_file: $!"; +} + +sub unlock_write { + #broken on freebsd? + #flock(STDOUT, LOCK_UN) or die "FATAL: can't release write lock: $!"; + + flock(LOCKFILE, LOCK_UN) or die "FATAL: can't unlock $lock_file: $!"; +} |