From 3ba62a830825f5e1e1f70a8ec1f85abeaadc3f1f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 23 Mar 1998 04:44:44 +0000 Subject: [PATCH] - keep a list of pids and send them a SIGUSR1 for cleanup rather than using setpgrp() - adapt the block size for really large files to reduce the checksum size and memory overheads --- main.c | 7 +------ rsync.c | 17 +++++++++++------ util.c | 27 ++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 13 deletions(-) diff --git a/main.c b/main.c index 9b2d9db2..23a465c8 100644 --- a/main.c +++ b/main.c @@ -356,7 +356,7 @@ static int do_recv(int f_in,int f_out,struct file_list *flist,char *local_name) } - if ((pid=fork()) == 0) { + if ((pid=do_fork()) == 0) { recv_files(f_in,flist,local_name,recv_pipe[1]); if (verbose > 2) fprintf(FERROR,"receiver read %d\n",read_total()); @@ -519,11 +519,6 @@ int main(int argc,char *argv[]) struct file_list *flist; char *local_name = NULL; -#ifdef SETPGRP_VOID - setpgrp(); -#else - setpgrp(0,0); -#endif signal(SIGUSR1, sigusr1_handler); starttime = time(NULL); diff --git a/rsync.c b/rsync.c index 059b3845..59d74226 100644 --- a/rsync.c +++ b/rsync.c @@ -277,6 +277,15 @@ static int skip_file(char *fname, } +/* use a larger block size for really big files */ +int adapt_block_size(struct file_struct *file, int bsize) +{ + int ret = file->length / (10000); /* rough heuristic */ + ret = ret & ~15; /* multiple of 16 */ + if (ret < bsize) ret = bsize; + return ret; +} + void recv_generator(char *fname,struct file_list *flist,int i,int f_out) { int fd; @@ -446,7 +455,7 @@ void recv_generator(char *fname,struct file_list *flist,int i,int f_out) if (verbose > 3) fprintf(FERROR,"gen mapped %s of size %d\n",fname,(int)st.st_size); - s = generate_sums(buf,st.st_size,block_size); + s = generate_sums(buf,st.st_size,adapt_block_size(file, block_size)); if (verbose > 2) fprintf(FERROR,"sending sums for %d\n",i); @@ -649,11 +658,7 @@ void exit_cleanup(int code) unlink(cleanup_fname); signal(SIGUSR1, SIG_IGN); if (code) { -#ifdef GETPGRP_VOID - kill(-getpgrp(), SIGUSR1); -#else - kill(-getpgrp(getpid()), SIGUSR1); -#endif + kill_all(SIGUSR1); } exit(code); } diff --git a/util.c b/util.c index 927aa996..6537717d 100644 --- a/util.c +++ b/util.c @@ -119,7 +119,7 @@ int piped_child(char **command,int *f_in,int *f_out) } - pid = fork(); + pid = do_fork(); if (pid < 0) { fprintf(FERROR,"fork: %s\n",strerror(errno)); exit_cleanup(1); @@ -352,3 +352,28 @@ void u_sleep(int usec) tv.tv_usec = usec; select(0, NULL, NULL, NULL, &tv); } + + +static pid_t all_pids[10]; +static int num_pids; + +/* fork and record the pid of the child */ +pid_t do_fork(void) +{ + pid_t newpid = fork(); + + if (newpid) { + all_pids[num_pids++] = newpid; + } + return newpid; +} + +/* kill all children */ +void kill_all(int sig) +{ + int i; + for (i=0;i