From 4cf64834ed182e6c10f2213f84d8d33a273b3896 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Wed, 20 Mar 2002 01:09:49 +0000 Subject: [PATCH] Patch from Paul Haas: * Fix situation where failure to fork (e.g. because out of process slots) would cause rsync to kill all processes owned by the current user. Yes, really! (Paul Haas, Martin Pool) Also, add a little more documentation and paranoia to make sure we never call kill(2) with a negative pid. --- NEWS | 6 +++++- util.c | 32 ++++++++++++++++++++++++++------ 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 3a22226c..ef198c40 100644 --- a/NEWS +++ b/NEWS @@ -10,10 +10,14 @@ rsync changes since last release BUG FIXES: + * Fix situation where failure to fork (e.g. because out of process + slots) would cause rsync to kill all processes owned by the + current user. Yes, really! (Paul Haas, Martin Pool) + * Fix test suite on Solaris. (Jos Backus) * Fix minor memory leak in socket code. (Dave Dykstra, Martin Pool.) * Fix --whole-file problem that caused it to be the default even - for remote connections. (Frank Schulz) + for remote connections. (Martin Pool, Frank Schulz) diff --git a/util.c b/util.c index c1e04710..245f3b29 100644 --- a/util.c +++ b/util.c @@ -478,27 +478,47 @@ int robust_rename(char *from, char *to) static pid_t all_pids[10]; static int num_pids; -/* fork and record the pid of the child */ +/** Fork and record the pid of the child. **/ pid_t do_fork(void) { pid_t newpid = fork(); - if (newpid) { + if (newpid != 0 && newpid != -1) { all_pids[num_pids++] = newpid; } return newpid; } -/* kill all children */ +/** + * Kill all children. + * + * @todo It would be kind of nice to make sure that they are actually + * all our children before we kill them, because their pids may have + * been recycled by some other process. Perhaps when we wait for a + * child, we should remove it from this array. Alternatively we could + * perhaps use process groups, but I think that would not work on + * ancient Unix versions that don't support them. + **/ void kill_all(int sig) { int i; - for (i=0;i