Commit 21cafc50 authored by Wayne Davison's avatar Wayne Davison

Some minor improvements in claim_connection().

parent de80679b
...@@ -19,30 +19,27 @@ ...@@ -19,30 +19,27 @@
#include "rsync.h" #include "rsync.h"
/**************************************************************************** /* A simple routine to do connection counting. This returns 1 on success
simple routine to do connection counting * and 0 on failure, with errno also being set if the open() failed (errno
****************************************************************************/ * will be 0 if the lock request failed). */
int claim_connection(char *fname,int max_connections) int claim_connection(char *fname, int max_connections)
{ {
int fd, i; int fd, i;
if (max_connections <= 0) if (max_connections > 0) {
return 1; if ((fd = open(fname, O_RDWR|O_CREAT, 0600)) < 0)
fd = open(fname,O_RDWR|O_CREAT, 0600);
if (fd == -1) {
return 0; return 0;
/* Find a free spot. */
for (i = 0; i < max_connections; i++) {
if (lock_range(fd, i*4, 4))
return 1;
} }
/* find a free spot */ close(fd);
for (i=0;i<max_connections;i++) {
if (lock_range(fd, i*4, 4)) return 1;
} }
/* only interested in open failures */ /* A lock failure needs to return an errno of 0. */
errno = 0; errno = 0;
close(fd);
return 0; return 0;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment