From owner-ssh@clinet.fi  Thu Dec 10 00:08:12 1998
Received: from lohi.clinet.fi (majordom@lohi.clinet.fi [194.100.0.7]) by hutcs.cs.hut.fi (8.8.8/8.8.8) with ESMTP id AAA02680; Thu, 10 Dec 1998 00:08:12 +0200 (EET)
Received: (from majordom@localhost)
	by lohi.clinet.fi (8.9.1/8.9.0) id XAA26907
	for ssh-outgoing; Wed, 9 Dec 1998 23:57:49 +0200 (EET)
X-Authentication-Warning: lohi.clinet.fi: majordom set sender to owner-ssh@clinet.fi using -f
Received: from mail-relay2.yahoo.com (mr1.yahoo.com [206.251.17.77])
	by lohi.clinet.fi (8.9.1/8.9.0) with ESMTP id XAA26894
	for <ssh@clinet.fi>; Wed, 9 Dec 1998 23:57:41 +0200 (EET)
Received: from borogove.yahoo.com (borogove.yahoo.com [205.216.162.65])
	by mail-relay2.yahoo.com (8.9.1a/8.8.8) with ESMTP id NAA06976
	for <ssh@clinet.fi>; Wed, 9 Dec 1998 13:57:29 -0800 (PST)
Received: from hootie.yahoo.com (hootie.yahoo.com [205.216.162.161])
	by borogove.yahoo.com (8.8.7/8.8.8) with ESMTP id NAA02716
	for <ssh@clinet.fi>; Wed, 9 Dec 1998 13:57:28 -0800 (PST)
Received: (from chiem@localhost) by hootie.yahoo.com (8.8.8/8.6.12) id NAA09063 for ssh@clinet.fi; Wed, 9 Dec 1998 13:57:28 -0800 (PST)
From: Keith Chiem <chiem@yahoo-inc.com>
Message-Id: <199812092157.NAA09063@hootie.yahoo.com>
Subject: scp (version 1) leaves zombie processes (patch included)
To: ssh@clinet.fi
Date: Wed, 9 Dec 1998 13:57:22 -0800 (PST)
X-Mailer: ELM [version 2.4ME+ PL47 (25)]
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary=ELM913240642-8988-0_
Content-Transfer-Encoding: 7bit
Sender: owner-ssh@clinet.fi
Precedence: bulk


--ELM913240642-8988-0_
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit


scp from version 1 distribution (1.2.26) does an exec call to run scp on the
remote system for every transfer of a remote source file, but does not 'wait'
for the child process.  Since scp allows multiple source files, a long 
transfer could leave a lot of zombie processes hanging around until the scp 
process finishes.

Here's a patch against scp.c in v1.2.26 which has been working for us.  I've
submitted this in to the people at ssh.fi.

--k


--ELM913240642-8988-0_
Content-Type: text/plain; charset=ISO-8859-1
Content-Disposition: attachment; filename=scp.patch
Content-Description: 'patch -p0 < scp.patch' in dir containing ssh-1.2.26 dir
Content-Transfer-Encoding: 7bit

diff -u ssh-1.2.26.old/scp.c ssh-1.2.26/scp.c
--- ssh-1.2.26.old/scp.c	Wed Jul  8 09:40:38 1998
+++ ssh-1.2.26/scp.c	Wed Dec  9 12:22:22 1998
@@ -225,12 +225,13 @@
 int ssh_options_alloc = 0;
 
 /* This function executes the given command as the specified user on the given
-   host.  This returns < 0 if execution fails, and >= 0 otherwise.
+   host.  This returns < 0 if execution fails, and childpid (> 0) otherwise.
    This assigns the input and output file descriptors on success. */
 
-int do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
+pid_t do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
 {
   int pin[2], pout[2], reserved[2];
+  pid_t childpid;
 
   if (verbose)
     fprintf(stderr, "Executing: host %s, user %s, command %s\n",
@@ -251,7 +252,8 @@
   close(reserved[1]);
 
   /* For a child to execute the command on the remote host using ssh. */
-  if (fork() == 0) 
+  childpid = fork();
+  if (childpid == 0) 
     {
       char *args[256];
       unsigned int i, j;
@@ -323,7 +325,7 @@
   *fdout = pin[1];
   close(pout[1]);
   *fdin = pout[0];
-  return 0;
+  return childpid;
 }
 
 void fatal(const char *fmt, ...)
@@ -569,6 +571,7 @@
 	int argc;
 {
 	int i, len;
+	pid_t childpid;
 	char *bp, *host, *src, *suser, *thost, *tuser;
 
 	*targ++ = 0;
@@ -646,14 +649,15 @@
 			        bp = xmalloc(len);
 				(void)sprintf(bp, "%s -t %s", cmd, targ);
 				host = thost;
-				if (do_cmd(host,  tuser,
-					   bp, &remin, &remout) < 0)
+				if ((childpid = do_cmd(host,  tuser,
+					   bp, &remin, &remout)) < 0)
 				  exit(1);
 				if (response() < 0)
 					exit(1);
 				(void)xfree(bp);
 			}
 			source(1, argv+i);
+			waitpid(childpid, NULL, WNOHANG);
 		}
 	}
 }
@@ -664,6 +668,7 @@
 	char *argv[];
 {
 	int i, len;
+	pid_t childpid;
 	char *bp, *host, *src, *suser;
 
 	for (i = 0; i < argc - 1; i++) {
@@ -698,7 +703,7 @@
 		len = strlen(src) + CMDNEEDS + 20;
 	        bp = xmalloc(len);
 		(void)sprintf(bp, "%s -f %s", cmd, src);
-	  	if (do_cmd(host, suser, bp, &remin, &remout) < 0) {
+	  	if ((childpid = do_cmd(host, suser, bp, &remin, &remout)) < 0) {
 		  (void)xfree(bp);
 		  ++errs;
 		  continue;
@@ -707,6 +712,7 @@
 		sink(1, argv + argc - 1);
 		(void)close(remin);
 		remin = remout = -1;
+		waitpid(childpid, NULL, WNOHANG);
 	}
 }
 

--ELM913240642-8988-0_--
