View | Details | Raw Unified | Return to bug 830 | Differences between
and this patch

Collapse All | Expand All

(-)openssh-3.8p1.orig/channels.c (+87 lines)
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
		fatal_remove_cleanup((void (*) (void *)) leave_non_blocking, NULL);
2867
	}
2868
}
2869
2870
/* Puts stdin terminal in non-blocking mode. */
2871
2872
static void
2873
enter_non_blocking(void)
2874
{
2875
	in_non_blocking_mode = 1;
2876
	(void) fcntl(fileno(stdin), F_SETFL, O_NONBLOCK);
2877
	fatal_add_cleanup((void (*) (void *)) leave_non_blocking, NULL); }
2878
2879
/*
2880
 * This is called when the interactive is entered.  This checks if 
2881
there is
2882
 * an EOF coming on stdin.  We must check this explicitly, as select() 
2883
does
2884
 * not appear to wake up when redirecting from /dev/null.
2885
 */
2886
2887
void
2888
channel_check_initial_eof_on_stdin(int id) {
2889
	int len;
2890
	char buf[1];
2891
2892
	Channel *c = channel_lookup(id);
2893
2894
	if (c == NULL) {
2895
		logit("channel_check_initial_eof_on_stdin: %d: bad id", id);
2896
		return;
2897
	}
2898
2899
	if ( c->type != SSH_CHANNEL_OPEN )
2900
		return;
2901
2902
	/*
2903
	 * Try to read a single character; it appears
2904
	 * that for some files, such /dev/null, select() never wakes up for
2905
	 * read for this descriptor, which means that we never get EOF.  This
2906
	 * way we will get the EOF if stdin comes from /dev/null or similar.
2907
	 */
2908
2909
	enter_non_blocking();
2910
2911
	/* Check for immediate EOF on stdin. */
2912
	len = read(c->rfd, buf, 1);
2913
	if (len < 0 && (errno == EINTR || errno == EAGAIN)) {
2914
		leave_non_blocking();
2915
		return;
2916
	}
2917
2918
	leave_non_blocking();
2919
2920
	if (len <= 0) {
2921
		debug2("channel %d: read<=0 rfd %d len %d",
2922
			c->self, c->rfd, len);
2923
		chan_read_failed(c);
2924
	} else {
2925
		/*
2926
	 	* Got data.  We must store the data in the buffer,
2927
	 	* and also process it as an escape character if
2928
	 	* appropriate.
2929
	 	*/
2930
		if (c->input_filter != NULL) {
2931
			if (c->input_filter(c, buf, len) == -1) {
2932
				debug2("channel %d: filter stops", c->self);
2933
				chan_read_failed(c);
2934
			}
2935
		} else {
2936
			buffer_append(&c->input, buf, 1);
2937
		}
2938
	}
2852
}
2939
}
(-)openssh-3.8p1.orig/channels.h (+1 lines)
Lines 165-170 Link Here
165
void	 channel_register_filter(int, channel_filter_fn *);
165
void	 channel_register_filter(int, channel_filter_fn *);
166
void	 channel_cancel_cleanup(int);
166
void	 channel_cancel_cleanup(int);
167
int	 channel_close_fd(int *);
167
int	 channel_close_fd(int *);
168
void	 channel_check_initial_eof_on_stdin(int);
168
169
169
/* protocol handler */
170
/* protocol handler */
170
171
(-)openssh-3.8p1.orig/ssh.c (+2 lines)
Lines 1119-1124 Link Here
1119
		packet_send();
1119
		packet_send();
1120
	}
1120
	}
1121
1121
1122
	channel_check_initial_eof_on_stdin(id);
1123
1122
	packet_set_interactive(interactive);
1124
	packet_set_interactive(interactive);
1123
}
1125
}
1124
1126

Return to bug 830