From 0c515f17c44344813e8949fbb684b357ad70cfdf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 May 1998 08:52:12 +0000 Subject: [PATCH] added two new options "max connections" and "lock file" --- Makefile.in | 2 +- clientserver.c | 5 ++ connection.c | 123 +++++++++++++++++++++++++++++++++++++++++++++++++ loadparm.c | 7 +++ util.c | 17 +++++++ 5 files changed, 153 insertions(+), 1 deletion(-) create mode 100644 connection.c diff --git a/Makefile.in b/Makefile.in index 43785150..a222a813 100644 --- a/Makefile.in +++ b/Makefile.in @@ -23,7 +23,7 @@ SHELL=/bin/sh LIBOBJ=lib/getopt.o lib/fnmatch.o lib/zlib.o lib/compat.o OBJS1=rsync.o exclude.o util.o md4.o main.o checksum.o match.o syscall.o log.o OBJS2=options.o flist.o io.o compat.o hlink.o token.o uidlist.o socket.o -DAEMON_OBJ = params.o loadparm.o clientserver.o access.o +DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o OBJS=$(OBJS1) $(OBJS2) $(DAEMON_OBJ) $(LIBOBJ) # note that the -I. is needed to handle config.h when using VPATH diff --git a/clientserver.c b/clientserver.c index 32deee76..18d9494e 100644 --- a/clientserver.c +++ b/clientserver.c @@ -108,6 +108,11 @@ static int rsync_module(int fd, int i) return -1; } + if (!claim_connection(lp_lock_file(), lp_max_connections())) { + rprintf(FERROR,"ERROR: max connections reached\n"); + return -1; + } + rprintf(FINFO,"rsync on module %s from %s (%s)\n", lp_name(i), host, addr); diff --git a/connection.c b/connection.c new file mode 100644 index 00000000..fc7c6667 --- /dev/null +++ b/connection.c @@ -0,0 +1,123 @@ +/* + Copyright (C) Andrew Tridgell 1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* support the max connections option */ +#include "rsync.h" + +int yield_connection(char *fname, int max_connections) +{ + int fd, i; + pid_t mypid=getpid(), pid=0; + + if (max_connections <= 0) + return 1; + + fd = open(fname,O_RDWR); + if (fd == -1) { + rprintf(FERROR,"Couldn't open lock file %s (%s)\n",fname,strerror(errno)); + return 0; + } + + if (!lock_file(fd)) { + rprintf(FERROR,"failed to lock %s\n", fname); + close(fd); + return 0; + } + + /* find the right spot */ + for (i=0;i