1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
/*
* bootsplash.c
*
* Bootsplash.org splash method support
*
* Copyright (C) 2006 Holger Macht <holger@homac.de>
*
* This file is released under the GPLv2.
*
*/
#include "config.h"
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include "vt.h"
#include "encrypt.h"
#define BOOTSPLASH_PROC "/proc/splash"
#define MAX_LINE_SIZE 1024
static FILE *splash_file = NULL;
int bootsplash_finish(void)
{
if (splash_file) {
fclose(splash_file);
splash_file = NULL;
}
return 0;
}
static int bootsplash_write(const char *buf)
{
int error = 0;
if (!splash_file)
return -1;
error = fputs(buf, splash_file);
if (error == EOF) {
fprintf(stderr, "Could not write '%s' to %s: %s\n",
buf, BOOTSPLASH_PROC, strerror(errno));
bootsplash_finish();
return error;
}
fflush(splash_file);
return 0;
}
static int bootsplash_to_silent(void)
{
return bootsplash_write("silent\n");
}
static int bootsplash_to_verbose(void)
{
return bootsplash_write("verbose\n");
}
int bootsplash_open(void)
{
char *str, buf[MAX_LINE_SIZE];
splash_file = fopen(BOOTSPLASH_PROC, "r+");
if (!splash_file)
return -1;
str = fgets(buf, MAX_LINE_SIZE, splash_file);
if (!str)
goto close;
if (!strstr(buf, ": on"))
goto close;
bootsplash_to_silent();
return 0;
close:
bootsplash_finish();
return -1;
}
void bootsplash_switch_to(void)
{
if (splash_file) {
/* assume that bootsplash is on console 1, there's no way
* to figure this out AFAIK */
chvt(1);
}
}
inline int bootsplash_progress(int p)
{
char buf[MAX_LINE_SIZE];
if (!splash_file)
return -1;
/* 65535 corresponds to 100 % on the progress bar */
snprintf(buf, MAX_LINE_SIZE, "show %d\n", p * (65535 / 100));
return bootsplash_write(buf);
}
void bootsplash_read_password(char * buf, int vrfy)
{
#if CONFIG_ENCRYPT
bootsplash_to_verbose();
read_password(buf, vrfy);
bootsplash_to_silent();
#endif
}
int bootsplash_dialog(const char *prompt)
{
int ret;
bootsplash_to_verbose();
printf(prompt);
ret = getchar();
bootsplash_to_silent();
return ret;
}
|