aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsin <sin@2f30.org>2014-02-07 16:15:48 +0000
committersin <sin@2f30.org>2014-02-07 16:15:48 +0000
commitb8cb53193c0d235cec99d70bb63838f27c3c5fda (patch)
treee3ee7a83080fb556532af67b945773717eff66c2
parentc381441b7020aaeea599de9a5569e2be8fb147c6 (diff)
Remove FIFO from sinit
We can just run /bin/rc.shutdown reboot|poweroff etc. It complicates things when rootfs is mounted as ro etc.
-rw-r--r--config.def.h7
-rw-r--r--sinit.c62
2 files changed, 3 insertions, 66 deletions
diff --git a/config.def.h b/config.def.h
index 9bfe505..75b2329 100644
--- a/config.def.h
+++ b/config.def.h
@@ -3,10 +3,3 @@
static const char *rcinitcmd[] = { "/bin/rc.init", NULL };
static const char *rcrebootcmd[] = { "/bin/rc.shutdown", "reboot", NULL };
static const char *rcpoweroffcmd[] = { "/bin/rc.shutdown", "poweroff", NULL };
-
-/* if you make this path NULL, then sinit will not use a FIFO */
-static const char *fifopath = "/var/run/sinit.fifo";
-static Command commands[] = {
- { "poweroff", spawn, { .v = rcpoweroffcmd } },
- { "reboot", spawn, { .v = rcrebootcmd } },
-};
diff --git a/sinit.c b/sinit.c
index 0bb6503..eff6533 100644
--- a/sinit.c
+++ b/sinit.c
@@ -18,12 +18,6 @@ typedef union {
const void *v;
} Arg;
-typedef struct {
- const char *name;
- void (*func)(const Arg *arg);
- const Arg arg;
-} Command;
-
volatile sig_atomic_t signum;
typedef struct {
@@ -31,20 +25,16 @@ typedef struct {
void (*func)(void);
} Sigmap;
-static void dispatchcmd(int);
-static void sigfifo(void);
static void sigreap(void);
static void sigreboot(void);
static void spawn(const Arg *);
static Sigmap dispatchsig[] = {
- { SIGHUP, sigfifo },
{ SIGCHLD, sigreap },
{ SIGINT, sigreboot },
};
static int sigfd = -1;
-static int fifofd = -1;
#include "config.h"
@@ -53,7 +43,8 @@ main(void)
{
struct signalfd_siginfo siginfo;
sigset_t sigset;
- int maxfd, i, ret;
+ int i;
+ int ret;
ssize_t n;
fd_set rfds;
@@ -75,13 +66,7 @@ main(void)
while (1) {
FD_ZERO(&rfds);
FD_SET(sigfd, &rfds);
- maxfd = sigfd;
- if (fifofd != -1) {
- FD_SET(fifofd, &rfds);
- if (fifofd > maxfd)
- maxfd = fifofd;
- }
- ret = select(maxfd + 1, &rfds, NULL, NULL, NULL);
+ ret = select(sigfd + 1, &rfds, NULL, NULL, NULL);
if (ret < 0)
eprintf("sinit: select:");
if (ret > 0) {
@@ -93,9 +78,6 @@ main(void)
if (dispatchsig[i].sig == siginfo.ssi_signo)
dispatchsig[i].func();
}
- if (fifofd != -1)
- if (FD_ISSET(fifofd, &rfds))
- dispatchcmd(fifofd);
}
}
@@ -103,44 +85,6 @@ main(void)
}
static void
-dispatchcmd(int fd)
-{
- int i;
- char buf[BUFSIZ], *p;
- ssize_t n;
-
- n = read(fd, buf, sizeof(buf) - 1);
- if (n < 0)
- weprintf("sinit: read:");
- buf[n] = '\0';
- p = strchr(buf, '\n');
- if (p)
- *p = '\0';
- for (i = 0; i < LEN(commands); i++) {
- if (strcmp(commands[i].name, buf) == 0) {
- commands[i].func(&commands[i].arg);
- break;
- }
- }
-}
-
-static void
-sigfifo(void)
-{
- if (!fifopath)
- return;
- if (fifofd != -1)
- close(fifofd);
- unlink(fifopath);
- umask(0);
- if (mkfifo(fifopath, 0600) < 0)
- weprintf("sinit: mkfifo %s:", fifopath);
- fifofd = open(fifopath, O_RDWR | O_NONBLOCK);
- if (fifofd < 0)
- weprintf("sinit: open %s:", fifopath);
-}
-
-static void
sigreap(void)
{
while (waitpid(-1, NULL, WNOHANG) > 0)