summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c29
1 files changed, 25 insertions, 4 deletions
diff --git a/sftp.c b/sftp.c
index 5ce864eeb..d068f7e0f 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.182 2017/11/03 03:46:52 djm Exp $ */ 1/* $OpenBSD: sftp.c,v 1.185 2018/04/26 14:47:03 bluhm Exp $ */
2/* 2/*
3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org> 3 * Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
4 * 4 *
@@ -81,7 +81,7 @@ FILE* infile;
81int batchmode = 0; 81int batchmode = 0;
82 82
83/* PID of ssh transport process */ 83/* PID of ssh transport process */
84static pid_t sshpid = -1; 84static volatile pid_t sshpid = -1;
85 85
86/* Suppress diagnositic messages */ 86/* Suppress diagnositic messages */
87int quiet = 0; 87int quiet = 0;
@@ -253,6 +253,25 @@ cmd_interrupt(int signo)
253 errno = olderrno; 253 errno = olderrno;
254} 254}
255 255
256/*ARGSUSED*/
257static void
258sigchld_handler(int sig)
259{
260 int save_errno = errno;
261 pid_t pid;
262 const char msg[] = "\rConnection closed. \n";
263
264 /* Report if ssh transport process dies. */
265 while ((pid = waitpid(sshpid, NULL, WNOHANG)) == -1 && errno == EINTR)
266 continue;
267 if (pid == sshpid) {
268 (void)write(STDERR_FILENO, msg, sizeof(msg) - 1);
269 sshpid = -1;
270 }
271
272 errno = save_errno;
273}
274
256static void 275static void
257help(void) 276help(void)
258{ 277{
@@ -1844,7 +1863,7 @@ complete_cmd_parse(EditLine *el, char *cmd, int lastarg, char quote,
1844 return 0; 1863 return 0;
1845 } 1864 }
1846 1865
1847 /* Complete ambigious command */ 1866 /* Complete ambiguous command */
1848 tmp = complete_ambiguous(cmd, list, count); 1867 tmp = complete_ambiguous(cmd, list, count);
1849 if (count > 1) 1868 if (count > 1)
1850 complete_display(list, 0); 1869 complete_display(list, 0);
@@ -2227,6 +2246,7 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
2227 if (err != 0) 2246 if (err != 0)
2228 break; 2247 break;
2229 } 2248 }
2249 signal(SIGCHLD, SIG_DFL);
2230 free(remote_path); 2250 free(remote_path);
2231 free(startdir); 2251 free(startdir);
2232 free(conn); 2252 free(conn);
@@ -2296,6 +2316,7 @@ connect_to_server(char *path, char **args, int *in, int *out)
2296 signal(SIGTSTP, suspchild); 2316 signal(SIGTSTP, suspchild);
2297 signal(SIGTTIN, suspchild); 2317 signal(SIGTTIN, suspchild);
2298 signal(SIGTTOU, suspchild); 2318 signal(SIGTTOU, suspchild);
2319 signal(SIGCHLD, sigchld_handler);
2299 close(c_in); 2320 close(c_in);
2300 close(c_out); 2321 close(c_out);
2301} 2322}
@@ -2535,7 +2556,7 @@ main(int argc, char **argv)
2535 if (batchmode) 2556 if (batchmode)
2536 fclose(infile); 2557 fclose(infile);
2537 2558
2538 while (waitpid(sshpid, NULL, 0) == -1) 2559 while (waitpid(sshpid, NULL, 0) == -1 && sshpid > 1)
2539 if (errno != EINTR) 2560 if (errno != EINTR)
2540 fatal("Couldn't wait for ssh process: %s", 2561 fatal("Couldn't wait for ssh process: %s",
2541 strerror(errno)); 2562 strerror(errno));