177
175
sigaddset(&new_action.sa_mask, SIGINT);
179
177
perror("sigaddset");
183
180
sigaddset(&new_action.sa_mask, SIGHUP);
185
182
perror("sigaddset");
189
185
sigaddset(&new_action.sa_mask, SIGTERM);
191
187
perror("sigaddset");
195
190
ret = sigaction(SIGINT, NULL, &old_action);
197
192
perror("sigaction");
201
195
if(old_action.sa_handler != SIG_IGN){
202
196
ret = sigaction(SIGINT, &new_action, NULL);
204
198
perror("sigaction");
209
202
ret = sigaction(SIGHUP, NULL, &old_action);
211
204
perror("sigaction");
215
207
if(old_action.sa_handler != SIG_IGN){
216
208
ret = sigaction(SIGHUP, &new_action, NULL);
218
210
perror("sigaction");
223
214
ret = sigaction(SIGTERM, NULL, &old_action);
225
216
perror("sigaction");
229
219
if(old_action.sa_handler != SIG_IGN){
230
220
ret = sigaction(SIGTERM, &new_action, NULL);
232
222
perror("sigaction");
228
if(interrupted_by_signal){
239
232
/* Fork off the splashy command to prompt for password */
240
pid_t splashy_command_pid = 0;
241
if(not interrupted_by_signal){
242
splashy_command_pid = fork();
243
if(splashy_command_pid == -1){
244
if(not interrupted_by_signal){
250
if(splashy_command_pid == 0){
233
splashy_command_pid = fork();
234
if(splashy_command_pid != 0 and interrupted_by_signal){
237
if(splashy_command_pid == -1){
242
if(splashy_command_pid == 0){
243
if(not interrupted_by_signal){
251
244
const char splashy_command[] = "/sbin/splashy_update";
252
ret = execl(splashy_command, splashy_command, prompt,
254
if(not interrupted_by_signal){
245
execl(splashy_command, splashy_command, prompt, (char *)NULL);
256
if(interrupted_by_signal){
265
260
/* Wait for command to complete */
266
if(not interrupted_by_signal and splashy_command_pid != 0){
268
ret = waitpid(splashy_command_pid, &status, 0);
264
ret = waitpid(splashy_command_pid, &status, 0);
265
} while(ret == -1 and errno == EINTR
266
and not interrupted_by_signal);
267
if(interrupted_by_signal){
273
272
if(errno == ECHILD){
274
273
splashy_command_pid = 0;
277
276
/* The child process has exited */
278
277
splashy_command_pid = 0;
279
if(not interrupted_by_signal and WIFEXITED(status)
280
and WEXITSTATUS(status)==0){
278
if(WIFEXITED(status) and WEXITSTATUS(status) == 0){
281
279
return EXIT_SUCCESS;
285
kill(splashy_pid, SIGTERM);
286
if(interrupted_by_signal and splashy_command_pid != 0){
287
kill(splashy_command_pid, SIGTERM);
290
while(kill(splashy_pid, 0) == 0){
291
kill(splashy_pid, SIGKILL);
294
pid_t new_splashy_pid = fork();
295
if(new_splashy_pid == 0){
296
/* Child; will become new splashy process */
288
if(proc_dir != NULL){
289
TEMP_FAILURE_RETRY(closedir(proc_dir));
292
if(splashy_command_pid != 0){
293
TEMP_FAILURE_RETRY(kill(splashy_command_pid, SIGTERM));
298
/* Make the effective user ID (root) the only user ID instead of
299
the real user ID (_mandos) */
300
ret = setuid(geteuid());
295
TEMP_FAILURE_RETRY(kill(splashy_pid, SIGTERM));
297
while(TEMP_FAILURE_RETRY(kill(splashy_pid, 0)) == 0){
298
TEMP_FAILURE_RETRY(kill(splashy_pid, SIGKILL));
301
pid_t new_splashy_pid = TEMP_FAILURE_RETRY(fork());
302
if(new_splashy_pid == 0){
303
/* Child; will become new splashy process */
305
/* Make the effective user ID (root) the only user ID instead of
306
the real user ID (_mandos) */
307
ret = setuid(geteuid());
317
/* if(fork() != 0){ */
318
/* _exit(EXIT_SUCCESS); */
320
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
307
/* if(fork() != 0){ */
308
/* _exit(EXIT_SUCCESS); */
310
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace our stdout */
326
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
313
328
_exit(EXIT_FAILURE);
316
execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
317
if(not interrupted_by_signal){
332
if(interrupted_by_signal){
333
struct sigaction signal_action;
334
sigemptyset(&signal_action.sa_mask);
335
signal_action.sa_handler = SIG_DFL;
336
ret = TEMP_FAILURE_RETRY(sigaction(signal_received,
337
&signal_action, NULL));
342
ret = raise(signal_received);
343
} while(ret != 0 and errno == EINTR);
348
TEMP_FAILURE_RETRY(pause());
323
351
return EXIT_FAILURE;