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:
Mattias Walström
2013-05-19 19:01:44 +02:00
committed by Joachim Nilsson
parent c3b76fdccf
commit 5d04a72a61
3 changed files with 45 additions and 8 deletions
+41 -8
View File
@@ -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);
+2
View File
@@ -64,6 +64,7 @@
#define INIT_MAGIC 0x03091969
#define INIT_CMD_RUNLVL 1
#define INIT_CMD_DEBUG 2
struct init_request {
int magic; /* Magic number */
@@ -81,6 +82,7 @@ extern char *hostname;
extern char *username;
extern char *rcsd;
extern char *console;
extern char *__progname;
/* conf.c */
void parse_finit_conf(char *file);
+2
View File
@@ -107,6 +107,8 @@ static void parse(void *UNUSED(arg), int fd, int UNUSED(events))
_d("Unsupported runlevel: %d", rq.runlevel);
break;
}
} else if (rq.cmd == INIT_CMD_DEBUG) {
debug = !debug;
} else {
_d("Unsupported cmd: %d", rq.cmd);
}