version 1.202, 2006/03/25 13:17:02 |
version 1.203, 2006/04/20 21:53:44 |
|
|
{ |
{ |
pid_t pid; |
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]; |
int inout[2], err[2]; |
/* Uses socket pairs to communicate with the program. */ |
/* Uses socket pairs to communicate with the program. */ |
if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) < 0 || |
if (socketpair(AF_UNIX, SOCK_STREAM, 0, inout) < 0 || |
socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0) |
socketpair(AF_UNIX, SOCK_STREAM, 0, err) < 0) |
packet_disconnect("Could not create socket pairs: %.100s", |
packet_disconnect("Could not create socket pairs: %.100s", |
strerror(errno)); |
strerror(errno)); |
#endif /* USE_PIPES */ |
|
if (s == NULL) |
if (s == NULL) |
fatal("do_exec_no_pty: no session"); |
fatal("do_exec_no_pty: no session"); |
|
|
|
|
if (setsid() < 0) |
if (setsid() < 0) |
error("setsid failed: %.100s", strerror(errno)); |
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 |
* Redirect stdin, stdout, and stderr. Stdin and stdout will |
* use the same socket, as some programs (particularly rdist) |
* use the same socket, as some programs (particularly rdist) |
* seem to depend on it. |
* seem to depend on it. |
|
|
perror("dup2 stdout"); |
perror("dup2 stdout"); |
if (dup2(err[0], 2) < 0) /* stderr */ |
if (dup2(err[0], 2) < 0) /* stderr */ |
perror("dup2 stderr"); |
perror("dup2 stderr"); |
#endif /* USE_PIPES */ |
|
|
|
/* Do processing for the child (exec command etc). */ |
/* Do processing for the child (exec command etc). */ |
do_child(s, command); |
do_child(s, command); |
|
|
s->pid = pid; |
s->pid = pid; |
/* Set interactive/non-interactive mode. */ |
/* Set interactive/non-interactive mode. */ |
packet_set_interactive(s->display != NULL); |
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. */ |
/* We are the parent. Close the child sides of the socket pairs. */ |
close(inout[0]); |
close(inout[0]); |
close(err[0]); |
close(err[0]); |
|
|
server_loop(pid, inout[1], inout[1], err[1]); |
server_loop(pid, inout[1], inout[1], err[1]); |
/* server_loop has closed inout[1] and err[1]. */ |
/* server_loop has closed inout[1] and err[1]. */ |
} |
} |
#endif /* USE_PIPES */ |
|
} |
} |
|
|
/* |
/* |