rsync connection limit

Jevgenijs Kuznecovs kuznecovs at antivirus.lv
Wed May 24 14:18:14 GMT 2006


Hello!
In the attached file is patch for the option to set client connection limit.
We had problem for dead hosts, so default system timeout is not enough.

--conlimit option added

Will be great to see this patch in the future version, so we do not need 
to patch every time.
Thanks and Cheers, Eugene.

--
-------------- next part --------------
diff -Naur rsync-2.6.8/errcode.h rsync-2.6.8-new/errcode.h
--- rsync-2.6.8/errcode.h	Sat Dec 17 01:48:28 2005
+++ rsync-2.6.8-new/errcode.h	Wed May 24 16:19:59 2006
@@ -47,6 +47,8 @@
 
 #define RERR_TIMEOUT    30      /* timeout in data send/receive */
 
+#define RERR_CON_TIMEOUT 35
+
 /* Although it doesn't seem to be specified anywhere,
  * ssh and the shell seem to return these values:
  *
diff -Naur rsync-2.6.8/log.c rsync-2.6.8-new/log.c
--- rsync-2.6.8/log.c	Sat Apr  8 19:04:34 2006
+++ rsync-2.6.8-new/log.c	Wed May 24 16:19:27 2006
@@ -83,6 +83,7 @@
 	{ RERR_PARTIAL    , "some files could not be transferred" },
 	{ RERR_VANISHED   , "some files vanished before they could be transferred" },
 	{ RERR_TIMEOUT    , "timeout in data send/receive" },
+	{ RERR_CON_TIMEOUT, "timeout in connect()" },
 	{ RERR_CMD_FAILED , "remote shell failed" },
 	{ RERR_CMD_KILLED , "remote shell killed" },
 	{ RERR_CMD_RUN    , "remote command could not be run" },
diff -Naur rsync-2.6.8/options.c rsync-2.6.8-new/options.c
--- rsync-2.6.8/options.c	Wed Mar 29 02:09:36 2006
+++ rsync-2.6.8-new/options.c	Wed May 24 15:50:43 2006
@@ -93,6 +93,7 @@
 int daemon_over_rsh = 0;
 int do_stats = 0;
 int do_progress = 0;
+int do_timeout = 0;
 int keep_partial = 0;
 int safe_symlinks = 0;
 int copy_unsafe_links = 0;
@@ -506,6 +507,7 @@
   {"from0",           '0', POPT_ARG_NONE,   &eol_nulls, 0, 0, 0},
   {"numeric-ids",      0,  POPT_ARG_NONE,   &numeric_ids, 0, 0, 0 },
   {"timeout",          0,  POPT_ARG_INT,    &io_timeout, 0, 0, 0 },
+  {"contimeout",       0,  POPT_ARG_INT,    &do_timeout, 0, 0, 0 },
   {"rsh",             'e', POPT_ARG_STRING, &shell_cmd, 0, 0, 0 },
   {"rsync-path",       0,  POPT_ARG_STRING, &rsync_path, 0, 0, 0 },
   {"temp-dir",        'T', POPT_ARG_STRING, &tmpdir, 0, 0, 0 },
@@ -1612,6 +1614,12 @@
 			goto oom;
 		args[ac++] = arg;
 	}
+	
+	if (do_timeout) {
+		if (asprintf(&arg, "--contimeout=%d", do_timeout) < 0)
+			goto oom;
+		args[ac++] = arg;
+	}
 
 	if (bwlimit) {
 		if (asprintf(&arg, "--bwlimit=%d", bwlimit) < 0)
diff -Naur rsync-2.6.8/rsync.yo rsync-2.6.8-new/rsync.yo
--- rsync-2.6.8/rsync.yo	Sat Apr 22 18:38:34 2006
+++ rsync-2.6.8-new/rsync.yo	Wed May 24 16:21:48 2006
@@ -2448,6 +2448,7 @@
 dit(bf(24)) Partial transfer due to vanished source files
 dit(bf(25)) The --max-delete limit stopped deletions
 dit(bf(30)) Timeout in data send/receive
+dit(bf(35)) Timeout in connect()
 enddit()
 
 manpagesection(ENVIRONMENT VARIABLES)
diff -Naur rsync-2.6.8/socket.c rsync-2.6.8-new/socket.c
--- rsync-2.6.8/socket.c	Tue Apr 11 03:48:28 2006
+++ rsync-2.6.8-new/socket.c	Wed May 24 16:22:48 2006
@@ -37,6 +37,7 @@
 
 extern char *bind_address;
 extern int default_af_hint;
+extern int do_timeout;
 
 #ifdef HAVE_SIGACTION
 static struct sigaction sigact;
@@ -162,6 +163,13 @@
 	return -1;
 }
 
+/**
+ * connect() timeout handler based on alarm()
+ **/
+static RETSIGTYPE contimeout_handler(UNUSED(int val))
+{
+	exit_cleanup(RERR_CON_TIMEOUT);
+}
 
 /**
  * Open a socket to a tcp remote host with the specified port .
@@ -266,11 +274,23 @@
 			s = -1;
 			continue;
 		}
+		if ( do_timeout > 0 )
+		{
+			SIGACTION(SIGALRM, contimeout_handler);
+			alarm(do_timeout);
+		}
+		
 		if (connect(s, res->ai_addr, res->ai_addrlen) < 0) {
 			close(s);
 			s = -1;
 			continue;
 		}
+		
+		if ( do_timeout > 0 )
+		{
+			alarm(0);
+		}
+		
 		if (proxied
 		 && establish_proxy_connection(s, host, port,
 					       proxy_user, proxy_pass) != 0) {


More information about the rsync mailing list