Skip to content

Instantly share code, notes, and snippets.

@spiculator
Created June 12, 2013 08:25
Show Gist options
  • Save spiculator/5763664 to your computer and use it in GitHub Desktop.
Save spiculator/5763664 to your computer and use it in GitHub Desktop.
make rsync sleep every 10 seconds
diff -Naur rsync-3.0.6/Makefile.in rsync-3.0.6-sleepflag/Makefile.in
--- rsync-3.0.6/Makefile.in 2009-04-11 03:24:49.000000000 +0400
+++ rsync-3.0.6-sleepflag/Makefile.in 2010-08-05 22:05:32.000000000 +0400
@@ -35,7 +35,7 @@
OBJS1=flist.o rsync.o generator.o receiver.o cleanup.o sender.o exclude.o \
util.o main.o checksum.o match.o syscall.o log.o backup.o
OBJS2=options.o io.o compat.o hlink.o token.o uidlist.o socket.o hashtable.o \
- fileio.o batch.o clientname.o chmod.o acls.o xattrs.o
+ fileio.o batch.o clientname.o chmod.o acls.o xattrs.o sleeper.o
OBJS3=progress.o pipe.o
DAEMON_OBJ = params.o loadparm.o clientserver.o access.o connection.o authenticate.o
popt_OBJS=popt/findme.o popt/popt.o popt/poptconfig.o \
diff -Naur rsync-3.0.6/flist.c rsync-3.0.6-sleepflag/flist.c
--- rsync-3.0.6/flist.c 2009-04-26 18:51:50.000000000 +0400
+++ rsync-3.0.6-sleepflag/flist.c 2010-08-05 22:05:32.000000000 +0400
@@ -1645,6 +1645,7 @@
remainder = MAXPATHLEN - (p - fbuf);
for (errno = 0, di = readdir(d); di; errno = 0, di = readdir(d)) {
+ sleeper_sleep(); // TEAK
char *dname = d_name(di);
if (dname[0] == '.' && (dname[1] == '\0'
|| (dname[1] == '.' && dname[2] == '\0')))
diff -Naur rsync-3.0.6/io.c rsync-3.0.6-sleepflag/io.c
--- rsync-3.0.6/io.c 2009-03-13 19:46:39.000000000 +0300
+++ rsync-3.0.6-sleepflag/io.c 2010-08-05 22:05:32.000000000 +0400
@@ -182,6 +182,7 @@
{
time_t t;
+ sleeper_sleep(); // TEAK
if (!io_timeout || ignore_timeout)
return;
diff -Naur rsync-3.0.6/proto.h rsync-3.0.6-sleepflag/proto.h
--- rsync-3.0.6/proto.h 2009-05-08 21:43:22.000000000 +0400
+++ rsync-3.0.6-sleepflag/proto.h 2010-08-05 22:26:32.000000000 +0400
@@ -285,6 +285,8 @@
const char *who_am_i(void);
void successful_send(int ndx);
void send_files(int f_in, int f_out);
+void sleeper_init(unsigned _interval);
+void sleeper_sleep();
int try_bind_local(int s, int ai_family, int ai_socktype,
const char *bind_addr);
int open_socket_out(char *host, int port, const char *bind_addr,
diff -Naur rsync-3.0.6/rsync.h rsync-3.0.6-sleepflag/rsync.h
--- rsync-3.0.6/rsync.h 2009-02-14 18:57:50.000000000 +0300
+++ rsync-3.0.6-sleepflag/rsync.h 2010-08-05 22:05:32.000000000 +0400
@@ -1144,3 +1144,5 @@
#ifdef MAINTAINER_MODE
const char *get_panic_action(void);
#endif
+
+void sleeper_sleep(void); // TEAK
diff -Naur rsync-3.0.6/sleeper.c rsync-3.0.6-sleepflag/sleeper.c
--- rsync-3.0.6/sleeper.c 1970-01-01 03:00:00.000000000 +0300
+++ rsync-3.0.6-sleepflag/sleeper.c 2010-08-05 23:55:46.000000000 +0400
@@ -0,0 +1,41 @@
+#include <time.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#define HIGHLOADFLAGPATH "/home/hostlocal/pause-rsync-task.flag"
+
+static time_t previous = 0;
+static unsigned interval = 0;
+
+void sleeper_init(unsigned _interval)
+{
+ interval = _interval;
+ previous = time( NULL );
+ fprintf( stderr,
+ "Sleeper initialized, interval is %d seconds.\n", interval );
+}
+
+void sleeper_sleep()
+{
+ struct stat buf; // not really used
+ if( !interval ) {
+ sleeper_init( 10 );
+ //return; // sleeper was not initialized, nothing to do
+ }
+ time_t now = time( NULL );
+ if( now - previous >= interval ) {
+ fprintf( stderr, "Sleeping for %d seconds... ", interval );
+ fflush( stderr );
+ sleep( interval );
+ if( 0 == stat( HIGHLOADFLAGPATH, &buf ) ) {
+ fprintf( stderr, "sleeping while %s file exists (checking every %d seconds)... ", HIGHLOADFLAGPATH, interval );
+ fflush( stderr );
+ do {
+ sleep( interval );
+ } while( 0 == stat( HIGHLOADFLAGPATH, &buf ) );
+ }
+ fprintf( stderr, "done sleeping.\n" );
+ fflush( stderr );
+ previous = time( NULL );
+ }
+}
diff -Naur rsync-3.0.6/util.c rsync-3.0.6-sleepflag/util.c
--- rsync-3.0.6/util.c 2009-03-03 19:57:43.000000000 +0300
+++ rsync-3.0.6-sleepflag/util.c 2010-08-05 22:05:32.000000000 +0400
@@ -572,6 +572,7 @@
if (!(d = opendir(abpos ? glob.arg_buf : ".")))
return;
while ((di = readdir(d)) != NULL) {
+ sleeper_sleep(); // TEAK
char *dname = d_name(di);
if (dname[0] == '.' && (dname[1] == '\0'
|| (dname[1] == '.' && dname[2] == '\0')))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment