mirror of
https://github.com/troglobit/finit.git
synced 2026-11-03 13:28:27 +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 <ctype.h>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <sys/stat.h> /* umask(), mkdir() */
|
#include <sys/stat.h> /* umask(), mkdir() */
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
#include "finit.h"
|
#include "finit.h"
|
||||||
#include "helpers.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[])
|
static int client(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int fd;
|
int fd;
|
||||||
|
int c;
|
||||||
|
struct option long_options[] = {
|
||||||
|
{"debug", 0, NULL, 'd'},
|
||||||
|
{"help", 0, NULL, 'h'},
|
||||||
|
{NULL, 0, NULL, 0}
|
||||||
|
};
|
||||||
struct init_request rq = {
|
struct init_request rq = {
|
||||||
.magic = INIT_MAGIC,
|
.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)) {
|
if (!fexist(FINIT_FIFO)) {
|
||||||
fprintf(stderr, "/sbin/init does not support %s!\n", FINIT_FIFO);
|
fprintf(stderr, "/sbin/init does not support %s!\n", FINIT_FIFO);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (argc < 2) {
|
|
||||||
fprintf(stderr, "Missing argument.\n");
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fd = open(FINIT_FIFO, O_WRONLY);
|
fd = open(FINIT_FIFO, O_WRONLY);
|
||||||
if (-1 == fd) {
|
if (-1 == fd) {
|
||||||
perror("Failed opening " FINIT_FIFO);
|
perror("Failed opening " FINIT_FIFO);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
rq.runlevel = (int)argv[1][0];
|
|
||||||
write(fd, &rq, sizeof(rq));
|
write(fd, &rq, sizeof(rq));
|
||||||
close(fd);
|
close(fd);
|
||||||
|
|
||||||
|
|||||||
@@ -64,6 +64,7 @@
|
|||||||
|
|
||||||
#define INIT_MAGIC 0x03091969
|
#define INIT_MAGIC 0x03091969
|
||||||
#define INIT_CMD_RUNLVL 1
|
#define INIT_CMD_RUNLVL 1
|
||||||
|
#define INIT_CMD_DEBUG 2
|
||||||
|
|
||||||
struct init_request {
|
struct init_request {
|
||||||
int magic; /* Magic number */
|
int magic; /* Magic number */
|
||||||
@@ -81,6 +82,7 @@ extern char *hostname;
|
|||||||
extern char *username;
|
extern char *username;
|
||||||
extern char *rcsd;
|
extern char *rcsd;
|
||||||
extern char *console;
|
extern char *console;
|
||||||
|
extern char *__progname;
|
||||||
|
|
||||||
/* conf.c */
|
/* conf.c */
|
||||||
void parse_finit_conf(char *file);
|
void parse_finit_conf(char *file);
|
||||||
|
|||||||
@@ -107,6 +107,8 @@ static void parse(void *UNUSED(arg), int fd, int UNUSED(events))
|
|||||||
_d("Unsupported runlevel: %d", rq.runlevel);
|
_d("Unsupported runlevel: %d", rq.runlevel);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
} else if (rq.cmd == INIT_CMD_DEBUG) {
|
||||||
|
debug = !debug;
|
||||||
} else {
|
} else {
|
||||||
_d("Unsupported cmd: %d", rq.cmd);
|
_d("Unsupported cmd: %d", rq.cmd);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user