29
29
                                   SIG_IGN, kill(), SIGKILL */
 
30
30
#include <stddef.h>             /* NULL */
 
31
31
#include <stdlib.h>             /* getenv() */
 
32
 
#include <stdio.h>              /* asprintf(), perror() */
 
 
32
#include <stdio.h>              /* asprintf() */
 
33
33
#include <stdlib.h>             /* EXIT_FAILURE, free(),
 
35
35
#include <sys/types.h>          /* pid_t, DIR, struct dirent,
 
 
43
43
                                   STDOUT_FILENO, _exit(),
 
45
45
#include <string.h>             /* memcmp() */
 
46
 
#include <errno.h>              /* errno */
 
 
46
#include <errno.h>              /* errno, EACCES, ENOTDIR, ELOOP,
 
 
47
                                   ENOENT, ENAMETOOLONG, EMFILE,
 
 
48
                                   ENFILE, ENOMEM, ENOEXEC, EINVAL,
 
 
49
                                   E2BIG, EFAULT, EIO, ETXTBSY,
 
 
50
                                   EISDIR, ELIBBAD, EPERM, EINTR,
 
 
52
#include <error.h>              /* error() */
 
47
53
#include <sys/wait.h>           /* waitpid(), WIFEXITED(),
 
 
55
#include <sysexits.h>           /* EX_OSERR, EX_OSFILE,
 
50
58
sig_atomic_t interrupted_by_signal = 0;
 
51
59
int signal_received;
 
 
99
109
    const char splashy_name[] = "/sbin/splashy";
 
100
110
    proc_dir = opendir("/proc");
 
101
111
    if(proc_dir == NULL){
 
 
113
      error(0, errno, "opendir");
 
 
120
        exitstatus = EX_OSFILE;
 
 
126
        exitstatus = EX_OSERR;
 
105
131
    for(struct dirent *proc_ent = readdir(proc_dir);
 
 
174
214
    sigemptyset(&new_action.sa_mask);
 
175
215
    ret = sigaddset(&new_action.sa_mask, SIGINT);
 
 
217
      error(0, errno, "sigaddset");
 
 
218
      exitstatus = EX_OSERR;
 
180
221
    ret = sigaddset(&new_action.sa_mask, SIGHUP);
 
 
223
      error(0, errno, "sigaddset");
 
 
224
      exitstatus = EX_OSERR;
 
185
227
    ret = sigaddset(&new_action.sa_mask, SIGTERM);
 
 
229
      error(0, errno, "sigaddset");
 
 
230
      exitstatus = EX_OSERR;
 
190
233
    ret = sigaction(SIGINT, NULL, &old_action);
 
 
235
      error(0, errno, "sigaction");
 
 
236
      exitstatus = EX_OSERR;
 
195
239
    if(old_action.sa_handler != SIG_IGN){
 
196
240
      ret = sigaction(SIGINT, &new_action, NULL);
 
 
242
        error(0, errno, "sigaction");
 
 
243
        exitstatus = EX_OSERR;
 
202
247
    ret = sigaction(SIGHUP, NULL, &old_action);
 
 
249
      error(0, errno, "sigaction");
 
 
250
      exitstatus = EX_OSERR;
 
207
253
    if(old_action.sa_handler != SIG_IGN){
 
208
254
      ret = sigaction(SIGHUP, &new_action, NULL);
 
 
256
        error(0, errno, "sigaction");
 
 
257
        exitstatus = EX_OSERR;
 
214
261
    ret = sigaction(SIGTERM, NULL, &old_action);
 
 
263
      error(0, errno, "sigaction");
 
 
264
      exitstatus = EX_OSERR;
 
219
267
    if(old_action.sa_handler != SIG_IGN){
 
220
268
      ret = sigaction(SIGTERM, &new_action, NULL);
 
 
270
        error(0, errno, "sigaction");
 
 
271
        exitstatus = EX_OSERR;
 
 
243
293
    if(not interrupted_by_signal){
 
244
294
      const char splashy_command[] = "/sbin/splashy_update";
 
245
295
      execl(splashy_command, splashy_command, prompt, (char *)NULL);
 
 
297
      error(0, errno, "execl");
 
 
303
        _exit(EX_UNAVAILABLE);
 
249
323
    _exit(EXIT_FAILURE);
 
 
306
380
         the real user ID (_mandos) */
 
307
381
      ret = setuid(geteuid());
 
 
383
        error(0, errno, "setuid");
 
313
387
      ret = chdir("/");
 
 
389
        error(0, errno, "chdir");
 
317
391
/*       if(fork() != 0){ */
 
318
392
/*      _exit(EXIT_SUCCESS); */
 
320
394
      ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace stdout */
 
 
396
        error(0, errno, "dup2");
 
326
400
      execl("/sbin/splashy", "/sbin/splashy", "boot", (char *)NULL);
 
 
403
        error(0, errno, "execl");
 
 
409
          _exit(EX_UNAVAILABLE);
 
 
336
426
    ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
 
337
427
                                            &signal_action, NULL));
 
 
429
      error(0, errno, "sigaction");
 
342
432
      ret = raise(signal_received);
 
343
433
    } while(ret != 0 and errno == EINTR);
 
 
435
      error(0, errno, "raise");
 
348
438
    TEMP_FAILURE_RETRY(pause());