Add wrappers to reduce #ifdefs.

Signed-off-by: Edward Tomasz Napierala <trasz@FreeBSD.org>
This commit is contained in:
Edward Tomasz Napierala 2017-07-29 12:28:49 +01:00
commit 12e2c46d6a
5 changed files with 37 additions and 55 deletions

View file

@ -27,25 +27,13 @@
#include "misc.h"
#include "write-buffer.h"
#include "settings.h"
#ifdef HAVE_CAPSICUM
#include "capsicum.h"
#endif
#include "servers.h"
static int rawlog_lines;
static int signal_rawlog;
static int rawlog_open_wrapper(const char *path, int flags, int mode)
{
#ifdef HAVE_CAPSICUM
if (capsicum_enabled())
return capsicum_open(path, flags, mode);
#endif
return open(path, flags, mode);
}
RAWLOG_REC *rawlog_create(void)
{
RAWLOG_REC *rec;
@ -139,8 +127,9 @@ void rawlog_open(RAWLOG_REC *rawlog, const char *fname)
return;
path = convert_home(fname);
rawlog->handle = rawlog_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
rawlog->handle = capsicum_open_wrapper(path,
O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
g_free(path);
if (rawlog->handle == -1) {
@ -167,18 +156,12 @@ void rawlog_save(RAWLOG_REC *rawlog, const char *fname)
int f;
dir = g_path_get_dirname(fname);
#ifdef HAVE_CAPSICUM
if (capsicum_enabled())
capsicum_mkdir_with_parents(dir, log_dir_create_mode);
else
g_mkdir_with_parents(dir, log_dir_create_mode);
#else
g_mkdir_with_parents(dir, log_dir_create_mode);
#endif
capsicum_mkdir_with_parents_wrapper(dir, log_dir_create_mode);
g_free(dir);
path = convert_home(fname);
f = rawlog_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT, log_file_create_mode);
f = capsicum_open_wrapper(path, O_WRONLY | O_APPEND | O_CREAT,
log_file_create_mode);
g_free(path);
if (f < 0) {