- keep a list of pids and send them a SIGUSR1 for cleanup rather than
authorAndrew Tridgell <tridge@samba.org>
Mon, 23 Mar 1998 04:44:44 +0000 (04:44 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 23 Mar 1998 04:44:44 +0000 (04:44 +0000)
using setpgrp()

- adapt the block size for really large files to reduce the checksum
  size and memory overheads

main.c
rsync.c
util.c

diff --git a/main.c b/main.c
index 9b2d9db..23a465c 100644 (file)
--- 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 059b384..59d7422 100644 (file)
--- 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 927aa99..6537717 100644 (file)
--- 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<num_pids;i++) {
+               if (all_pids[i] != getpid())
+                       kill(all_pids[i], sig);
+       }
+}