|
Lines 134-139
Link Here
|
| 134 |
/* helper */ |
134 |
/* helper */ |
| 135 |
static void port_open_helper(Channel *c, char *rtype); |
135 |
static void port_open_helper(Channel *c, char *rtype); |
| 136 |
|
136 |
|
|
|
137 |
/* non_blocking switch */ |
| 138 |
static int in_non_blocking_mode = 0; |
| 139 |
|
| 137 |
/* -- channel core */ |
140 |
/* -- channel core */ |
| 138 |
|
141 |
|
| 139 |
Channel * |
142 |
Channel * |
|
Lines 2849-2852
Link Here
|
| 2849 |
packet_start(SSH_CMSG_AGENT_REQUEST_FORWARDING); |
2852 |
packet_start(SSH_CMSG_AGENT_REQUEST_FORWARDING); |
| 2850 |
packet_send(); |
2853 |
packet_send(); |
| 2851 |
packet_write_wait(); |
2854 |
packet_write_wait(); |
|
|
2855 |
} |
| 2856 |
|
| 2857 |
|
| 2858 |
/* Restores stdin to blocking mode. */ |
| 2859 |
|
| 2860 |
static void |
| 2861 |
leave_non_blocking(void) |
| 2862 |
{ |
| 2863 |
if (in_non_blocking_mode) { |
| 2864 |
(void) fcntl(fileno(stdin), F_SETFL, 0); |
| 2865 |
in_non_blocking_mode = 0; |
| 2866 |
} |
| 2867 |
} |
| 2868 |
|
| 2869 |
/* Puts stdin terminal in non-blocking mode. */ |
| 2870 |
|
| 2871 |
static void |
| 2872 |
enter_non_blocking(void) |
| 2873 |
{ |
| 2874 |
in_non_blocking_mode = 1; |
| 2875 |
(void) fcntl(fileno(stdin), F_SETFL, O_NONBLOCK); } |
| 2876 |
|
| 2877 |
/* |
| 2878 |
* This is called when the interactive is entered. This checks if |
| 2879 |
there is |
| 2880 |
* an EOF coming on stdin. We must check this explicitly, as select() |
| 2881 |
does |
| 2882 |
* not appear to wake up when redirecting from /dev/null. |
| 2883 |
*/ |
| 2884 |
|
| 2885 |
void |
| 2886 |
channel_check_initial_eof_on_stdin(int id) { |
| 2887 |
int len; |
| 2888 |
char buf[1]; |
| 2889 |
|
| 2890 |
Channel *c = channel_lookup(id); |
| 2891 |
|
| 2892 |
if (c == NULL) { |
| 2893 |
logit("channel_check_initial_eof_on_stdin: %d: bad id", id); |
| 2894 |
return; |
| 2895 |
} |
| 2896 |
|
| 2897 |
if ( c->type != SSH_CHANNEL_OPEN ) |
| 2898 |
return; |
| 2899 |
|
| 2900 |
/* |
| 2901 |
* Try to read a single character; it appears |
| 2902 |
* that for some files, such /dev/null, select() never wakes up for |
| 2903 |
* read for this descriptor, which means that we never get EOF. This |
| 2904 |
* way we will get the EOF if stdin comes from /dev/null or similar. |
| 2905 |
*/ |
| 2906 |
|
| 2907 |
enter_non_blocking(); |
| 2908 |
|
| 2909 |
/* Check for immediate EOF on stdin. */ |
| 2910 |
len = read(c->rfd, buf, 1); |
| 2911 |
if (len < 0 && (errno == EINTR || errno == EAGAIN)) { |
| 2912 |
leave_non_blocking(); |
| 2913 |
return; |
| 2914 |
} |
| 2915 |
|
| 2916 |
leave_non_blocking(); |
| 2917 |
|
| 2918 |
if (len <= 0) { |
| 2919 |
debug2("channel %d: read<=0 rfd %d len %d", |
| 2920 |
c->self, c->rfd, len); |
| 2921 |
chan_read_failed(c); |
| 2922 |
} else { |
| 2923 |
/* |
| 2924 |
* Got data. We must store the data in the buffer, |
| 2925 |
* and also process it as an escape character if |
| 2926 |
* appropriate. |
| 2927 |
*/ |
| 2928 |
if (c->input_filter != NULL) { |
| 2929 |
if (c->input_filter(c, buf, len) == -1) { |
| 2930 |
debug2("channel %d: filter stops", c->self); |
| 2931 |
chan_read_failed(c); |
| 2932 |
} |
| 2933 |
} else { |
| 2934 |
buffer_append(&c->input, buf, 1); |
| 2935 |
} |
| 2936 |
} |
| 2852 |
} |
2937 |
} |