/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to plugins.d/usplash.c

Merge from Teddy:

* New upstream release.
* debian/rules: Build with BROKEN_PIE set on mips and mipsel
  architectures - fixes FTBFS there.
* New upstream release.
* Do not copy unnecessary files to initrd (Closes: #551907)

Show diffs side-by-side

added added

removed removed

Lines of Context:
47
47
#include <dirent.h>             /* opendir(), readdir(), closedir() */
48
48
#include <inttypes.h>           /* intmax_t, strtoimax() */
49
49
#include <sys/stat.h>           /* struct stat, lstat(), S_ISLNK */
 
50
#include <sysexits.h>           /* EX_OSERR, EX_UNAVAILABLE */
50
51
 
51
52
sig_atomic_t interrupted_by_signal = 0;
52
53
int signal_received;
297
298
  size_t buf_len = 0;
298
299
  pid_t usplash_pid = -1;
299
300
  bool usplash_accessed = false;
 
301
  int status = EXIT_FAILURE;    /* Default failure exit status */
300
302
  
301
303
  char *prompt = makeprompt();
302
304
  if(prompt == NULL){
 
305
    status = EX_OSERR;
303
306
    goto failure;
304
307
  }
305
308
  
308
311
  size_t cmdline_len = 0;
309
312
  usplash_pid = find_usplash(&cmdline, &cmdline_len);
310
313
  if(usplash_pid == 0){
 
314
    status = EX_UNAVAILABLE;
311
315
    goto failure;
312
316
  }
313
317
  
320
324
    ret = sigaddset(&new_action.sa_mask, SIGINT);
321
325
    if(ret == -1){
322
326
      perror("sigaddset");
 
327
      status = EX_OSERR;
323
328
      goto failure;
324
329
    }
325
330
    ret = sigaddset(&new_action.sa_mask, SIGHUP);
326
331
    if(ret == -1){
327
332
      perror("sigaddset");
 
333
      status = EX_OSERR;
328
334
      goto failure;
329
335
    }
330
336
    ret = sigaddset(&new_action.sa_mask, SIGTERM);
331
337
    if(ret == -1){
332
338
      perror("sigaddset");
 
339
      status = EX_OSERR;
333
340
      goto failure;
334
341
    }
335
342
    ret = sigaction(SIGINT, NULL, &old_action);
336
343
    if(ret == -1){
337
344
      if(errno != EINTR){
338
345
        perror("sigaction");
 
346
        status = EX_OSERR;
339
347
      }
340
348
      goto failure;
341
349
    }
344
352
      if(ret == -1){
345
353
        if(errno != EINTR){
346
354
          perror("sigaction");
 
355
          status = EX_OSERR;
347
356
        }
348
357
        goto failure;
349
358
      }
352
361
    if(ret == -1){
353
362
      if(errno != EINTR){
354
363
        perror("sigaction");
 
364
        status = EX_OSERR;
355
365
      }
356
366
      goto failure;
357
367
    }
360
370
      if(ret == -1){
361
371
        if(errno != EINTR){
362
372
          perror("sigaction");
 
373
          status = EX_OSERR;
363
374
        }
364
375
        goto failure;
365
376
      }
368
379
    if(ret == -1){
369
380
      if(errno != EINTR){
370
381
        perror("sigaction");
 
382
        status = EX_OSERR;
371
383
      }
372
384
      goto failure;
373
385
    }
376
388
      if(ret == -1){
377
389
        if(errno != EINTR){
378
390
          perror("sigaction");
 
391
          status = EX_OSERR;
379
392
        }
380
393
        goto failure;
381
394
      }
387
400
  if(not usplash_write(&fifo_fd, "TIMEOUT", "0")){
388
401
    if(errno != EINTR){
389
402
      perror("usplash_write");
 
403
      status = EX_OSERR;
390
404
    }
391
405
    goto failure;
392
406
  }
398
412
  if(not usplash_write(&fifo_fd, "INPUTQUIET", prompt)){
399
413
    if(errno != EINTR){
400
414
      perror("usplash_write");
 
415
      status = EX_OSERR;
401
416
    }
402
417
    goto failure;
403
418
  }
415
430
  if(outfifo_fd == -1){
416
431
    if(errno != EINTR){
417
432
      perror("open");
 
433
      status = EX_OSERR;
418
434
    }
419
435
    goto failure;
420
436
  }
433
449
      if(tmp == NULL){
434
450
        if(errno != EINTR){
435
451
          perror("realloc");
 
452
          status = EX_OSERR;
436
453
        }
437
454
        goto failure;
438
455
      }
444
461
    if(sret == -1){
445
462
      if(errno != EINTR){
446
463
        perror("read");
 
464
        status = EX_OSERR;
447
465
      }
448
466
      TEMP_FAILURE_RETRY(close(outfifo_fd));
449
467
      goto failure;
458
476
  if(ret == -1){
459
477
    if(errno != EINTR){
460
478
      perror("close");
 
479
      status = EX_OSERR;
461
480
    }
462
481
    goto failure;
463
482
  }
470
489
  if(not usplash_write(&fifo_fd, "TIMEOUT", "15")){
471
490
    if(errno != EINTR){
472
491
      perror("usplash_write");
 
492
      status = EX_OSERR;
473
493
    }
474
494
    goto failure;
475
495
  }
482
502
  if(ret == -1){
483
503
    if(errno != EINTR){
484
504
      perror("close");
 
505
      status = EX_OSERR;
485
506
    }
486
507
    goto failure;
487
508
  }
495
516
      if(sret == -1){
496
517
        if(errno != EINTR){
497
518
          perror("write");
 
519
          status = EX_OSERR;
498
520
        }
499
521
        goto failure;
500
522
      }
523
545
  
524
546
  /* If usplash was never accessed, we can stop now */
525
547
  if(not usplash_accessed){
526
 
    return EXIT_FAILURE;
 
548
    return status;
527
549
  }
528
550
  
529
551
  /* Close FIFO */
555
577
      if(tmp == NULL){
556
578
        perror("realloc");
557
579
        free(cmdline_argv);
558
 
        return EXIT_FAILURE;
 
580
        return status;
559
581
      }
560
582
      cmdline_argv = tmp;
561
583
      cmdline_argv[cmdline_argc] = cmdline + position;
591
613
    ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace our stdout */
592
614
    if(ret == -1){
593
615
      perror("dup2");
594
 
      _exit(EXIT_FAILURE);
 
616
      _exit(EX_OSERR);
595
617
    }
596
618
    
597
619
    execv(usplash_name, cmdline_argv);
600
622
    }
601
623
    free(cmdline);
602
624
    free(cmdline_argv);
603
 
    _exit(EXIT_FAILURE);
 
625
    _exit(EX_OSERR);
604
626
  }
605
627
  free(cmdline);
606
628
  free(cmdline_argv);
638
660
    TEMP_FAILURE_RETRY(pause());
639
661
  }
640
662
  
641
 
  return EXIT_FAILURE;
 
663
  return status;
642
664
}