commit d1bf48edff0d2fb3f1f3849b6ee1b529e1e0f96e from: Caleb Stein date: Wed Aug 12 00:01:35 2026 UTC add fifo assistant process to restrict main pledge further commit - 2e1efec7bbdebe1a293af303972ac0562ec5ce69 commit + d1bf48edff0d2fb3f1f3849b6ee1b529e1e0f96e blob - a35938e3106115a6f9911eafbfd21c8be054d771 blob + f543a341f449998f34d1d61846372585d81763b5 --- include/statbar.h +++ include/statbar.h @@ -24,7 +24,8 @@ extern void read_config(void); extern int open_command_interface(void); extern int open_output(void); extern int open_timer(void); -extern void close_fifos(void); +extern void close_fifos(int delete); +extern pid_t start_fifo_assistant(void); /* Clock */ #define CLOCK_STRING_SIZE 23 blob - a118dc16d10119e830a3bff3a1420697a4a8e5f3 blob + 64d711b1ca02f2b97ed36b93007508c86f5197c5 --- src/fs.c +++ src/fs.c @@ -2,8 +2,8 @@ #include #include -#include #include +#include #include #include @@ -18,6 +18,7 @@ static char *outpath; static int timer_rdfd; static int timer_wrfd; static char *timerpath; +static sig_atomic_t should_quit = 0; static int mkdir_recursive(char *path) @@ -211,19 +212,52 @@ open_timer(void) } void -close_fifos(void) +close_fifos(int delete) { (void)close(cmd_rdfd); (void)close(cmd_wrfd); - (void)remove(cmdpath); + if (delete) (void)remove(cmdpath); free(cmdpath); (void)close(out_rdfd); (void)close(out_wrfd); - (void)remove(outpath); + if (delete) (void)remove(outpath); free(outpath); (void)close(timer_rdfd); (void)close(timer_wrfd); - (void)remove(timerpath); + if (delete) (void)remove(timerpath); free(timerpath); } +static void +signal_handler(int sig) +{ + if (sig == SIGTERM || sig == SIGINT) should_quit = 1; +} + +pid_t +start_fifo_assistant(void) +{ + pid_t pid = fork(); + + if (pid) return pid; + + setproctitle("fifo assistant"); + (void)puts("Started FIFO assistant"); + + (void)signal(SIGTERM, signal_handler); + (void)signal(SIGINT, signal_handler); + + if (pledge("stdio rpath cpath", NULL) == -1) + { + perror("pledge"); + + _exit(1); + } + + while (!should_quit) (void)pause(); + (void)puts("Closing FIFO assistant"); + close_fifos(1); + + _exit(0); +} + blob - 6e727bb37bc5ddc79682c0d32ab9e2d4a0b4176c blob + 963de7a46db1b8b53acd091e6aee03a82337b30d --- src/main.c +++ src/main.c @@ -60,6 +60,7 @@ main(void) int timerval_fd; int network_fd; int mail_fd; + pid_t fifo_pid; pid_t clock_pid; pid_t batt_pid; pid_t vol_pid; @@ -149,7 +150,8 @@ main(void) mail_pfd->events = POLLIN; } - if (pledge("stdio rpath cpath proc", NULL) == -1) + fifo_pid = start_fifo_assistant(); + if (pledge("stdio proc", NULL) == -1) { perror("pledge"); @@ -247,7 +249,8 @@ cleanup: if (timer_pid > 0) (void)kill(timer_pid, SIGTERM); if (network_pid > 0) (void)kill(network_pid, SIGTERM); if (mail_pid > 0) (void)kill(mail_pid, SIGTERM); - close_fifos(); + if (fifo_pid > 0) (void)kill(fifo_pid, SIGTERM); + close_fifos(0); return 0; }