aboutsummaryrefslogtreecommitdiff
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 5ce864eeb0fe..d068f7e0feed 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sftp.c,v 1.182 2017/11/03 03:46:52 djm Exp $ */
+/* $OpenBSD: sftp.c,v 1.185 2018/04/26 14:47:03 bluhm Exp $ */
/*
* Copyright (c) 2001-2004 Damien Miller <djm@openbsd.org>
*
@@ -81,7 +81,7 @@ FILE* infile;
int batchmode = 0;
/* PID of ssh transport process */
-static pid_t sshpid = -1;
+static volatile pid_t sshpid = -1;
/* Suppress diagnositic messages */
int quiet = 0;
@@ -253,6 +253,25 @@ cmd_interrupt(int signo)
errno = olderrno;
}
+/*ARGSUSED*/
+static void
+sigchld_handler(int sig)
+{
+ int save_errno = errno;
+ pid_t pid;
+ const char msg[] = "\rConnection closed. \n";
+
+ /* Report if ssh transport process dies. */
+ while ((pid = waitpid(sshpid, NULL, WNOHANG)) == -1 && errno == EINTR)
+ continue;
+ if (pid == sshpid) {
+ (void)write(STDERR_FILENO, msg, sizeof(msg) - 1);
+ sshpid = -1;
+ }
+
+ errno = save_errno;
+}
+
static void
help(void)
{
@@ -1844,7 +1863,7 @@ complete_cmd_parse(EditLine *el, char *cmd, int lastarg, char quote,
return 0;
}
- /* Complete ambigious command */
+ /* Complete ambiguous command */
tmp = complete_ambiguous(cmd, list, count);
if (count > 1)
complete_display(list, 0);
@@ -2227,6 +2246,7 @@ interactive_loop(struct sftp_conn *conn, char *file1, char *file2)
if (err != 0)
break;
}
+ signal(SIGCHLD, SIG_DFL);
free(remote_path);
free(startdir);
free(conn);
@@ -2296,6 +2316,7 @@ connect_to_server(char *path, char **args, int *in, int *out)
signal(SIGTSTP, suspchild);
signal(SIGTTIN, suspchild);
signal(SIGTTOU, suspchild);
+ signal(SIGCHLD, sigchld_handler);
close(c_in);
close(c_out);
}
@@ -2535,7 +2556,7 @@ main(int argc, char **argv)
if (batchmode)
fclose(infile);
- while (waitpid(sshpid, NULL, 0) == -1)
+ while (waitpid(sshpid, NULL, 0) == -1 && sshpid > 1)
if (errno != EINTR)
fatal("Couldn't wait for ssh process: %s",
strerror(errno));