[openssh-commits] [openssh] 03/04: add back use of pipes in scp.c under USE_PIPES

git+noreply at mindrot.org git+noreply at mindrot.org
Wed Jan 11 11:48:45 AEDT 2023


This is an automated email from the git hooks/post-receive script.

djm pushed a commit to branch master
in repository openssh.

commit f5154d2aac3e6a32a1b13dec23a701a087850cdc
Author: Damien Miller <djm at mindrot.org>
Date:   Wed Jan 11 11:44:19 2023 +1100

    add back use of pipes in scp.c under USE_PIPES
    
    This matches sftp.c which prefers socketpair but uses pipes on
    some older platforms.
---
 scp.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/scp.c b/scp.c
index 42cd034b..543d3b1f 100644
--- a/scp.c
+++ b/scp.c
@@ -279,7 +279,11 @@ int
 do_cmd(char *program, char *host, char *remuser, int port, int subsystem,
     char *cmd, int *fdin, int *fdout, pid_t *pid)
 {
+#ifdef USE_PIPES
+	int pin[2], pout[2];
+#else
 	int sv[2];
+#endif
 
 	if (verbose_mode)
 		fmprintf(stderr,
@@ -290,9 +294,14 @@ do_cmd(char *program, char *host, char *remuser, int port, int subsystem,
 	if (port == -1)
 		port = sshport;
 
+#ifdef USE_PIPES
+	if (pipe(pin) == -1 || pipe(pout) == -1)
+		fatal("pipe: %s", strerror(errno));
+#else
 	/* Create a socket pair for communicating with ssh. */
 	if (socketpair(AF_UNIX, SOCK_STREAM, 0, sv) == -1)
 		fatal("socketpair: %s", strerror(errno));
+#endif
 
 	ssh_signal(SIGTSTP, suspchild);
 	ssh_signal(SIGTTIN, suspchild);
@@ -305,13 +314,25 @@ do_cmd(char *program, char *host, char *remuser, int port, int subsystem,
 		fatal("fork: %s", strerror(errno));
 	case 0:
 		/* Child. */
+#ifdef USE_PIPES
+		if (dup2(pin[0], STDIN_FILENO) == -1 ||
+		    dup2(pout[1], STDOUT_FILENO) == -1) {
+			error("dup2: %s", strerror(errno));
+			_exit(1);
+		}
+		close(pin[0]);
+		close(pin[1]);
+		close(pout[0]);
+		close(pout[1]);
+#else
 		if (dup2(sv[0], STDIN_FILENO) == -1 ||
 		    dup2(sv[0], STDOUT_FILENO) == -1) {
-			perror("dup2");
+			error("dup2: %s", strerror(errno));
 			_exit(1);
 		}
 		close(sv[0]);
 		close(sv[1]);
+#endif
 		replacearg(&args, 0, "%s", program);
 		if (port != -1) {
 			addargs(&args, "-p");
@@ -332,9 +353,16 @@ do_cmd(char *program, char *host, char *remuser, int port, int subsystem,
 		_exit(1);
 	default:
 		/* Parent.  Close the other side, and return the local side. */
+#ifdef USE_PIPES
+		close(pin[0]);
+		close(pout[1]);
+		*fdout = pin[1];
+		*fdin = pout[0];
+#else
 		close(sv[0]);
 		*fdin = sv[1];
 		*fdout = sv[1];
+#endif
 		ssh_signal(SIGTERM, killchild);
 		ssh_signal(SIGINT, killchild);
 		ssh_signal(SIGHUP, killchild);

-- 
To stop receiving notification emails like this one, please contact
djm at mindrot.org.


More information about the openssh-commits mailing list