diff --git a/configs/f2b.conf.in b/configs/f2b.conf.in index 7eb54b0..d479894 100644 --- a/configs/f2b.conf.in +++ b/configs/f2b.conf.in @@ -8,6 +8,8 @@ logfile = /var/log/f2b.log user = root group = root daemon = yes +coredumps = no +nice = 0 [defaults] state = no diff --git a/src/appconfig.c b/src/appconfig.c index d20d721..6277c42 100644 --- a/src/appconfig.c +++ b/src/appconfig.c @@ -10,9 +10,11 @@ #include "appconfig.h" f2b_appconfig_t appconfig = { + .coredumps = false, .daemon = false, .uid = 0, .gid = 0, + .nice = 0, .logdest = "file", .config_path = "/etc/f2b/f2b.conf", .logfile_path = "/var/log/f2b.log", @@ -38,11 +40,18 @@ f2b_appconfig_update(f2b_config_section_t *section) { if ((grp = getgrnam(pa->value)) != NULL) appconfig.gid = grp->gr_gid; } + if ((pa = f2b_config_param_find(section->param, "nice")) != NULL) { + appconfig.nice = atoi(pa->value); + } if ((pa = f2b_config_param_find(section->param, "daemon")) != NULL) { appconfig.daemon = (strcmp(pa->value, "yes") == 0) ? true : false; } + if ((pa = f2b_config_param_find(section->param, "coredumps")) != NULL) { + appconfig.coredumps = (strcmp(pa->value, "yes") == 0) ? true : false; + } + if ((pa = f2b_config_param_find(section->param, "pidfile")) != NULL) strlcpy(appconfig.pidfile_path, pa->value, sizeof(appconfig.pidfile_path)); diff --git a/src/appconfig.h b/src/appconfig.h index 9967bb1..6b128b0 100644 --- a/src/appconfig.h +++ b/src/appconfig.h @@ -12,6 +12,8 @@ typedef struct f2b_appconfig_t { bool daemon; + bool coredumps; + int nice; uid_t uid; gid_t gid; char logdest[CONFIG_KEY_MAX]; diff --git a/src/daemon.c b/src/daemon.c index a4d077e..7f79582 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -5,6 +5,11 @@ * published by the Free Software Foundation. */ #include "common.h" + +#include +#include +#include + #include "ipaddr.h" #include "config.h" #include "jail.h" @@ -14,9 +19,6 @@ #include "commands.h" #include "csocket.h" -#include -#include - /** * @def SA_REGISTER * Register signal handler @@ -272,6 +274,22 @@ int main(int argc, char *argv[]) { } } + if (appconfig.nice != 0) { + errno = 0; + nice(appconfig.nice); + if (errno) + f2b_log_msg(log_warn, "can't set process priority: %s", strerror(errno)); + } + + if (appconfig.coredumps) { + struct rlimit rl; + if (getrlimit(RLIMIT_CORE, &rl) < 0) + f2b_log_msg(log_error, "can't get current coresize limit"); + rl.rlim_cur = rl.rlim_max; + if (setrlimit(RLIMIT_CORE, &rl) < 0) + f2b_log_msg(log_error, "can't get current coresize limit"); + } + if (appconfig.pidfile_path[0] != '\0') { FILE *pidfile = NULL; if ((pidfile = fopen(appconfig.pidfile_path, "w")) != NULL) {