@@ -74,8 +74,14 @@ static void sigusr1_handler(int __attribute__((__unused__))x)
74
74
void prepare_child_env (void ) {
75
75
char pid_s [10 ];
76
76
77
- signal (SIGCHLD , sigchld_handler );
78
- signal (SIGUSR1 , sigusr1_handler );
77
+ struct sigaction action = {
78
+ .sa_handler = sigchld_handler ,
79
+ .sa_flags = 0 ,
80
+ };
81
+ sigemptyset (& action .sa_mask );
82
+ if (sigaction (SIGCHLD , & action , NULL )) abort ();
83
+ action .sa_handler = sigusr1_handler ;
84
+ if (sigaction (SIGUSR1 , & action , NULL )) abort ();
79
85
int res = snprintf (pid_s , sizeof (pid_s ), "%d" , getpid ());
80
86
if (res < 0 ) abort ();
81
87
if (res >= (int )sizeof (pid_s )) abort ();
@@ -160,69 +166,6 @@ static int handle_just_exec(struct qrexec_parsed_command *cmd)
160
166
return 0 ;
161
167
}
162
168
163
- static const long BILLION_NANOSECONDS = 1000000000L ;
164
-
165
- static int wait_for_vchan_connection_with_timeout (
166
- libvchan_t * conn , int wait_fd , bool is_server , time_t timeout ) {
167
- struct timespec end_tp , now_tp , timeout_tp ;
168
-
169
- if (timeout && clock_gettime (CLOCK_MONOTONIC , & end_tp )) {
170
- PERROR ("clock_gettime" );
171
- return -1 ;
172
- }
173
- assert (end_tp .tv_nsec >= 0 && end_tp .tv_nsec < BILLION_NANOSECONDS );
174
- end_tp .tv_sec += timeout ;
175
- while (true) {
176
- bool did_timeout = true;
177
- struct pollfd fds = { .fd = wait_fd , .events = POLLIN | POLLHUP , .revents = 0 };
178
-
179
- /* calculate how much time left until connection timeout expire */
180
- if (clock_gettime (CLOCK_MONOTONIC , & now_tp )) {
181
- PERROR ("clock_gettime" );
182
- return -1 ;
183
- }
184
- assert (now_tp .tv_nsec >= 0 && now_tp .tv_nsec < BILLION_NANOSECONDS );
185
- if (now_tp .tv_sec <= end_tp .tv_sec ) {
186
- timeout_tp .tv_sec = end_tp .tv_sec - now_tp .tv_sec ;
187
- timeout_tp .tv_nsec = end_tp .tv_nsec - now_tp .tv_nsec ;
188
- if (timeout_tp .tv_nsec < 0 ) {
189
- timeout_tp .tv_nsec += BILLION_NANOSECONDS ;
190
- timeout_tp .tv_sec -- ;
191
- }
192
- did_timeout = timeout_tp .tv_sec < 0 ;
193
- }
194
- switch (did_timeout ? 0 : ppoll (& fds , 1 , & timeout_tp , NULL )) {
195
- case -1 :
196
- if (errno == EINTR )
197
- break ;
198
- LOG (ERROR , "vchan connection error" );
199
- return -1 ;
200
- case 0 :
201
- LOG (ERROR , "vchan connection timeout" );
202
- return -1 ;
203
- case 1 :
204
- break ;
205
- default :
206
- abort ();
207
- }
208
- if (fds .revents & POLLIN ) {
209
- if (is_server ) {
210
- libvchan_wait (conn );
211
- return 0 ;
212
- } else {
213
- int connect_ret = libvchan_client_init_async_finish (conn , true);
214
-
215
- if (connect_ret < 0 ) {
216
- LOG (ERROR , "vchan connection error" );
217
- return -1 ;
218
- } else if (connect_ret == 0 ) {
219
- return 0 ;
220
- }
221
- }
222
- }
223
- }
224
- }
225
-
226
169
227
170
/* Behaviour depends on type parameter:
228
171
* MSG_JUST_EXEC - connect to vchan server, fork+exec process given by cmdline
@@ -263,7 +206,8 @@ static int handle_new_process_common(
263
206
LOG (ERROR , "Data vchan connection failed" );
264
207
exit (1 );
265
208
}
266
- if (wait_for_vchan_connection_with_timeout (data_vchan , wait_fd , false, connection_timeout ) < 0 ) {
209
+ if (qubes_wait_for_vchan_connection_with_timeout (
210
+ data_vchan , wait_fd , false, connection_timeout ) < 0 ) {
267
211
LOG (ERROR , "Data vchan connection failed" );
268
212
exit (1 );
269
213
}
@@ -391,7 +335,7 @@ int handle_data_client(
391
335
LOG (ERROR , "Data vchan connection failed" );
392
336
exit (1 );
393
337
}
394
- if (wait_for_vchan_connection_with_timeout (
338
+ if (qubes_wait_for_vchan_connection_with_timeout (
395
339
data_vchan , libvchan_fd_for_select (data_vchan ), true, connection_timeout ) < 0 ) {
396
340
LOG (ERROR , "Data vchan connection failed" );
397
341
exit (1 );
0 commit comments