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@openssh.com, does not appear to accept mail). Many thanks for your excellent software! edo -- esb@hawaii.edu edo@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
Could you please attach you patch in unified "diff -u" format to the bug, rather than pasting it into the comments field? Bugs in comments fields usually have to be manually reconstructed.
Created attachment 317 [details] diff -u for the bug, as requested by djm
patch applied, thanks. (a similar one for sftp too)
Mass change of RESOLVED bugs to CLOSED