31
31
#include <fcntl.h>              /* open(), O_WRONLY, O_RDONLY */
 
32
32
#include <iso646.h>             /* and, or, not*/
 
33
33
#include <errno.h>              /* errno, EINTR */
 
35
34
#include <sys/types.h>          /* size_t, ssize_t, pid_t, DIR, struct
 
37
36
#include <stddef.h>             /* NULL */
 
38
37
#include <string.h>             /* strlen(), memcmp() */
 
39
 
#include <stdio.h>              /* asprintf()*/
 
 
38
#include <stdio.h>              /* asprintf(), perror() */
 
40
39
#include <unistd.h>             /* close(), write(), readlink(),
 
41
40
                                   read(), STDOUT_FILENO, sleep(),
 
42
41
                                   fork(), setuid(), geteuid(),
 
43
42
                                   setsid(), chdir(), dup2(),
 
44
43
                                   STDERR_FILENO, execv() */
 
45
44
#include <stdlib.h>             /* free(), EXIT_FAILURE, realloc(),
 
46
 
                                   EXIT_SUCCESS, malloc(), _exit(),
 
 
45
                                   EXIT_SUCCESS, malloc(), _exit() */
 
 
46
#include <stdlib.h>             /* getenv() */
 
48
47
#include <dirent.h>             /* opendir(), readdir(), closedir() */
 
49
48
#include <inttypes.h>           /* intmax_t, strtoimax() */
 
50
49
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
 
51
 
#include <sysexits.h>           /* EX_OSERR, EX_UNAVAILABLE */
 
53
51
sig_atomic_t interrupted_by_signal = 0;
 
54
52
int signal_received;
 
 
225
223
        ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
 
226
224
                       proc_ent->d_name);
 
228
 
          error(0, errno, "asprintf");
 
229
227
          goto fail_find_usplash;
 
231
229
        cl_fd = open(cmdline_filename, O_RDONLY);
 
232
230
        free(cmdline_filename);
 
234
 
          error(0, errno, "open");
 
235
233
          goto fail_find_usplash;
 
 
243
241
        if(cmdline_len + blocksize > cmdline_allocated){
 
244
242
          tmp = realloc(cmdline, cmdline_allocated + blocksize);
 
246
 
            error(0, errno, "realloc");
 
248
246
            goto fail_find_usplash;
 
 
262
260
      } while(sret != 0);
 
263
261
      ret = close(cl_fd);
 
265
 
        error(0, errno, "close");
 
266
264
        goto fail_find_usplash;
 
269
267
    /* Close directory */
 
270
268
    ret = closedir(proc_dir);
 
272
 
      error(0, errno, "closedir");
 
273
271
      goto fail_find_usplash;
 
 
324
319
    sigemptyset(&new_action.sa_mask);
 
325
320
    ret = sigaddset(&new_action.sa_mask, SIGINT);
 
327
 
      error(0, errno, "sigaddset");
 
331
325
    ret = sigaddset(&new_action.sa_mask, SIGHUP);
 
333
 
      error(0, errno, "sigaddset");
 
337
330
    ret = sigaddset(&new_action.sa_mask, SIGTERM);
 
339
 
      error(0, errno, "sigaddset");
 
343
335
    ret = sigaction(SIGINT, NULL, &old_action);
 
345
337
      if(errno != EINTR){
 
346
 
        error(0, errno, "sigaction");
 
 
400
386
  /* Write command to FIFO */
 
401
387
  if(not usplash_write(&fifo_fd, "TIMEOUT", "0")){
 
402
388
    if(errno != EINTR){
 
403
 
      error(0, errno, "usplash_write");
 
 
389
      perror("usplash_write");
 
 
547
524
  /* If usplash was never accessed, we can stop now */
 
548
525
  if(not usplash_accessed){
 
553
530
  if(fifo_fd != -1){
 
554
531
    ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
 
555
532
    if(ret == -1 and errno != EINTR){
 
556
 
      error(0, errno, "close");
 
 
603
580
       the real user ID (_mandos) */
 
604
581
    ret = setuid(geteuid());
 
606
 
      error(0, errno, "setuid");
 
610
587
    ret = chdir("/");
 
612
 
      error(0, errno, "chdir");
 
615
588
/*     if(fork() != 0){ */
 
616
589
/*       _exit(EXIT_SUCCESS); */
 
618
591
    ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace our stdout */
 
620
 
      error(0, errno, "dup2");
 
624
597
    execv(usplash_name, cmdline_argv);
 
625
598
    if(not interrupted_by_signal){
 
626
 
      error(0, errno, "execv");
 
629
602
    free(cmdline_argv);
 
633
606
  free(cmdline_argv);
 
635
608
  if(not usplash_write(&fifo_fd, "PULSATE", NULL)){
 
636
609
    if(errno != EINTR){
 
637
 
      error(0, errno, "usplash_write");
 
 
610
      perror("usplash_write");
 
641
614
  /* Close FIFO (again) */
 
643
 
    ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
 
644
 
    if(ret == -1 and errno != EINTR){
 
645
 
      error(0, errno, "close");
 
 
615
  ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
 
 
616
  if(ret == -1 and errno != EINTR){
 
650
621
  if(interrupted_by_signal){
 
651
622
    struct sigaction signal_action = { .sa_handler = SIG_DFL };
 
 
653
624
    ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
 
654
625
                                            &signal_action, NULL));
 
656
 
      error(0, errno, "sigaction");
 
659
630
      ret = raise(signal_received);
 
660
631
    } while(ret != 0 and errno == EINTR);
 
662
 
      error(0, errno, "raise");
 
665
636
    TEMP_FAILURE_RETRY(pause());