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 */
34
35
#include <sys/types.h> /* size_t, ssize_t, pid_t, DIR, struct
36
37
#include <stddef.h> /* NULL */
37
38
#include <string.h> /* strlen(), memcmp() */
38
#include <stdio.h> /* asprintf(), perror() */
39
#include <stdio.h> /* asprintf()*/
39
40
#include <unistd.h> /* close(), write(), readlink(),
40
41
read(), STDOUT_FILENO, sleep(),
41
42
fork(), setuid(), geteuid(),
42
43
setsid(), chdir(), dup2(),
43
44
STDERR_FILENO, execv() */
44
45
#include <stdlib.h> /* free(), EXIT_FAILURE, realloc(),
45
EXIT_SUCCESS, malloc(), _exit() */
46
#include <stdlib.h> /* getenv() */
46
EXIT_SUCCESS, malloc(), _exit(),
47
48
#include <dirent.h> /* opendir(), readdir(), closedir() */
48
49
#include <inttypes.h> /* intmax_t, strtoimax() */
49
50
#include <sys/stat.h> /* struct stat, lstat(), S_ISLNK */
50
51
#include <sysexits.h> /* EX_OSERR, EX_UNAVAILABLE */
52
#include <argz.h> /* argz_count(), argz_extract() */
52
54
sig_atomic_t interrupted_by_signal = 0;
53
55
int signal_received;
224
226
ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
225
227
proc_ent->d_name);
229
error(0, errno, "asprintf");
228
230
goto fail_find_usplash;
230
232
cl_fd = open(cmdline_filename, O_RDONLY);
231
233
free(cmdline_filename);
235
error(0, errno, "open");
234
236
goto fail_find_usplash;
323
325
sigemptyset(&new_action.sa_mask);
324
326
ret = sigaddset(&new_action.sa_mask, SIGINT);
328
error(0, errno, "sigaddset");
327
329
status = EX_OSERR;
330
332
ret = sigaddset(&new_action.sa_mask, SIGHUP);
334
error(0, errno, "sigaddset");
333
335
status = EX_OSERR;
336
338
ret = sigaddset(&new_action.sa_mask, SIGTERM);
340
error(0, errno, "sigaddset");
339
341
status = EX_OSERR;
342
344
ret = sigaction(SIGINT, NULL, &old_action);
344
346
if(errno != EINTR){
347
error(0, errno, "sigaction");
346
348
status = EX_OSERR;
399
401
/* Write command to FIFO */
400
402
if(not usplash_write(&fifo_fd, "TIMEOUT", "0")){
401
403
if(errno != EINTR){
402
perror("usplash_write");
404
error(0, errno, "usplash_write");
403
405
status = EX_OSERR;
561
563
if(outfifo_fd != -1){
562
564
ret = (int)TEMP_FAILURE_RETRY(close(outfifo_fd));
568
/* Create argc and argv for new usplash*/
569
int cmdline_argc = 0;
570
char **cmdline_argv = malloc(sizeof(char *));
573
while(position < cmdline_len){
574
char **tmp = realloc(cmdline_argv,
576
* (size_t)(cmdline_argc + 2)));
583
cmdline_argv[cmdline_argc] = cmdline + position;
585
position += strlen(cmdline + position) + 1;
587
cmdline_argv[cmdline_argc] = NULL;
566
error(0, errno, "close");
570
/* Create argv for new usplash*/
571
char **cmdline_argv = malloc((argz_count(cmdline, cmdline_len) + 1)
572
* sizeof(char *)); /* Count args */
573
if(cmdline_argv == NULL){
574
error(0, errno, "malloc");
577
argz_extract(cmdline, cmdline_len, cmdline_argv); /* Create argv */
589
579
/* Kill old usplash */
590
580
kill(usplash_pid, SIGTERM);
602
592
the real user ID (_mandos) */
603
593
ret = setuid(geteuid());
595
error(0, errno, "setuid");
609
599
ret = chdir("/");
601
error(0, errno, "chdir");
610
604
/* if(fork() != 0){ */
611
605
/* _exit(EXIT_SUCCESS); */
613
607
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace our stdout */
609
error(0, errno, "dup2");
619
613
execv(usplash_name, cmdline_argv);
620
614
if(not interrupted_by_signal){
615
error(0, errno, "execv");
624
618
free(cmdline_argv);
648
642
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
649
643
&signal_action, NULL));
645
error(0, errno, "sigaction");
654
648
ret = raise(signal_received);
655
649
} while(ret != 0 and errno == EINTR);
651
error(0, errno, "raise");
660
654
TEMP_FAILURE_RETRY(pause());