}
- 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());
struct file_list *flist;
char *local_name = NULL;
-#ifdef SETPGRP_VOID
- setpgrp();
-#else
- setpgrp(0,0);
-#endif
signal(SIGUSR1, sigusr1_handler);
starttime = time(NULL);
}
+/* 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;
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);
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);
}
}
- pid = fork();
+ pid = do_fork();
if (pid < 0) {
fprintf(FERROR,"fork: %s\n",strerror(errno));
exit_cleanup(1);
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);
+ }
+}