From 299dd7877a935464a1550170d6b310c6a10b9ddc Mon Sep 17 00:00:00 2001 From: je Date: Sun, 27 Feb 2011 12:06:26 +0100 Subject: [PATCH] Prevent wrapper.c from flooding the IRC server. --- config.mk | 19 ++++++++++++------- wrapper.c | 8 +++++--- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/config.mk b/config.mk index 0983427..e7b5cf1 100644 --- a/config.mk +++ b/config.mk @@ -17,10 +17,12 @@ DESTDIR ?= INCDIR ?= ${PREFIX}/include LIBDIR ?= ${PREFIX}/lib VERSION ?= 1.6 -# The ii(1) executable that the wrapper(1) program will use: -EXECUTABLE ?= ii -# Amount of seconds that it (generally) takes for ii(1) to connect: -SSLEEP ?= 300 +# The ii executable that the wrapper program will use: +II_EXEC ?= ii +# Amount of seconds that it (generally) takes for ii to connect: +CHLD_SLEEP ?= 300 +# Amount of seconds before wrapper initiates an ii instance: +LOOP_SLEEP ?= 60 # Includes and libs: INCLUDES += -I. -I${INCDIR} -I/usr/include @@ -29,15 +31,18 @@ LIBS += -L${LIBDIR} -L/usr/lib -lc -lssl -lcrypto # Compiler flags: CC ?= cc CFLAGS += -g -O0 -W -Wall ${INCLUDES} -DVERSION=\"${VERSION}\" \ - -DEXECUTABLE=\"${EXECUTABLE}\" -DSSLEEP=${SSLEEP} -DHAVE_SSL + -DII_EXEC=\"${II_EXEC}\" -DCHLD_SLEEP=${CHLD_SLEEP} \ + -DLOOP_SLEEP=${LOOP_SLEEP} -DHAVE_SSL LDFLAGS += ${LIBS} # Uncomment for compiling on Solaris: #LIBS = -L${LIBDIR} -L/usr/lib -lc -lsocket -lnsl -lssl -lcrypto #CFLAGS = -g ${INCLUDES} -DVERSION=\"${VERSION}\" \ -# -DEXECUTABLE=\"${EXECUTABLE}\" -DSSLEEP=${SSLEEP} -DHAVE_SSL + -DII_EXEC=\"${II_EXEC}\" -DCHLD_SLEEP=${CHLD_SLEEP} \ + -DLOOP_SLEEP=${LOOP_SLEEP} -DHAVE_SSL # Uncomment to disable SSL support in ii: #LIBS = -L${LIBDIR} -L/usr/lib -lc #CFLAGS = -g -O0 -W -Wall ${INCLUDES} -DVERSION=\"${VERSION}\" \ -# -DEXECUTABLE=\"${EXECUTABLE}\" -DSSLEEP=${SSLEEP} + -DII_EXEC=\"${II_EXEC}\" -DCHLD_SLEEP=${CHLD_SLEEP} \ + -DLOOP_SLEEP=${LOOP_SLEEP} diff --git a/wrapper.c b/wrapper.c index 7362a29..cba27c0 100644 --- a/wrapper.c +++ b/wrapper.c @@ -106,15 +106,17 @@ main(int argc, char **argv) waitpid(0, NULL, 0); } + sleep(LOOP_SLEEP); + /* http://eternallyconfuzzled.com/arts/jsw_art_rand.aspx */ n = o + 1 + random() * 1.0 / ( RAND_MAX + 1.0 ) * (uargc - o - 1); if ((n - o) & 1) n--; s = strlen(args[0]) + strlen(argv[n]) + strlen(argv[n + 1]) + 10 - + sizeof(EXECUTABLE); + + sizeof(II_EXEC); if ((init = calloc(s, 1)) == NULL) _exit(1); - strlcpy(init, EXECUTABLE" ", s); + strlcpy(init, II_EXEC" ", s); strlcat(init, args[0], s); strlcat(init, " -s ", s); strlcat(init, argv[n], s); @@ -131,7 +133,7 @@ main(int argc, char **argv) continue; } - sleep(SSLEEP); + sleep(CHLD_SLEEP); system(args[1]); _exit(0); } else { -- 2.11.4.GIT