Browse Source

* new options for daemon: "coredumps" && "nice"

master
Alex 'AdUser' Z 3 years ago
parent
commit
7480e63795
  1. 2
      configs/f2b.conf.in
  2. 9
      src/appconfig.c
  3. 2
      src/appconfig.h
  4. 24
      src/daemon.c

2
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

9
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));

2
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];

24
src/daemon.c

@ -5,6 +5,11 @@
* published by the Free Software Foundation.
*/
#include "common.h"
#include <getopt.h>
#include <signal.h>
#include <sys/resource.h>
#include "ipaddr.h"
#include "config.h"
#include "jail.h"
@ -14,9 +19,6 @@
#include "commands.h"
#include "csocket.h"
#include <getopt.h>
#include <signal.h>
/**
* @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) {

Loading…
Cancel
Save