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 */
51
#include <sysexits.h> /* EX_OSERR, EX_UNAVAILABLE */
51
53
sig_atomic_t interrupted_by_signal = 0;
52
54
int signal_received;
223
225
ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
224
226
proc_ent->d_name);
228
error(0, errno, "asprintf");
227
229
goto fail_find_usplash;
229
231
cl_fd = open(cmdline_filename, O_RDONLY);
230
232
free(cmdline_filename);
234
error(0, errno, "open");
233
235
goto fail_find_usplash;
241
243
if(cmdline_len + blocksize > cmdline_allocated){
242
244
tmp = realloc(cmdline, cmdline_allocated + blocksize);
246
error(0, errno, "realloc");
246
248
goto fail_find_usplash;
260
262
} while(sret != 0);
261
263
ret = close(cl_fd);
265
error(0, errno, "close");
264
266
goto fail_find_usplash;
267
269
/* Close directory */
268
270
ret = closedir(proc_dir);
272
error(0, errno, "closedir");
271
273
goto fail_find_usplash;
319
324
sigemptyset(&new_action.sa_mask);
320
325
ret = sigaddset(&new_action.sa_mask, SIGINT);
327
error(0, errno, "sigaddset");
325
331
ret = sigaddset(&new_action.sa_mask, SIGHUP);
333
error(0, errno, "sigaddset");
330
337
ret = sigaddset(&new_action.sa_mask, SIGTERM);
339
error(0, errno, "sigaddset");
335
343
ret = sigaction(SIGINT, NULL, &old_action);
337
345
if(errno != EINTR){
346
error(0, errno, "sigaction");
386
400
/* Write command to FIFO */
387
401
if(not usplash_write(&fifo_fd, "TIMEOUT", "0")){
388
402
if(errno != EINTR){
389
perror("usplash_write");
403
error(0, errno, "usplash_write");
524
547
/* If usplash was never accessed, we can stop now */
525
548
if(not usplash_accessed){
530
553
if(fifo_fd != -1){
531
554
ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
532
555
if(ret == -1 and errno != EINTR){
556
error(0, errno, "close");
580
603
the real user ID (_mandos) */
581
604
ret = setuid(geteuid());
606
error(0, errno, "setuid");
587
610
ret = chdir("/");
612
error(0, errno, "chdir");
588
615
/* if(fork() != 0){ */
589
616
/* _exit(EXIT_SUCCESS); */
591
618
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace our stdout */
620
error(0, errno, "dup2");
597
624
execv(usplash_name, cmdline_argv);
598
625
if(not interrupted_by_signal){
626
error(0, errno, "execv");
602
629
free(cmdline_argv);
606
633
free(cmdline_argv);
608
635
if(not usplash_write(&fifo_fd, "PULSATE", NULL)){
609
636
if(errno != EINTR){
610
perror("usplash_write");
637
error(0, errno, "usplash_write");
614
641
/* Close FIFO (again) */
615
ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
616
if(ret == -1 and errno != EINTR){
643
ret = (int)TEMP_FAILURE_RETRY(close(fifo_fd));
644
if(ret == -1 and errno != EINTR){
645
error(0, errno, "close");
621
650
if(interrupted_by_signal){
622
651
struct sigaction signal_action = { .sa_handler = SIG_DFL };
624
653
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
625
654
&signal_action, NULL));
656
error(0, errno, "sigaction");
630
659
ret = raise(signal_received);
631
660
} while(ret != 0 and errno == EINTR);
662
error(0, errno, "raise");
636
665
TEMP_FAILURE_RETRY(pause());