diff options
author | Damien Miller <djm@mindrot.org> | 2023-01-11 01:44:19 +0100 |
---|---|---|
committer | Damien Miller <djm@mindrot.org> | 2023-01-11 01:44:19 +0100 |
commit | f5154d2aac3e6a32a1b13dec23a701a087850cdc (patch) | |
tree | 1b2b8b8a4f8fc29069f4358059ea8f07fa91b52a /scp.c | |
parent | upstream: Switch scp from using pipes to a socketpair for (diff) | |
download | openssh-f5154d2aac3e6a32a1b13dec23a701a087850cdc.tar.xz openssh-f5154d2aac3e6a32a1b13dec23a701a087850cdc.zip |
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.
Diffstat (limited to 'scp.c')
-rw-r--r-- | scp.c | 30 |
1 files changed, 29 insertions, 1 deletions
@@ -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); |