Compare commits

...

6 Commits

  1. 18
      CMakeLists.txt
  2. 1
      configs/f2b.conf.in
  3. 6
      debian/changelog
  4. 1
      docs/install.md
  5. 14
      src/log.c
  6. 2
      src/log.h
  7. 3
      src/sources/files.c

18
CMakeLists.txt

@ -1,8 +1,9 @@
cmake_minimum_required(VERSION 3.4)
set(CNAME "f2b") set(CNAME "f2b")
set(VERSION "0.6") set(VERSION "0.6.1")
project(${CNAME} C) project(${CNAME} C)
cmake_minimum_required(VERSION 2.6)
include(CTest) include(CTest)
@ -16,14 +17,11 @@ option(WITH_PCRE "Build pcre-compatible filter" ON)
option(WITH_REDIS "Build redis source/backend" OFF) option(WITH_REDIS "Build redis source/backend" OFF)
option(WITH_IPSET "Build native ipset backend" OFF) option(WITH_IPSET "Build native ipset backend" OFF)
set(INIT_SCRIPT "OFF") # valid variants: "off", "sysvinit", "openrc", "systemd"
if (NOT DEFINED CMAKE_INSTALL_PREFIX) if (NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/usr") set(CMAKE_INSTALL_PREFIX "/usr")
endif () endif ()
# HACK: cmake >= 3.4 fixes this
if (CMAKE_INSTALL_PREFIX MATCHES "^/usr/?$")
set(CMAKE_INSTALL_SYSCONFDIR "/etc")
set(CMAKE_INSTALL_LOCALSTATEDIR "/var")
endif ()
include(GNUInstallDirs) include(GNUInstallDirs)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c99") set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -pedantic -std=c99")
@ -80,6 +78,12 @@ install(DIRECTORY "configs/" DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/${CNAM
install(FILES "configs/f2b.conf" DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/${CNAME}" install(FILES "configs/f2b.conf" DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/${CNAME}"
RENAME "f2b.conf.sample") RENAME "f2b.conf.sample")
if (INIT_SCRIPT STREQUAL "openrc")
install(FILES "contrib/init.openrc" DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/init.d" RENAME "f2b")
elseif (INIT_SCRIPT STREQUAL "systemd")
install(FILES "contrib/f2b.service" DESTINATION "${CMAKE_INSTALL_FULL_LIBDIR}/systemd/system")
endif ()
add_custom_target("dist" COMMAND add_custom_target("dist" COMMAND
"git" "archive" "--format=tar.gz" "git" "archive" "--format=tar.gz"
"--output=${CNAME}_v${VERSION}.tar.gz" "--output=${CNAME}_v${VERSION}.tar.gz"

1
configs/f2b.conf.in

@ -2,6 +2,7 @@
includes = ${CMAKE_INSTALL_FULL_SYSCONFDIR}/f2b/conf-enabled includes = ${CMAKE_INSTALL_FULL_SYSCONFDIR}/f2b/conf-enabled
pidfile = /var/run/f2b.pid pidfile = /var/run/f2b.pid
statedir = ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/f2b statedir = ${CMAKE_INSTALL_FULL_LOCALSTATEDIR}/lib/f2b
; valid destinations: stdout, stderr, syslog, file (logfile option should be set)
logdest = syslog logdest = syslog
loglevel = info loglevel = info
logfile = /var/log/f2b.log logfile = /var/log/f2b.log

6
debian/changelog vendored

@ -1,3 +1,9 @@
f2b (0.6.1-1) unstable; urgency=medium
* bugfix version
-- Alex 'AdUser' Z <ad_user@runbox.com> Tue, 04 Jun 2024 09:48:18 +1000
f2b (0.6-1) unstable; urgency=medium f2b (0.6-1) unstable; urgency=medium
* new version * new version

1
docs/install.md

@ -25,6 +25,7 @@ Other noticeable options are:
* `CMAKE_BUILD_TYPE` (Debug, Release or unset) -- sets compiler optimization level and debugging info. Set to "Release" for production code. * `CMAKE_BUILD_TYPE` (Debug, Release or unset) -- sets compiler optimization level and debugging info. Set to "Release" for production code.
* `CMAKE_C_COMPILER` -- allows specify another compiler * `CMAKE_C_COMPILER` -- allows specify another compiler
* `CMAKE_INSTALL_PREFIX` -- set root of install dir ($DESTDIR also will be prefixed if set). * `CMAKE_INSTALL_PREFIX` -- set root of install dir ($DESTDIR also will be prefixed if set).
* `INIT_SCRIPT` -- install system init script (values: off/openrc/systemd, default: off)
After building you may type `sudo make install` to install compiled binaries and other files. After building you may type `sudo make install` to install compiled binaries and other files.
Default install layout is: Default install layout is:

14
src/log.c

@ -10,7 +10,12 @@
#include <sys/syslog.h> #include <sys/syslog.h>
static log_msgtype_t minlevel = log_info; static log_msgtype_t minlevel = log_info;
static enum { log_stderr = 0, log_file = 1, log_syslog = 2 } dest = log_stderr; static enum {
log_stderr = 0,
log_stdout = 1,
log_file = 2,
log_syslog = 3
} dest = log_stderr;
static FILE *logfile = NULL; static FILE *logfile = NULL;
static const char *loglevels[] = { static const char *loglevels[] = {
@ -79,6 +84,13 @@ void f2b_log_set_level(const char *level) {
if (strcmp(level, "fatal") == 0) { minlevel = log_fatal; return; } if (strcmp(level, "fatal") == 0) { minlevel = log_fatal; return; }
} }
void f2b_log_to_stdout() {
if (logfile && logfile != stdout)
fclose(logfile);
dest = log_stdout;
logfile = stdout;
}
void f2b_log_to_stderr() { void f2b_log_to_stderr() {
if (logfile && logfile != stderr) if (logfile && logfile != stderr)
fclose(logfile); fclose(logfile);

2
src/log.h

@ -52,6 +52,8 @@ void f2b_log_set_level(const char *level);
* @param path Path for logfile * @param path Path for logfile
*/ */
void f2b_log_to_file (const char *path); void f2b_log_to_file (const char *path);
/** @brief Use logging to stdout */
void f2b_log_to_stdout();
/** @brief Use logging to stderr */ /** @brief Use logging to stderr */
void f2b_log_to_stderr(); void f2b_log_to_stderr();
/** @brief Use logging to syslog */ /** @brief Use logging to syslog */

3
src/sources/files.c

@ -215,7 +215,8 @@ next(cfg_t *cfg, char *buf, size_t bufsize, bool reset) {
for (f2b_file_t *file = cfg->current; file != NULL; file = file->next) { for (f2b_file_t *file = cfg->current; file != NULL; file = file->next) {
if (file_rotated(cfg, file)) if (file_rotated(cfg, file))
file_close(file); file_close(file);
if (file->fd == NULL && !file_open(file, NULL)) { if (file->fd == NULL) {
if (!file_open(file, NULL))
log_msg(cfg, error, "can't open file: %s", file->path); log_msg(cfg, error, "can't open file: %s", file->path);
continue; continue;
} }

Loading…
Cancel
Save