|
Lines 95-100
Link Here
|
| 95 |
*/ |
95 |
*/ |
| 96 |
extern char *host; |
96 |
extern char *host; |
| 97 |
|
97 |
|
|
|
98 |
extern int fork_after_authentication_flag; |
| 99 |
extern int wait_for_port_open_before_fork; |
| 100 |
|
| 98 |
/* |
101 |
/* |
| 99 |
* Flag to indicate that we have received a window change signal which has |
102 |
* Flag to indicate that we have received a window change signal which has |
| 100 |
* not yet been processed. This will cause a message indicating the new |
103 |
* not yet been processed. This will cause a message indicating the new |
|
Lines 1007-1012
Link Here
|
| 1007 |
|
1010 |
|
| 1008 |
/*********/ |
1011 |
/*********/ |
| 1009 |
|
1012 |
|
|
|
1013 |
/* |
| 1014 |
* Detach the program (continue to serve connections, |
| 1015 |
* but put in background and no more new connections). |
| 1016 |
*/ |
| 1017 |
static |
| 1018 |
void |
| 1019 |
forkoff(int stop_listening, int detach) |
| 1020 |
{ |
| 1021 |
pid_t pid; |
| 1022 |
int fd; |
| 1023 |
Channel *c; |
| 1024 |
|
| 1025 |
/* Restore tty modes. */ |
| 1026 |
leave_raw_mode(); |
| 1027 |
|
| 1028 |
/* Stop listening for new connections. */ |
| 1029 |
if (stop_listening) |
| 1030 |
channel_stop_listening(); |
| 1031 |
|
| 1032 |
fprintf(stderr, "Forking off into the background - %s", |
| 1033 |
stop_listening ? "no longer listening" : "still listening"); |
| 1034 |
|
| 1035 |
/* Fork into background. */ |
| 1036 |
pid = fork(); |
| 1037 |
if (pid < 0) { |
| 1038 |
error("fork: %.100s", strerror(errno)); |
| 1039 |
return; |
| 1040 |
} |
| 1041 |
if (pid != 0) { /* This is the parent. */ |
| 1042 |
/* The parent just exits. */ |
| 1043 |
exit(0); |
| 1044 |
} |
| 1045 |
|
| 1046 |
c = channel_lookup(session_ident); |
| 1047 |
if (c == NULL) |
| 1048 |
error("couldn't lookup session channel"); |
| 1049 |
|
| 1050 |
/* The child continues serving connections. */ |
| 1051 |
/* fake EOF on stdin */ |
| 1052 |
if (compat20) { |
| 1053 |
buffer_append(&stdin_buffer, "\004", 1); |
| 1054 |
} else if (!stdin_eof) { |
| 1055 |
/* |
| 1056 |
* Sending SSH_CMSG_EOF alone does not always appear |
| 1057 |
* to be enough. So we try to send an EOF character |
| 1058 |
* first. |
| 1059 |
*/ |
| 1060 |
packet_start(SSH_CMSG_STDIN_DATA); |
| 1061 |
packet_put_string("\004", 1); |
| 1062 |
packet_send(); |
| 1063 |
/* Close stdin. */ |
| 1064 |
stdin_eof = 1; |
| 1065 |
if (buffer_len(&stdin_buffer) == 0) { |
| 1066 |
packet_start(SSH_CMSG_EOF); |
| 1067 |
packet_send(); |
| 1068 |
} |
| 1069 |
} |
| 1070 |
|
| 1071 |
if (detach) { |
| 1072 |
chan_read_failed(c); |
| 1073 |
chan_write_failed(c); |
| 1074 |
channel_close_fds(c); |
| 1075 |
fd = open(_PATH_DEVNULL, O_RDWR, 0); |
| 1076 |
if (fd < 0) |
| 1077 |
return; |
| 1078 |
(void) dup2(fd, STDIN_FILENO); |
| 1079 |
(void) dup2(fd, STDOUT_FILENO); |
| 1080 |
(void) dup2(fd, STDERR_FILENO); |
| 1081 |
if (fd > 2) |
| 1082 |
(void) close(fd); |
| 1083 |
(void) setsid(); |
| 1084 |
} |
| 1085 |
} |
| 1086 |
|
| 1010 |
static void |
1087 |
static void |
| 1011 |
client_input_stdout_data(int type, int plen, void *ctxt) |
1088 |
client_input_stdout_data(int type, int plen, void *ctxt) |
| 1012 |
{ |
1089 |
{ |
|
Lines 1187-1192
Link Here
|
| 1187 |
packet_put_int(c->local_maxpacket); |
1264 |
packet_put_int(c->local_maxpacket); |
| 1188 |
packet_send(); |
1265 |
packet_send(); |
| 1189 |
} |
1266 |
} |
|
|
1267 |
if (fork_after_authentication_flag && wait_for_port_open_before_fork) |
| 1268 |
forkoff(0, 1); |
| 1190 |
} else { |
1269 |
} else { |
| 1191 |
debug("failure %s", ctype); |
1270 |
debug("failure %s", ctype); |
| 1192 |
packet_start(SSH2_MSG_CHANNEL_OPEN_FAILURE); |
1271 |
packet_start(SSH2_MSG_CHANNEL_OPEN_FAILURE); |