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 */
35
34
#include <sys/types.h> /* size_t, ssize_t, pid_t, DIR, struct
37
36
#include <stddef.h> /* NULL */
38
37
#include <string.h> /* strlen(), memcmp() */
39
#include <stdio.h> /* asprintf()*/
38
#include <stdio.h> /* asprintf(), perror() */
40
39
#include <unistd.h> /* close(), write(), readlink(),
41
40
read(), STDOUT_FILENO, sleep(),
42
41
fork(), setuid(), geteuid(),
43
42
setsid(), chdir(), dup2(),
44
43
STDERR_FILENO, execv() */
45
44
#include <stdlib.h> /* free(), EXIT_FAILURE, realloc(),
46
EXIT_SUCCESS, malloc(), _exit(),
45
EXIT_SUCCESS, malloc(), _exit() */
46
#include <stdlib.h> /* getenv() */
48
47
#include <dirent.h> /* opendir(), readdir(), closedir() */
49
48
#include <inttypes.h> /* intmax_t, strtoimax() */
50
49
#include <sys/stat.h> /* struct stat, lstat(), S_ISLNK */
225
224
ret = asprintf(&cmdline_filename, "/proc/%s/cmdline",
226
225
proc_ent->d_name);
228
error(0, errno, "asprintf");
229
228
goto fail_find_usplash;
231
230
cl_fd = open(cmdline_filename, O_RDONLY);
232
231
free(cmdline_filename);
234
error(0, errno, "open");
235
234
goto fail_find_usplash;
243
242
if(cmdline_len + blocksize > cmdline_allocated){
244
243
tmp = realloc(cmdline, cmdline_allocated + blocksize);
246
error(0, errno, "realloc");
248
247
goto fail_find_usplash;
262
261
} while(sret != 0);
263
262
ret = close(cl_fd);
265
error(0, errno, "close");
266
265
goto fail_find_usplash;
269
268
/* Close directory */
270
269
ret = closedir(proc_dir);
272
error(0, errno, "closedir");
273
272
goto fail_find_usplash;
324
323
sigemptyset(&new_action.sa_mask);
325
324
ret = sigaddset(&new_action.sa_mask, SIGINT);
327
error(0, errno, "sigaddset");
328
327
status = EX_OSERR;
331
330
ret = sigaddset(&new_action.sa_mask, SIGHUP);
333
error(0, errno, "sigaddset");
334
333
status = EX_OSERR;
337
336
ret = sigaddset(&new_action.sa_mask, SIGTERM);
339
error(0, errno, "sigaddset");
340
339
status = EX_OSERR;
343
342
ret = sigaction(SIGINT, NULL, &old_action);
345
344
if(errno != EINTR){
346
error(0, errno, "sigaction");
347
346
status = EX_OSERR;
400
399
/* Write command to FIFO */
401
400
if(not usplash_write(&fifo_fd, "TIMEOUT", "0")){
402
401
if(errno != EINTR){
403
error(0, errno, "usplash_write");
402
perror("usplash_write");
404
403
status = EX_OSERR;
603
602
the real user ID (_mandos) */
604
603
ret = setuid(geteuid());
606
error(0, errno, "setuid");
610
609
ret = chdir("/");
612
error(0, errno, "chdir");
615
610
/* if(fork() != 0){ */
616
611
/* _exit(EXIT_SUCCESS); */
618
613
ret = dup2(STDERR_FILENO, STDOUT_FILENO); /* replace our stdout */
620
error(0, errno, "dup2");
624
619
execv(usplash_name, cmdline_argv);
625
620
if(not interrupted_by_signal){
626
error(0, errno, "execv");
629
624
free(cmdline_argv);
653
648
ret = (int)TEMP_FAILURE_RETRY(sigaction(signal_received,
654
649
&signal_action, NULL));
656
error(0, errno, "sigaction");
659
654
ret = raise(signal_received);
660
655
} while(ret != 0 and errno == EINTR);
662
error(0, errno, "raise");
665
660
TEMP_FAILURE_RETRY(pause());