[Bug 241] New: When I kill scp, the underlying ssh child process remains alive
bugzilla-daemon at mindrot.org
bugzilla-daemon at mindrot.org
Tue May 14 11:26:58 EST 2002
http://bugzilla.mindrot.org/show_bug.cgi?id=241
Summary: When I kill scp, the underlying ssh child process
remains alive
Product: Portable OpenSSH
Version: 3.1p1
Platform: All
OS/Version: Linux
Status: NEW
Severity: minor
Priority: P3
Component: scp
AssignedTo: openssh-unix-dev at mindrot.org
ReportedBy: esb at hawaii.edu
I am trying to use scp in an automated script, and would like to be
able to kill it (automatically) if there is a timeout. However, when
I kill the scp process, the ssh process that scp created continues to
run. This causes problems with my automated system -- the ssh
processes take a long time to time out or complete, and sometimes
complete inappropriately.
Fix: I enclose some diffs that work on linux. I have only caught
SIGTERM -- a more complete implementation might catch other signals as
well (maybe at least SIGINT).
The /*esb*/ comments are for my reference only and may be removed -- I
do not need to be credited. The version openssh-3.1p1x is the one
with my changes. An acknowledgement that this message has reached the
correct individual(s) would be appreciated (your listed address,
openssh at openssh.com, does not appear to accept mail).
Many thanks for your excellent software!
edo -- esb at hawaii.edu
edo at maru 36-> diff -c openssh-3.1p1*/scp.c
*** openssh-3.1p1/scp.c Tue Mar 5 08:59:45 2002
--- openssh-3.1p1x/scp.c Sat May 4 15:42:50 2002
***************
*** 133,138 ****
--- 133,142 ----
/* This is the program to execute for the secured connection. ("ssh"
or -S) */
char *ssh_program = _PATH_SSH_PROGRAM;
+ /* esb: added the child PID so we can kill it if we get killed */
+ pid_t childpid;
+ static void killchild(int signo);
+
/*
* This function executes the given command as the specified user on the
* given host. This returns < 0 if execution fails, and >= 0 otherwise. This
***************
*** 167,173 ****
close(reserved[1]);
/* For a child to execute the command on the remote host using ssh. */
! if (fork() == 0) {
/* Child. */
close(pin[1]);
close(pout[0]);
--- 171,178 ----
close(reserved[1]);
/* For a child to execute the command on the remote host using ssh. */
! /* esb */
! if ((childpid = fork()) == 0) {
/* Child. */
close(pin[1]);
close(pout[0]);
***************
*** 191,196 ****
--- 196,203 ----
*fdout = pin[1];
close(pout[1]);
*fdin = pout[0];
+ /* esb */
+ (void) signal(SIGTERM, killchild);
return 0;
}
***************
*** 1086,1091 ****
--- 1093,1105 ----
signal(SIGALRM, updateprogressmeter);
alarm(PROGRESSTIME);
errno = save_errno;
+ }
+
+ static void
+ killchild(int signo)
+ {
+ kill (childpid, signo);
+ _exit(1);
}
static int
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
More information about the openssh-unix-dev
mailing list