mirror of
https://github.com/troglobit/finit.git
synced 2026-10-17 10:49:34 +00:00
Add support for toggling the debug mode at runtime
This commit adds support for -d, --debug option to init, which can be used to toggle the finit debug mode at runtime. Signed-off-by: Mattias Walström <lazzer@gmail.com> Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
1 parent
c3b76fdccf
commit
5d04a72a61
3 files changed
+45
-8
No files matched your search
@@ -26,6 +26,7 @@
|
||||
#include <ctype.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h> /* umask(), mkdir() */
|
||||
#include <getopt.h>
|
||||
|
||||
#include "finit.h"
|
||||
#include "helpers.h"
|
||||
@@ -65,31 +66,63 @@ static void parse_kernel_cmdline(void)
|
||||
}
|
||||
}
|
||||
|
||||
static int usage(int rc)
|
||||
{
|
||||
fprintf(stderr, "Usage: %s [OPTIONS] [RUNLEVEL]\n\n"
|
||||
" -d, --debug Enable/Disable debug\n"
|
||||
" -h, --help This help text\n\n", __progname);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
static int client(int argc, char *argv[])
|
||||
{
|
||||
int fd;
|
||||
int c;
|
||||
struct option long_options[] = {
|
||||
{"debug", 0, NULL, 'd'},
|
||||
{"help", 0, NULL, 'h'},
|
||||
{NULL, 0, NULL, 0}
|
||||
};
|
||||
struct init_request rq = {
|
||||
.magic = INIT_MAGIC,
|
||||
.cmd = INIT_CMD_RUNLVL,
|
||||
.cmd = 0
|
||||
};
|
||||
|
||||
while ((c = getopt_long (argc, argv, "h?d", long_options, NULL)) != EOF) {
|
||||
switch(c) {
|
||||
case 'd':
|
||||
rq.cmd = INIT_CMD_DEBUG;
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
case '?':
|
||||
return usage(0);
|
||||
default:
|
||||
return usage(1);
|
||||
}
|
||||
}
|
||||
|
||||
if (!rq.cmd) {
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Missing runlevel.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
rq.cmd = INIT_CMD_RUNLVL;
|
||||
rq.runlevel = (int)argv[1][0];
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Reference in new issue
Block a user