summaryrefslogtreecommitdiff
path: root/sftp.c
diff options
context:
space:
mode:
authorbluhm@openbsd.org <bluhm@openbsd.org>2018-04-26 14:47:03 +0000
committerDamien Miller <djm@mindrot.org>2018-05-11 13:10:49 +1000
commite7751aa4094d51a9bc00778aa8d07e22934c55ee (patch)
treee16bc42496fed77e01e0ae6463e7f67ab70beedf /sftp.c
parent7c15301841e2e9d37cae732400de63ae9c0961d6 (diff)
upstream: Since the previous commit, ssh regress test sftp-chroot was
failing. The sftp program terminated with the wrong exit code as sftp called fatal() instad of exit(0). So when the sigchld handler waits for the child, remember that it was found. Then don't expect that main() can wait again. OK dtucker@ OpenBSD-Commit-ID: bfafd940c0de5297940c71ddf362053db0232266
Diffstat (limited to 'sftp.c')
-rw-r--r--sftp.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/sftp.c b/sftp.c
index da81897e4..d068f7e0f 100644
--- a/sftp.c
+++ b/sftp.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: sftp.c,v 1.184 2018/04/13 05:04:12 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;
@@ -264,8 +264,10 @@ sigchld_handler(int sig)
264 /* Report if ssh transport process dies. */ 264 /* Report if ssh transport process dies. */
265 while ((pid = waitpid(sshpid, NULL, WNOHANG)) == -1 && errno == EINTR) 265 while ((pid = waitpid(sshpid, NULL, WNOHANG)) == -1 && errno == EINTR)
266 continue; 266 continue;
267 if (pid == sshpid) 267 if (pid == sshpid) {
268 (void)write(STDERR_FILENO, msg, sizeof(msg) - 1); 268 (void)write(STDERR_FILENO, msg, sizeof(msg) - 1);
269 sshpid = -1;
270 }
269 271
270 errno = save_errno; 272 errno = save_errno;
271} 273}
@@ -2554,7 +2556,7 @@ main(int argc, char **argv)
2554 if (batchmode) 2556 if (batchmode)
2555 fclose(infile); 2557 fclose(infile);
2556 2558
2557 while (waitpid(sshpid, NULL, 0) == -1) 2559 while (waitpid(sshpid, NULL, 0) == -1 && sshpid > 1)
2558 if (errno != EINTR) 2560 if (errno != EINTR)
2559 fatal("Couldn't wait for ssh process: %s", 2561 fatal("Couldn't wait for ssh process: %s",
2560 strerror(errno)); 2562 strerror(errno));