From 0a6c7c773eeb1e0d34669284be5a84787d1a81be Mon Sep 17 00:00:00 2001 From: Damien Miller Date: Thu, 20 Apr 2006 21:53:45 +0000 Subject: Switch from using pipes to socketpairs for communication between sftp/scp and ssh, and between sshd and its subprocesses. This saves a file descriptor per session and apparently makes userland ppp over ssh work; ok markus@ deraadt@ --- usr.bin/ssh/includes.h | 8 +------- usr.bin/ssh/session.c | 51 +------------------------------------------------- usr.bin/ssh/sftp.c | 13 +------------ 3 files changed, 3 insertions(+), 69 deletions(-) (limited to 'usr.bin/ssh') diff --git a/usr.bin/ssh/includes.h b/usr.bin/ssh/includes.h index 5a1a0de1b5c..7b0fcb5d0a7 100644 --- a/usr.bin/ssh/includes.h +++ b/usr.bin/ssh/includes.h @@ -1,4 +1,4 @@ -/* $OpenBSD: includes.h,v 1.39 2006/03/25 22:22:43 djm Exp $ */ +/* $OpenBSD: includes.h,v 1.40 2006/04/20 21:53:44 djm Exp $ */ /* * Author: Tatu Ylonen @@ -39,10 +39,4 @@ #include "version.h" -/* - * Define this to use pipes instead of socketpairs for communicating with the - * client program. Socketpairs do not seem to work on all systems. - */ -#define USE_PIPES 1 - #endif /* INCLUDES_H */ diff --git a/usr.bin/ssh/session.c b/usr.bin/ssh/session.c index 763542662c0..faf70dd4b0c 100644 --- a/usr.bin/ssh/session.c +++ b/usr.bin/ssh/session.c @@ -1,4 +1,4 @@ -/* $OpenBSD: session.c,v 1.202 2006/03/25 13:17:02 djm Exp $ */ +/* $OpenBSD: session.c,v 1.203 2006/04/20 21:53:44 djm Exp $ */ /* * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland * All rights reserved @@ -379,20 +379,12 @@ do_exec_no_pty(Session *s, const char *command) { pid_t pid; -#ifdef USE_PIPES - int pin[2], pout[2], perr[2]; - /* Allocate pipes for communicating with the program. */ - if (pipe(pin) < 0 || pipe(pout) < 0 || pipe(perr) < 0) - packet_disconnect("Could not create pipes: %.100s", - strerror(errno)); -#else /* USE_PIPES */ int inout[2], err[2]; /* Uses socket pairs to communicate with the program. */ if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) < 0 || socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0) packet_disconnect("Could not create socket pairs: %.100s", strerror(errno)); -#endif /* USE_PIPES */ if (s == NULL) fatal("do_exec_no_pty: no session"); @@ -412,28 +404,6 @@ do_exec_no_pty(Session *s, const char *command) if (setsid() < 0) error("setsid failed: %.100s", strerror(errno)); -#ifdef USE_PIPES - /* - * Redirect stdin. We close the parent side of the socket - * pair, and make the child side the standard input. - */ - close(pin[1]); - if (dup2(pin[0], 0) < 0) - perror("dup2 stdin"); - close(pin[0]); - - /* Redirect stdout. */ - close(pout[0]); - if (dup2(pout[1], 1) < 0) - perror("dup2 stdout"); - close(pout[1]); - - /* Redirect stderr. */ - close(perr[0]); - if (dup2(perr[1], 2) < 0) - perror("dup2 stderr"); - close(perr[1]); -#else /* USE_PIPES */ /* * Redirect stdin, stdout, and stderr. Stdin and stdout will * use the same socket, as some programs (particularly rdist) @@ -447,7 +417,6 @@ do_exec_no_pty(Session *s, const char *command) perror("dup2 stdout"); if (dup2(err[0], 2) < 0) /* stderr */ perror("dup2 stderr"); -#endif /* USE_PIPES */ /* Do processing for the child (exec command etc). */ do_child(s, command); @@ -458,24 +427,7 @@ do_exec_no_pty(Session *s, const char *command) s->pid = pid; /* Set interactive/non-interactive mode. */ packet_set_interactive(s->display != NULL); -#ifdef USE_PIPES - /* We are the parent. Close the child sides of the pipes. */ - close(pin[0]); - close(pout[1]); - close(perr[1]); - if (compat20) { - if (s->is_subsystem) { - close(perr[0]); - perr[0] = -1; - } - session_set_fds(s, pin[1], pout[0], perr[0]); - } else { - /* Enter the interactive session. */ - server_loop(pid, pin[1], pout[0], perr[0]); - /* server_loop has closed pin[1], pout[0], and perr[0]. */ - } -#else /* USE_PIPES */ /* We are the parent. Close the child sides of the socket pairs. */ close(inout[0]); close(err[0]); @@ -490,7 +442,6 @@ do_exec_no_pty(Session *s, const char *command) server_loop(pid, inout[1], inout[1], err[1]); /* server_loop has closed inout[1] and err[1]. */ } -#endif /* USE_PIPES */ } /* diff --git a/usr.bin/ssh/sftp.c b/usr.bin/ssh/sftp.c index 91592b20598..392a2de1fd4 100644 --- a/usr.bin/ssh/sftp.c +++ b/usr.bin/ssh/sftp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sftp.c,v 1.80 2006/03/27 23:15:46 djm Exp $ */ +/* $OpenBSD: sftp.c,v 1.81 2006/04/20 21:53:44 djm Exp $ */ /* * Copyright (c) 2001-2004 Damien Miller * @@ -1361,23 +1361,12 @@ connect_to_server(char *path, char **args, int *in, int *out) { int c_in, c_out; -#ifdef USE_PIPES - int pin[2], pout[2]; - - if ((pipe(pin) == -1) || (pipe(pout) == -1)) - fatal("pipe: %s", strerror(errno)); - *in = pin[0]; - *out = pout[1]; - c_in = pout[0]; - c_out = pin[1]; -#else /* USE_PIPES */ int inout[2]; if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) == -1) fatal("socketpair: %s", strerror(errno)); *in = *out = inout[0]; c_in = c_out = inout[1]; -#endif /* USE_PIPES */ if ((sshpid = fork()) == -1) fatal("fork: %s", strerror(errno)); -- cgit v1.2.3