Add basic support for runlevels and bugfix FIFO I/O plugins

Like most other init implementations do, when entering runlevel 1, finit
creates the file /etc/nologin to prevent users from logging in during
single-user mode, this file is then removed upon leaving runlevel 1.

Also, bugfix how FIFO I/O plugins are handled in finit.  A FIFO will
need to be reopened by the server side when the client closes the pipe.

Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Joachim Nilsson committed 2013-05-19 19:01:44 +02:00
1 parent ec95243dad
commit c3b76fdccf
7 files changed
+237 -57

No files matched your search

+45 -9
View File
@@ -35,14 +35,16 @@
#include "sig.h"
#include "lite.h"
int debug = 0;
int verbose = 1;
char *sdown = NULL;
char *network = NULL;
char *username = NULL;
char *hostname = NULL;
char *rcsd = NULL;
char *console = NULL;
int debug = 0;
int verbose = 1;
int runlevel = 3;
int prevlevel = 1;
char *sdown = NULL;
char *network = NULL;
char *username = NULL;
char *hostname = NULL;
char *rcsd = NULL;
char *console = NULL;
static void parse_kernel_cmdline(void)
{
@@ -63,6 +65,37 @@ static void parse_kernel_cmdline(void)
}
}
static int client(int argc, char *argv[])
{
int fd;
struct init_request rq = {
.magic = INIT_MAGIC,
.cmd = INIT_CMD_RUNLVL,
};
if (!fexist(FINIT_FIFO)) {
fprintf(stderr, "/sbin/init does not support %s!\n", FINIT_FIFO);
return 1;
}
if (argc < 2) {
fprintf(stderr, "Missing argument.\n");
return 1;
}
fd = open(FINIT_FIFO, O_WRONLY);
if (-1 == fd) {
perror("Failed opening " FINIT_FIFO);
return 1;
}
rq.runlevel = (int)argv[1][0];
write(fd, &rq, sizeof(rq));
close(fd);
return 0;
}
static int run_loop(void)
{
while (1) {
@@ -82,8 +115,11 @@ static void banner(void)
#endif
}
int main(int UNUSED(args), char* UNUSED(argv[]))
int main(int argc, char* argv[])
{
if (getpid() != 1)
return client(argc, argv);
/*
* Initial setup of signals, ignore all until we're up.
*/