put the footer in one frigging file, whew
[freeside.git] / fs_selfservice / FS-SelfService / freeside-selfservice-clientd
index 5a05838..bdc8e15 100644 (file)
@@ -43,6 +43,7 @@ $SIG{__WARN__} = \&_logmsg;
 
 warn "Creating $lock_file\n" if $Debug;
 open(LOCKFILE,">$lock_file") or die "can't open $lock_file: $!";
+close LOCKFILE;
 
 warn "Creating $socket\n" if $Debug;
 my $uaddr = sockaddr_un($socket);
@@ -56,8 +57,9 @@ if ( -e $pid_file ) {
   open(PIDFILE,"<$pid_file");
   my $old_pid = <PIDFILE>;
   close PIDFILE;
-  $old_pid =~ /^(\d+)$/;
-  kill 'TERM', $1;
+  if ( $old_pid =~ /^(\d+)$/ ) {
+    kill 'TERM', $1;
+  }
 }
 open(PIDFILE,">$pid_file");
 print PIDFILE "$$\n";
@@ -256,6 +258,9 @@ sub lock_write {
   #broken on freebsd?
   #flock(STDOUT, LOCK_EX) or die "FATAL: can't lock write stream: $!";
 
+  #open a new one for each kid to get a unique lock
+  open(LOCKFILE,">$lock_file") or die "can't open $lock_file: $!";
+
   flock(LOCKFILE, LOCK_EX) or die "FATAL: can't lock $lock_file: $!";
 }