]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
add back use of pipes in scp.c under USE_PIPES
authorDamien Miller <djm@mindrot.org>
Wed, 11 Jan 2023 00:44:19 +0000 (11:44 +1100)
committerDamien Miller <djm@mindrot.org>
Wed, 11 Jan 2023 00:44:19 +0000 (11:44 +1100)
This matches sftp.c which prefers socketpair but uses pipes on
some older platforms.

scp.c

diff --git a/scp.c b/scp.c
index 42cd034be11ca45bc67e6d59e88314edaa800b88..543d3b1f3060a8303265d86a05cba2309817bca2 100644 (file)
--- 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);