@@ -16,25 +16,27 @@ int qubes_wait_for_vchan_connection_with_timeout(
16
16
assert (end_tp .tv_nsec >= 0 && end_tp .tv_nsec < BILLION_NANOSECONDS );
17
17
end_tp .tv_sec += timeout ;
18
18
for (;;) {
19
- bool did_timeout = true;
20
19
struct pollfd fds = { .fd = wait_fd , .events = POLLIN | POLLHUP , .revents = 0 };
20
+ bool did_timeout = timeout > 0 ;
21
21
22
22
/* calculate how much time left until connection timeout expire */
23
- if (clock_gettime (CLOCK_MONOTONIC , & now_tp )) {
24
- PERROR ("clock_gettime" );
25
- return -1 ;
26
- }
27
- assert (now_tp .tv_nsec >= 0 && now_tp .tv_nsec < BILLION_NANOSECONDS );
28
- if (now_tp .tv_sec <= end_tp .tv_sec ) {
29
- timeout_tp .tv_sec = end_tp .tv_sec - now_tp .tv_sec ;
30
- timeout_tp .tv_nsec = end_tp .tv_nsec - now_tp .tv_nsec ;
31
- if (timeout_tp .tv_nsec < 0 ) {
32
- timeout_tp .tv_nsec += BILLION_NANOSECONDS ;
33
- timeout_tp .tv_sec -- ;
23
+ if (did_timeout ) {
24
+ if (clock_gettime (CLOCK_MONOTONIC , & now_tp )) {
25
+ PERROR ("clock_gettime" );
26
+ return -1 ;
27
+ }
28
+ assert (now_tp .tv_nsec >= 0 && now_tp .tv_nsec < BILLION_NANOSECONDS );
29
+ if (now_tp .tv_sec <= end_tp .tv_sec ) {
30
+ timeout_tp .tv_sec = end_tp .tv_sec - now_tp .tv_sec ;
31
+ timeout_tp .tv_nsec = end_tp .tv_nsec - now_tp .tv_nsec ;
32
+ if (timeout_tp .tv_nsec < 0 ) {
33
+ timeout_tp .tv_nsec += BILLION_NANOSECONDS ;
34
+ timeout_tp .tv_sec -- ;
35
+ }
36
+ did_timeout = timeout_tp .tv_sec < 0 ;
34
37
}
35
- did_timeout = timeout_tp .tv_sec < 0 ;
36
38
}
37
- switch (did_timeout ? 0 : ppoll (& fds , 1 , & timeout_tp , NULL )) {
39
+ switch (did_timeout ? 0 : ppoll (& fds , 1 , timeout > 0 ? & timeout_tp : NULL , NULL )) {
38
40
case -1 :
39
41
if (errno == EINTR )
40
42
break ;
0 commit comments