comparison common-session.c @ 419:b2f81110c80b channel-fix

propagate from branch 'au.asn.ucc.matt.dropbear' (head 924b731b50d4147eed8e9382c98a2573259a6cad) to branch 'au.asn.ucc.matt.dropbear.channel-fix' (head e73ee8f7ae404a9355685c30828a0ad4524031bc)
author Matt Johnston <matt@ucc.asn.au>
date Sun, 11 Feb 2007 09:55:00 +0000
parents a01c0c8e543a
children 9c61e7af0156
comparison
equal deleted inserted replaced
418:ab57ba0cb667 419:b2f81110c80b
59 ses.sock = sock; 59 ses.sock = sock;
60 ses.maxfd = sock; 60 ses.maxfd = sock;
61 61
62 ses.connecttimeout = 0; 62 ses.connecttimeout = 0;
63 63
64 if (pipe(ses.signal_pipe) < 0) {
65 dropbear_exit("signal pipe failed");
66 }
67 setnonblocking(ses.signal_pipe[0]);
68 setnonblocking(ses.signal_pipe[1]);
69
64 kexfirstinitialise(); /* initialise the kex state */ 70 kexfirstinitialise(); /* initialise the kex state */
65 71
66 ses.writepayload = buf_new(MAX_TRANS_PAYLOAD_LEN); 72 ses.writepayload = buf_new(MAX_TRANS_PAYLOAD_LEN);
67 ses.transseq = 0; 73 ses.transseq = 0;
68 74
105 ses.remoteident = NULL; 111 ses.remoteident = NULL;
106 112
107 ses.chantypes = NULL; 113 ses.chantypes = NULL;
108 114
109 ses.allowprivport = 0; 115 ses.allowprivport = 0;
110
111 116
112 TRACE(("leave session_init")) 117 TRACE(("leave session_init"))
113 } 118 }
114 119
115 void session_loop(void(*loophandler)()) { 120 void session_loop(void(*loophandler)()) {
130 FD_SET(ses.sock, &readfd); 135 FD_SET(ses.sock, &readfd);
131 if (!isempty(&ses.writequeue)) { 136 if (!isempty(&ses.writequeue)) {
132 FD_SET(ses.sock, &writefd); 137 FD_SET(ses.sock, &writefd);
133 } 138 }
134 } 139 }
140
141 /* We get woken up when signal handlers write to this pipe.
142 SIGCHLD in svr-chansession is the only one currently. */
143 FD_SET(ses.signal_pipe[0], &readfd);
135 144
136 /* set up for channels which require reading/writing */ 145 /* set up for channels which require reading/writing */
137 if (ses.dataallowed) { 146 if (ses.dataallowed) {
138 setchannelfds(&readfd, &writefd); 147 setchannelfds(&readfd, &writefd);
139 } 148 }
141 150
142 if (exitflag) { 151 if (exitflag) {
143 dropbear_exit("Terminated by signal"); 152 dropbear_exit("Terminated by signal");
144 } 153 }
145 154
146 if (val < 0) { 155 if (val < 0 && errno != EINTR) {
147 if (errno == EINTR) { 156 dropbear_exit("Error in select");
148 /* This must happen even if we've been interrupted, so that 157 }
149 * changed signal-handler vars can take effect etc */ 158
150 if (loophandler) { 159 if (val <= 0) {
151 loophandler(); 160 /* If we were interrupted or the select timed out, we still
152 } 161 * want to iterate over channels etc for reading, to handle
153 continue; 162 * server processes exiting etc.
154 } else { 163 * We don't want to read/write FDs. */
155 dropbear_exit("Error in select"); 164 FD_ZERO(&writefd);
156 } 165 FD_ZERO(&readfd);
166 }
167
168 /* We'll just empty out the pipe if required. We don't do
169 any thing with the data, since the pipe's purpose is purely to
170 wake up the select() above. */
171 if (FD_ISSET(ses.signal_pipe[0], &readfd)) {
172 char x;
173 while (read(ses.signal_pipe[0], &x, 1) > 0) {}
157 } 174 }
158 175
159 /* check for auth timeout, rekeying required etc */ 176 /* check for auth timeout, rekeying required etc */
160 checktimeouts(); 177 checktimeouts();
161
162 if (val == 0) {
163 /* timeout */
164 TRACE(("select timeout"))
165 continue;
166 }
167 178
168 /* process session socket's incoming/outgoing data */ 179 /* process session socket's incoming/outgoing data */
169 if (ses.sock != -1) { 180 if (ses.sock != -1) {
170 if (FD_ISSET(ses.sock, &writefd) && !isempty(&ses.writequeue)) { 181 if (FD_ISSET(ses.sock, &writefd) && !isempty(&ses.writequeue)) {
171 write_packet(); 182 write_packet();