@@ -150,69 +150,6 @@ static int handle_just_exec(struct qrexec_parsed_command *cmd)
150
150
return 0 ;
151
151
}
152
152
153
- static const long BILLION_NANOSECONDS = 1000000000L ;
154
-
155
- static int wait_for_vchan_connection_with_timeout (
156
- libvchan_t * conn , int wait_fd , bool is_server , time_t timeout ) {
157
- struct timespec end_tp , now_tp , timeout_tp ;
158
-
159
- if (timeout && clock_gettime (CLOCK_MONOTONIC , & end_tp )) {
160
- PERROR ("clock_gettime" );
161
- return -1 ;
162
- }
163
- assert (end_tp .tv_nsec >= 0 && end_tp .tv_nsec < BILLION_NANOSECONDS );
164
- end_tp .tv_sec += timeout ;
165
- while (true) {
166
- bool did_timeout = true;
167
- struct pollfd fds = { .fd = wait_fd , .events = POLLIN | POLLHUP , .revents = 0 };
168
-
169
- /* calculate how much time left until connection timeout expire */
170
- if (clock_gettime (CLOCK_MONOTONIC , & now_tp )) {
171
- PERROR ("clock_gettime" );
172
- return -1 ;
173
- }
174
- assert (now_tp .tv_nsec >= 0 && now_tp .tv_nsec < BILLION_NANOSECONDS );
175
- if (now_tp .tv_sec <= end_tp .tv_sec ) {
176
- timeout_tp .tv_sec = end_tp .tv_sec - now_tp .tv_sec ;
177
- timeout_tp .tv_nsec = end_tp .tv_nsec - now_tp .tv_nsec ;
178
- if (timeout_tp .tv_nsec < 0 ) {
179
- timeout_tp .tv_nsec += BILLION_NANOSECONDS ;
180
- timeout_tp .tv_sec -- ;
181
- }
182
- did_timeout = timeout_tp .tv_sec < 0 ;
183
- }
184
- switch (did_timeout ? 0 : ppoll (& fds , 1 , & timeout_tp , NULL )) {
185
- case -1 :
186
- if (errno == EINTR )
187
- break ;
188
- LOG (ERROR , "vchan connection error" );
189
- return -1 ;
190
- case 0 :
191
- LOG (ERROR , "vchan connection timeout" );
192
- return -1 ;
193
- case 1 :
194
- break ;
195
- default :
196
- abort ();
197
- }
198
- if (fds .revents & POLLIN ) {
199
- if (is_server ) {
200
- libvchan_wait (conn );
201
- return 0 ;
202
- } else {
203
- int connect_ret = libvchan_client_init_async_finish (conn , true);
204
-
205
- if (connect_ret < 0 ) {
206
- LOG (ERROR , "vchan connection error" );
207
- return -1 ;
208
- } else if (connect_ret == 0 ) {
209
- return 0 ;
210
- }
211
- }
212
- }
213
- }
214
- }
215
-
216
153
217
154
/* Behaviour depends on type parameter:
218
155
* MSG_JUST_EXEC - connect to vchan server, fork+exec process given by cmdline
@@ -253,7 +190,8 @@ static int handle_new_process_common(
253
190
LOG (ERROR , "Data vchan connection failed" );
254
191
exit (1 );
255
192
}
256
- if (wait_for_vchan_connection_with_timeout (data_vchan , wait_fd , false, connection_timeout ) < 0 ) {
193
+ if (qubes_wait_for_vchan_connection_with_timeout (
194
+ data_vchan , wait_fd , false, connection_timeout ) < 0 ) {
257
195
LOG (ERROR , "Data vchan connection failed" );
258
196
exit (1 );
259
197
}
@@ -381,7 +319,7 @@ int handle_data_client(
381
319
LOG (ERROR , "Data vchan connection failed" );
382
320
exit (1 );
383
321
}
384
- if (wait_for_vchan_connection_with_timeout (
322
+ if (qubes_wait_for_vchan_connection_with_timeout (
385
323
data_vchan , libvchan_fd_for_select (data_vchan ), true, connection_timeout ) < 0 ) {
386
324
LOG (ERROR , "Data vchan connection failed" );
387
325
exit (1 );
0 commit comments