Browse Source

* add 'log level <level>' command

* change 'rotate' command to 'log rotate' for consistency
master
Alex 'AdUser' Z 8 years ago
parent
commit
835016140d
  1. 20
      src/commands.c
  2. 3
      src/commands.h
  3. 4
      src/daemon.c

20
src/commands.c

@ -38,9 +38,9 @@ struct f2b_cmd_t {
.tokens = { "status", NULL }, .tokens = { "status", NULL },
.help = "Show general stats and jails list", .help = "Show general stats and jails list",
}, },
[CMD_ROTATE] = { [CMD_LOG_ROTATE] = {
.argc = 0, .tokenc = 1, .argc = 0, .tokenc = 2,
.tokens = { "rotate", NULL }, .tokens = { "log", "rotate", NULL },
.help = "Reopen daemon's own log file", .help = "Reopen daemon's own log file",
}, },
[CMD_RELOAD] = { [CMD_RELOAD] = {
@ -53,6 +53,11 @@ struct f2b_cmd_t {
.tokens = { "shutdown", NULL }, .tokens = { "shutdown", NULL },
.help = "Gracefully terminate f2b daemon", .help = "Gracefully terminate f2b daemon",
}, },
[CMD_LOG_LEVEL] = {
.argc = 1, .tokenc = 3,
.tokens = { "log", "level", "<level>", NULL },
.help = "Change maximum level of logged messages",
},
[CMD_JAIL_STATUS] = { [CMD_JAIL_STATUS] = {
.argc = 1, .tokenc = 3, .argc = 1, .tokenc = 3,
.tokens = { "jail", "<jailname>", "status", NULL }, .tokens = { "jail", "<jailname>", "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; } if (strcmp(line, "ping") == 0) { return CMD_PING; }
else if (strcmp(line, "help") == 0) { return CMD_HELP; } else if (strcmp(line, "help") == 0) { return CMD_HELP; }
else if (strcmp(line, "status") == 0) { return CMD_STATUS; } 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, "reload") == 0) { return CMD_RELOAD; }
else if (strcmp(line, "shutdown") == 0) { return CMD_SHUTDOWN; } 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) { if (tokenc == 4 && strcmp(tokens[2], "filter") == 0 && strcmp(tokens[3], "reload") == 0) {
return CMD_JAIL_FILTER_RELOAD; 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; return CMD_NONE;

3
src/commands.h

@ -28,9 +28,10 @@ enum f2b_cmd_type {
CMD_HELP, /**< show help for commands (used internally by client) */ CMD_HELP, /**< show help for commands (used internally by client) */
CMD_PING = 8, /**< check connection */ CMD_PING = 8, /**< check connection */
CMD_STATUS, /**< show general status of f2b daemon */ 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_RELOAD, /**< reload all jails */
CMD_SHUTDOWN, /**< gracefull shutdown */ CMD_SHUTDOWN, /**< gracefull shutdown */
CMD_LOG_LEVEL, /**< change maximum level of logged messages */
/* jail commands */ /* jail commands */
CMD_JAIL_STATUS = 16, /**< show status of given jail */ CMD_JAIL_STATUS = 16, /**< show status of given jail */
CMD_JAIL_SET, /**< set parameter of given jail */ CMD_JAIL_SET, /**< set parameter of given jail */

4
src/daemon.c

@ -95,8 +95,10 @@ f2b_cmsg_process(const f2b_cmsg_t *msg, char *res, size_t ressize) {
/* nothing to do */ /* nothing to do */
} else if (msg->type == CMD_RELOAD) { } else if (msg->type == CMD_RELOAD) {
state = reconfig; state = reconfig;
} else if (msg->type == CMD_ROTATE) { } else if (msg->type == CMD_LOG_ROTATE) {
state = logrotate; state = logrotate;
} else if (msg->type == CMD_LOG_LEVEL) {
f2b_log_set_level(args[0]);
} else if (msg->type == CMD_SHUTDOWN) { } else if (msg->type == CMD_SHUTDOWN) {
state = stop; state = stop;
} else if (msg->type == CMD_STATUS) { } else if (msg->type == CMD_STATUS) {

Loading…
Cancel
Save