--- rsync-2.6.4/clientserver.c.orig 2005-03-31 04:21:15 +0400 +++ rsync-2.6.4/clientserver.c 2005-03-31 18:27:43 +0400 @@ -26,6 +26,7 @@ **/ #include "rsync.h" +#include extern int verbose; extern int list_only; @@ -217,6 +218,21 @@ int start_inband_exchange(char *user, ch } +int set_rlimit_nproc (int f_out) +{ + struct rlimit rlim; + + rlim.rlim_cur = rlim.rlim_max = 1; + if (setrlimit (RLIMIT_NPROC, &rlim)) + { + rsyserr (FERROR, errno, "setrlimit(%d) failed", RLIMIT_NPROC); + if (f_out >= 0) + io_printf (f_out, "@ERROR: setrlimit failed\n"); + return -1; + } + return 0; +} + static int rsync_module(int f_in, int f_out, int i) { @@ -407,7 +423,7 @@ static int rsync_module(int f_in, int f_ } #ifdef HAVE_SETGROUPS /* Get rid of any supplementary groups this process - * might have inheristed. */ + * might have inherited. */ if (setgroups(1, &gid)) { rsyserr(FLOG, errno, "setgroups failed"); io_printf(f_out, "@ERROR: setgroups failed\n"); @@ -421,6 +437,11 @@ static int rsync_module(int f_in, int f_ return -1; } + if (am_sender || lp_read_only(module_id)) { + if (set_rlimit_nproc(f_out)) + return -1; + } + am_root = (MY_UID() == 0); } --- rsync-2.6.4/main.c.orig 2005-03-30 20:55:11 +0400 +++ rsync-2.6.4/main.c 2005-03-31 18:30:39 +0400 @@ -554,6 +554,7 @@ static int do_recv(int f_in,int f_out,st close(error_pipe[0]); if (f_in != f_out) close(f_out); + f_out = -1; /* we can't let two processes write to the socket at one time */ close_multiplexing_out(); @@ -561,6 +562,8 @@ static int do_recv(int f_in,int f_out,st /* set place to send errors */ set_msg_fd_out(error_pipe[1]); + (void) set_rlimit_nproc(f_out); + recv_files(f_in, flist, local_name); io_flush(FULL_FLUSH); handle_stats(f_in); --- rsync-2.6.4/proto.h.orig 2005-03-31 04:19:27 +0400 +++ rsync-2.6.4/proto.h 2005-03-31 18:27:43 +0400 @@ -296,3 +296,4 @@ void *_realloc_array(void *ptr, unsigned const char *find_filename_suffix(const char *fn, int fn_len, int *len_ptr); uint32 fuzzy_distance(const char *s1, int len1, const char *s2, int len2); int sys_gettimeofday(struct timeval *tv); +int set_rlimit_nproc(int f_out);