Skip to content

Commit

Permalink
lib: Move failure handler structs and typedefs to failures-private.h
Browse files Browse the repository at this point in the history
Also change the function typedefs to be non-pointers, like they usually are
in Dovecot code.
  • Loading branch information
sirainen authored and villesavolainen committed Sep 7, 2018
1 parent 4576851 commit 7ebce77
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/lib/Makefile.am
Expand Up @@ -191,6 +191,7 @@ headers = \
event-log.h \
execv-const.h \
failures.h \
failures-private.h \
fd-util.h \
fdatasync-path.h \
fdpass.h \
Expand Down
26 changes: 26 additions & 0 deletions src/lib/failures-private.h
@@ -0,0 +1,26 @@
#ifndef FAILURES_PRIVATE_H
#define FAILURES_PRIVATE_H

typedef int
failure_write_to_file_t(enum log_type type, string_t *data, size_t prefix_len);
typedef string_t *
failure_format_str_t(const struct failure_context *ctx, size_t *prefix_len_r,
const char *format, va_list args);
typedef void failure_on_handler_failure_t(const struct failure_context *ctx);
typedef void failure_post_handler_t(const struct failure_context *ctx);

struct failure_handler_vfuncs {
failure_write_to_file_t *write;
failure_format_str_t *format;
failure_on_handler_failure_t *on_handler_failure;
failure_post_handler_t *post_handler;
};

struct failure_handler_config {
int fatal_err_reset;
struct failure_handler_vfuncs *v;
};

extern struct failure_handler_config failure_handler;

#endif
20 changes: 1 addition & 19 deletions src/lib/failures.c
Expand Up @@ -10,6 +10,7 @@
#include "backtrace-string.h"
#include "printf-format-fix.h"
#include "write-full.h"
#include "failures-private.h"

#include <unistd.h>
#include <fcntl.h>
Expand Down Expand Up @@ -60,13 +61,6 @@ static void log_prefix_add(const struct failure_context *ctx, string_t *str);
static void i_failure_send_option(const char *key, const char *value);
static int internal_send_split(string_t *full_str, size_t prefix_len);

typedef int (*failure_write_to_file_t)(enum log_type type, string_t *data, size_t prefix_len);
typedef string_t *(*failure_format_str_t)(const struct failure_context *ctx,
size_t *prefix_len_r, const char *format,
va_list args);
typedef void (*failure_on_handler_failure_t)(const struct failure_context *ctx);
typedef void (*failure_post_handler_t)(const struct failure_context *ctx);

static string_t * ATTR_FORMAT(3, 0) default_format(const struct failure_context *ctx,
size_t *prefix_len_r ATTR_UNUSED,
const char *format,
Expand Down Expand Up @@ -223,18 +217,6 @@ static void internal_post_handler(const struct failure_context *ctx ATTR_UNUSED)
{
}

struct failure_handler_vfuncs {
failure_write_to_file_t write;
failure_format_str_t format;
failure_on_handler_failure_t on_handler_failure;
failure_post_handler_t post_handler;
};

struct failure_handler_config {
int fatal_err_reset;
struct failure_handler_vfuncs *v;
};

static struct failure_handler_vfuncs default_handler_vfuncs = {
.write = &default_write,
.format = &default_format,
Expand Down

0 comments on commit 7ebce77

Please sign in to comment.