23
23
* Contact the authors at <mandos@recompile.se>.
26
#define _GNU_SOURCE /* asprintf(), TEMP_FAILURE_RETRY() */
27
#include <signal.h> /* sig_atomic_t, struct sigaction,
28
sigemptyset(), sigaddset(), SIGINT,
29
SIGHUP, SIGTERM, sigaction(),
26
#define _GNU_SOURCE /* program_invocation_short_name,
27
vasprintf(), asprintf(),
28
TEMP_FAILURE_RETRY() */
29
#include <sys/types.h> /* sig_atomic_t, pid_t, setuid(),
30
geteuid(), setsid() */
31
#include <argp.h> /* argp_program_version,
32
argp_program_bug_address,
35
ARGP_ERR_UNKNOWN, struct argp,
36
argp_parse(), ARGP_IN_ORDER */
37
#include <stddef.h> /* NULL, size_t */
31
38
#include <stdbool.h> /* bool, false, true */
39
#include <stdio.h> /* FILE, fprintf(), vfprintf(),
40
vasprintf(), stderr, asprintf(),
41
fopen(), fscanf(), fclose(),
43
#include <stdarg.h> /* va_list, va_start(), vfprintf() */
44
#include <errno.h> /* program_invocation_short_name,
45
errno, ENOMEM, EINTR, ENOENT,
47
#include <string.h> /* strerror(), strdup(), memcmp() */
48
#include <error.h> /* error() */
49
#include <stdlib.h> /* free(), getenv(), malloc(),
50
reallocarray(), realloc(),
51
EXIT_FAILURE, EXIT_SUCCESS */
52
#include <unistd.h> /* TEMP_FAILURE_RETRY(), setuid(),
53
geteuid(), setsid(), chdir(),
54
dup2(), STDERR_FILENO,
55
STDOUT_FILENO, fork(), _exit(),
56
execv(), ssize_t, readlink(),
57
close(), read(), access(), X_OK */
58
#include <signal.h> /* kill(), SIGTERM, struct sigaction,
59
sigemptyset(), SIGINT, SIGHUP,
60
sigaddset(), SIG_IGN */
61
#include <sys/wait.h> /* waitpid(), WIFEXITED(),
62
WEXITSTATUS(), WIFSIGNALED(),
64
#include <iso646.h> /* not, and, or */
65
#include <sysexits.h> /* EX_OSERR, EX_USAGE,
67
#include <stdint.h> /* SIZE_MAX */
68
#include <dirent.h> /* struct dirent, scandir(),
70
#include <inttypes.h> /* uintmax_t, strtoumax(), SCNuMAX,
72
#include <sys/stat.h> /* struct stat, lstat(), S_ISLNK() */
32
73
#include <fcntl.h> /* open(), O_RDONLY */
33
#include <iso646.h> /* and, or, not*/
34
#include <sys/types.h> /* size_t, ssize_t, pid_t, struct
36
#include <sys/wait.h> /* waitpid() */
37
#include <stddef.h> /* NULL */
38
#include <string.h> /* strchr(), memcmp() */
39
#include <stdio.h> /* asprintf(), perror(), fopen(),
40
fscanf(), vasprintf(), fprintf(),
42
#include <unistd.h> /* close(), readlink(), read(),
43
fork(), setsid(), chdir(), dup2(),
44
STDERR_FILENO, execv(), access() */
45
#include <stdlib.h> /* free(), EXIT_FAILURE, realloc(),
46
EXIT_SUCCESS, malloc(), _exit(),
48
#include <dirent.h> /* scandir(), alphasort() */
49
#include <inttypes.h> /* intmax_t, strtoumax(), SCNuMAX */
50
#include <sys/stat.h> /* struct stat, lstat() */
51
#include <sysexits.h> /* EX_OSERR, EX_UNAVAILABLE */
52
#include <error.h> /* error() */
53
#include <errno.h> /* TEMP_FAILURE_RETRY */
54
74
#include <argz.h> /* argz_count(), argz_extract() */
55
#include <stdarg.h> /* va_list, va_start(), ... */
57
76
sig_atomic_t interrupted_by_signal = 0;
77
const char *argp_program_version = "plymouth " VERSION;
78
const char *argp_program_bug_address = "<mandos@recompile.se>";
59
80
/* Used by Ubuntu 11.04 (Natty Narwahl) */
60
81
const char plymouth_old_old_pid[] = "/dev/.initramfs/plymouth.pid";
408
469
int main(__attribute__((unused))int argc,
409
470
__attribute__((unused))char **argv){
411
472
char *prompt_arg;
412
473
pid_t plymouth_command_pid;
478
struct argp_option options[] = {
479
{ .name = "prompt", .key = 128, .arg = "PROMPT",
480
.doc = "The prompt to show" },
481
{ .name = "debug", .key = 129,
482
.doc = "Debug mode" },
486
__attribute__((nonnull(3)))
487
error_t parse_opt (int key, char *arg, __attribute__((unused))
488
struct argp_state *state){
491
case 128: /* --prompt */
494
fprintf_plus(stderr, "Custom prompt \"%s\"\n", prompt);
497
case 129: /* --debug */
501
return ARGP_ERR_UNKNOWN;
506
struct argp argp = { .options = options, .parser = parse_opt,
508
.doc = "Mandos plymouth -- Read and"
509
" output a password" };
510
ret = argp_parse(&argp, argc, argv, ARGP_IN_ORDER, NULL, NULL);
517
error_plus(0, errno, "argp_parse");
520
error_plus(0, errno, "argp_parse");
416
525
/* test -x /bin/plymouth */
417
526
ret = access(plymouth_path, X_OK);
419
528
/* Plymouth is probably not installed. Don't print an error
420
529
message, just exit. */
531
fprintf_plus(stderr, "Plymouth (%s) not found\n",
421
534
exit(EX_UNAVAILABLE);