summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2018-04-13 05:04:12 +0000
committerDamien Miller <djm@mindrot.org>2018-04-15 07:52:56 +1000
commit3455f1e7c48e2e549192998d330214975b9b1dc7 (patch)
tree01906cbc22cde9cfd014a8a6f05b7b0bf37742f7
parent1c5b4bc827f4abc3e65888cda061ad5edf1b8c7c (diff)
upstream: notify user immediately when underlying ssh process dies;
patch from Thomas Kuthan in bz2719; ok dtucker@ OpenBSD-Commit-ID: 78fac88c2f08054d1fc5162c43c24162b131cf78
-rw-r--r--sftp.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/sftp.c b/sftp.c
index 279f7d46e..da81897e4 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.183 2018/04/10 00:10:49 djm Exp $ */ 1/* $OpenBSD: sftp.c,v 1.184 2018/04/13 05:04:12 djm 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 *
@@ -253,6 +253,23 @@ 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
270 errno = save_errno;
271}
272
256static void 273static void
257help(void) 274help(void)
258{ 275{
@@ -2227,6 +2244,7 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
2227 if (err != 0) 2244 if (err != 0)
2228 break; 2245 break;
2229 } 2246 }
2247 signal(SIGCHLD, SIG_DFL);
2230 free(remote_path); 2248 free(remote_path);
2231 free(startdir); 2249 free(startdir);
2232 free(conn); 2250 free(conn);
@@ -2296,6 +2314,7 @@ connect_to_server(char *path, char **args, int *in, int *out)
2296 signal(SIGTSTP, suspchild); 2314 signal(SIGTSTP, suspchild);
2297 signal(SIGTTIN, suspchild); 2315 signal(SIGTTIN, suspchild);
2298 signal(SIGTTOU, suspchild); 2316 signal(SIGTTOU, suspchild);
2317 signal(SIGCHLD, sigchld_handler);
2299 close(c_in); 2318 close(c_in);
2300 close(c_out); 2319 close(c_out);
2301} 2320}