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 */
224
225
ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
225
226
proc_ent->d_name);
228
error(0, errno, "asprintf");
228
229
goto fail_find_usplash;
230
231
cl_fd = open(cmdline_filename, O_RDONLY);
231
232
free(cmdline_filename);
234
error(0, errno, "open");
234
235
goto fail_find_usplash;
242
243
if(cmdline_len + blocksize > cmdline_allocated){
243
244
tmp = realloc(cmdline, cmdline_allocated + blocksize);
246
error(0, errno, "realloc");
247
248
goto fail_find_usplash;
261
262
} while(sret != 0);
262
263
ret = close(cl_fd);
265
error(0, errno, "close");
265
266
goto fail_find_usplash;
268
269
/* Close directory */
269
270
ret = closedir(proc_dir);
272
error(0, errno, "closedir");
272
273
goto fail_find_usplash;
323
324
sigemptyset(&new_action.sa_mask);
324
325
ret = sigaddset(&new_action.sa_mask, SIGINT);
327
error(0, errno, "sigaddset");
327
328
status = EX_OSERR;
330
331
ret = sigaddset(&new_action.sa_mask, SIGHUP);
333
error(0, errno, "sigaddset");
333
334
status = EX_OSERR;
336
337
ret = sigaddset(&new_action.sa_mask, SIGTERM);
339
error(0, errno, "sigaddset");
339
340
status = EX_OSERR;
342
343
ret = sigaction(SIGINT, NULL, &old_action);
344
345
if(errno != EINTR){
346
error(0, errno, "sigaction");
346
347
status = EX_OSERR;
399
400
/* Write command to FIFO */
400
401
if(not usplash_write(&fifo_fd, "TIMEOUT", "0")){
401
402
if(errno != EINTR){
402
perror("usplash_write");
403
error(0, errno, "usplash_write");
403
404
status = EX_OSERR;
602
603
the real user ID (_mandos) */
603
604
ret = setuid(geteuid());
606
error(0, errno, "setuid");
609
610
ret = chdir("/");
612
error(0, errno, "chdir");
610
615
/* if(fork() != 0){ */
611
616
/* _exit(EXIT_SUCCESS); */
613
618
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace our stdout */
620
error(0, errno, "dup2");
619
624
execv(usplash_name, cmdline_argv);
620
625
if(not interrupted_by_signal){
626
error(0, errno, "execv");
624
629
free(cmdline_argv);
648
653
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
649
654
&signal_action, NULL));
656
error(0, errno, "sigaction");
654
659
ret = raise(signal_received);
655
660
} while(ret != 0 and errno == EINTR);
662
error(0, errno, "raise");
660
665
TEMP_FAILURE_RETRY(pause());