diff --git a/src/commands.c b/src/commands.c index 9959cd4..62eb6f5 100644 --- a/src/commands.c +++ b/src/commands.c @@ -38,9 +38,9 @@ struct f2b_cmd_t { .tokens = { "status", NULL }, .help = "Show general stats and jails list", }, - [CMD_ROTATE] = { - .argc = 0, .tokenc = 1, - .tokens = { "rotate", NULL }, + [CMD_LOG_ROTATE] = { + .argc = 0, .tokenc = 2, + .tokens = { "log", "rotate", NULL }, .help = "Reopen daemon's own log file", }, [CMD_RELOAD] = { @@ -53,6 +53,11 @@ struct f2b_cmd_t { .tokens = { "shutdown", NULL }, .help = "Gracefully terminate f2b daemon", }, + [CMD_LOG_LEVEL] = { + .argc = 1, .tokenc = 3, + .tokens = { "log", "level", "", NULL }, + .help = "Change maximum level of logged messages", + }, [CMD_JAIL_STATUS] = { .argc = 1, .tokenc = 3, .tokens = { "jail", "", "status", NULL }, @@ -146,7 +151,6 @@ f2b_cmd_parse(char *buf, size_t bufsize, const char *src) { if (strcmp(line, "ping") == 0) { return CMD_PING; } else if (strcmp(line, "help") == 0) { return CMD_HELP; } else if (strcmp(line, "status") == 0) { return CMD_STATUS; } - else if (strcmp(line, "rotate") == 0) { return CMD_ROTATE; } else if (strcmp(line, "reload") == 0) { return CMD_RELOAD; } else if (strcmp(line, "shutdown") == 0) { return CMD_SHUTDOWN; } @@ -190,6 +194,14 @@ f2b_cmd_parse(char *buf, size_t bufsize, const char *src) { if (tokenc == 4 && strcmp(tokens[2], "filter") == 0 && strcmp(tokens[3], "reload") == 0) { return CMD_JAIL_FILTER_RELOAD; } + } else if (strcmp(line, "log") == 0 && tokenc > 1) { + if (tokenc == 2 && strcmp(tokens[1], "rotate") == 0) { + return CMD_LOG_ROTATE; + } + if (tokenc == 3 && strcmp(tokens[1], "level") == 0) { + f2b_cmd_append_arg(buf, bufsize, tokens[2]); + return CMD_LOG_LEVEL; + } } return CMD_NONE; diff --git a/src/commands.h b/src/commands.h index fe1b0df..cc00bd7 100644 --- a/src/commands.h +++ b/src/commands.h @@ -28,9 +28,10 @@ enum f2b_cmd_type { CMD_HELP, /**< show help for commands (used internally by client) */ CMD_PING = 8, /**< check connection */ CMD_STATUS, /**< show general status of f2b daemon */ - CMD_ROTATE, /**< reopen logfile. works only if set `logdest = file` */ + CMD_LOG_ROTATE,/**< reopen logfile. works only if set `logdest = file` */ CMD_RELOAD, /**< reload all jails */ CMD_SHUTDOWN, /**< gracefull shutdown */ + CMD_LOG_LEVEL, /**< change maximum level of logged messages */ /* jail commands */ CMD_JAIL_STATUS = 16, /**< show status of given jail */ CMD_JAIL_SET, /**< set parameter of given jail */ diff --git a/src/daemon.c b/src/daemon.c index 397a2e9..6597658 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -95,8 +95,10 @@ f2b_cmsg_process(const f2b_cmsg_t *msg, char *res, size_t ressize) { /* nothing to do */ } else if (msg->type == CMD_RELOAD) { state = reconfig; - } else if (msg->type == CMD_ROTATE) { + } else if (msg->type == CMD_LOG_ROTATE) { state = logrotate; + } else if (msg->type == CMD_LOG_LEVEL) { + f2b_log_set_level(args[0]); } else if (msg->type == CMD_SHUTDOWN) { state = stop; } else if (msg->type == CMD_STATUS) {