Skip to content

Commit

Permalink
linelog: Add option to fsync on every write
Browse files Browse the repository at this point in the history
  • Loading branch information
arr2036 committed Oct 1, 2024
1 parent 4312a2d commit b20a8d0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
8 changes: 8 additions & 0 deletions raddb/mods-available/linelog
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ linelog {
# a limited range should set this to `yes`.
#
escape_filenames = no

#
# fsync::
#
# Synchronise data written with the file system after every
# write, returning fail when the operation fails.
#
fsync = no
}

#
Expand Down
7 changes: 7 additions & 0 deletions src/modules/rlm_linelog/rlm_linelog.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ typedef struct {
gid_t group; //!< Resolved gid.
exfile_t *ef; //!< Exclusive file access handle.
bool escape; //!< Do filename escaping, yes / no.
bool fsync; //!< fsync after each write.
} file;

struct {
Expand All @@ -143,6 +144,7 @@ static const conf_parser_t file_config[] = {
{ FR_CONF_OFFSET("permissions", rlm_linelog_t, file.permissions), .dflt = "0600" },
{ FR_CONF_OFFSET("group", rlm_linelog_t, file.group_str) },
{ FR_CONF_OFFSET("escape_filenames", rlm_linelog_t, file.escape), .dflt = "no" },
{ FR_CONF_OFFSET("fsync", rlm_linelog_t, file.fsync), .dflt = "no" },
CONF_PARSER_TERMINATOR
};

Expand Down Expand Up @@ -436,6 +438,11 @@ static int linelog_write(rlm_linelog_t const *inst, linelog_call_env_t const *ca

return -1;
}
if (inst->file.fsync && (fsync(fd) < 0)) {
RERROR("Failed syncing \"%pV\" to persistent storage: %s", call_env->filename, fr_syserror(errno));
exfile_close(inst->file.ef, fd);
return -1;
}
}

if (RDEBUG_ENABLED3) linelog_hexdump(request, vector_p, vector_len, "linelog data");
Expand Down

0 comments on commit b20a8d0

Please sign in to comment.