27
27
interrupted_by_signal = 1;
30
static bool usplash_write(const char *cmd, const char *arg){
32
* usplash_write("TIMEOUT", "15"); -> "TIMEOUT 15\0"
33
* usplash_write("PULSATE", NULL); -> "PULSATE\0"
40
fifo_fd = open("/dev/.initramfs/usplash_fifo", O_WRONLY);
41
if(fifo_fd == -1 and (errno != EINTR or interrupted_by_signal)){
44
}while(fifo_fd == -1);
47
char *cmd_line_alloc = NULL;
50
ret = (int)strlen(cmd);
53
ret = asprintf(&cmd_line_alloc, "%s %s", cmd, arg);
54
if(ret == -1 and (errno != EINTR or interrupted_by_signal)){
61
cmd_line = cmd_line_alloc;
64
size_t cmd_line_len = (size_t)ret + 1;
66
while(not interrupted_by_signal and written < cmd_line_len){
67
ret = write(fifo_fd, cmd_line + written,
68
cmd_line_len - written);
70
if(errno != EINTR or interrupted_by_signal){
80
written += (size_t)ret;
85
if(ret == -1 and (errno != EINTR or interrupted_by_signal)){
89
if(interrupted_by_signal){
30
95
int main(__attribute__((unused))int argc,
31
96
__attribute__((unused))char **argv){
218
283
/* Write command to FIFO */
219
284
if(not interrupted_by_signal){
220
int fifo_fd = open("/dev/.initramfs/usplash_fifo", O_WRONLY);
227
ret = asprintf(&command, "INPUTQUIET %s", prompt);
235
size_t command_len = (size_t)ret + 1;
237
while(not interrupted_by_signal and written < command_len){
238
ret = write(fifo_fd, command + written, command_len - written);
240
if(interrupted_by_signal){
248
an_error_occured = true;
251
written += (size_t)ret;
253
ret = close(fifo_fd);
254
if(ret == -1 and not interrupted_by_signal){
255
an_error_occured = true;
285
if(not usplash_write("TIMEOUT", "0")
286
and (errno != EINTR)){
287
perror("usplash_write");
288
an_error_occured = true;
291
if(not interrupted_by_signal and not an_error_occured){
292
if(not usplash_write("INPUTQUIET", prompt)
293
and (errno != EINTR)){
294
perror("usplash_write");
295
an_error_occured = true;
300
/* This is not really a loop; while() is used to be able to "break"
301
out of it; those breaks are marked "Big" */
302
while(not interrupted_by_signal and not an_error_occured){
263
303
char *buf = NULL;
264
304
size_t buf_len = 0;
309
fifo_fd = open("/dev/.initramfs/usplash_outfifo", O_RDONLY);
313
an_error_occured = true;
316
if(interrupted_by_signal){
320
}while(fifo_fd == -1);
321
if(interrupted_by_signal or an_error_occured){
266
325
/* Read from FIFO */
267
if(not interrupted_by_signal and not an_error_occured){
268
int fifo_fd = open("/dev/.initramfs/usplash_outfifo", O_RDONLY);
269
if(fifo_fd == -1 and not interrupted_by_signal){
326
size_t buf_allocated = 0;
327
const size_t blocksize = 1024;
329
if(buf_len + blocksize > buf_allocated){
330
char *tmp = realloc(buf, buf_allocated + blocksize);
333
an_error_occured = true;
337
buf_allocated += blocksize;
273
size_t buf_allocated = 0;
274
const int blocksize = 1024;
276
if(buf_len + blocksize > buf_allocated){
277
char *tmp = realloc(buf, buf_allocated + blocksize);
280
an_error_occured = true;
284
buf_allocated += blocksize;
286
340
sret = read(fifo_fd, buf + buf_len, buf_allocated - buf_len);
289
an_error_occured = true;
344
an_error_occured = true;
347
if(interrupted_by_signal){
292
buf_len += (size_t)sret;
293
}while(not interrupted_by_signal and sret != 0);
352
if(interrupted_by_signal or an_error_occured){
356
buf_len += (size_t)sret;
359
if(interrupted_by_signal or an_error_occured){
363
if(not usplash_write("TIMEOUT", "15")
364
and (errno != EINTR)){
365
perror("usplash_write");
366
an_error_occured = true;
368
if(interrupted_by_signal or an_error_occured){
297
372
/* Print password to stdout */
298
if(not interrupted_by_signal and not an_error_occured){
301
376
sret = write(STDOUT_FILENO, buf + written, buf_len - written);
302
if(sret == -1 and not interrupted_by_signal){
304
an_error_occured = true;
380
an_error_occured = true;
383
if(interrupted_by_signal){
307
written += (size_t)sret;
308
}while(written < buf_len);
309
if(not interrupted_by_signal and not an_error_occured){
388
if(interrupted_by_signal or an_error_occured){
392
written += (size_t)sret;
393
}while(written < buf_len);
394
if(not interrupted_by_signal and not an_error_occured){
315
kill(usplash_pid, SIGTERM);
400
/* If we got here, an error or interrupt must have happened */
317
402
int cmdline_argc = 0;
318
403
char **cmdline_argv = malloc(sizeof(char *));
319
404
/* Create argv and argc for new usplash*/
321
ptrdiff_t position = 0;
322
while((size_t)position < cmdline_len){
407
while(position < cmdline_len){
323
408
char **tmp = realloc(cmdline_argv,
324
409
(sizeof(char *) * (size_t)(cmdline_argc + 2)));
330
415
cmdline_argv = tmp;
331
416
cmdline_argv[cmdline_argc] = cmdline + position;
333
position = (char *)rawmemchr(cmdline + position, '\0')
418
position += strlen(cmdline + position) + 1;
336
420
cmdline_argv[cmdline_argc] = NULL;
422
/* Kill old usplash */
423
kill(usplash_pid, SIGTERM);
425
while(kill(usplash_pid, 0) == 0){
426
kill(usplash_pid, SIGKILL);
338
429
pid_t new_usplash_pid = fork();
339
430
if(new_usplash_pid == 0){
340
431
/* Child; will become new usplash process */
341
while(kill(usplash_pid, 0)){
343
kill(usplash_pid, SIGKILL);
433
/* Make the effective user ID (root) the only user ID instead of
434
the real user ID (mandos) */
435
ret = setuid(geteuid());
442
/* if(fork() != 0){ */
443
/* _exit(EXIT_SUCCESS); */
346
445
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace our stdout */
349
448
_exit(EXIT_FAILURE);
351
execv("/sbin/usplash", cmdline_argv);
451
execv(usplash_name, cmdline_argv);
454
if(not usplash_write("PULSATE", NULL)
455
and (errno != EINTR)){
456
perror("usplash_write");
354
459
return EXIT_FAILURE;