commit 7604819: [Minor] Switch to buffered IO
Vsevolod Stakhov
vsevolod at highsecure.ru
Mon Oct 19 11:42:08 UTC 2020
Author: Vsevolod Stakhov
Date: 2020-10-19 12:36:30 +0100
URL: https://github.com/rspamd/rspamd/commit/7604819ab9e65d0177ab35888c49ec791b98b649 (HEAD -> master)
[Minor] Switch to buffered IO
---
src/libserver/roll_history.c | 6 ++++--
src/libserver/worker_util.c | 6 ++++--
2 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/src/libserver/roll_history.c b/src/libserver/roll_history.c
index 8f50de693..a8c1c42a9 100644
--- a/src/libserver/roll_history.c
+++ b/src/libserver/roll_history.c
@@ -367,6 +367,7 @@ gboolean
rspamd_roll_history_save (struct roll_history *history, const gchar *filename)
{
gint fd;
+ FILE *fp;
ucl_object_t *obj, *elt;
guint i;
struct roll_history_row *row;
@@ -383,6 +384,7 @@ rspamd_roll_history_save (struct roll_history *history, const gchar *filename)
return FALSE;
}
+ fp = fdopen (fd, "w");
obj = ucl_object_typed_new (UCL_ARRAY);
for (i = 0; i < history->nrows; i ++) {
@@ -418,12 +420,12 @@ rspamd_roll_history_save (struct roll_history *history, const gchar *filename)
ucl_array_append (obj, elt);
}
- emitter_func = ucl_object_emit_fd_funcs (fd);
+ emitter_func = ucl_object_emit_file_funcs (fp);
ucl_object_emit_full (obj, UCL_EMIT_JSON_COMPACT, emitter_func, NULL);
ucl_object_emit_funcs_free (emitter_func);
ucl_object_unref (obj);
- close (fd);
+ fclose (fp);
return TRUE;
}
diff --git a/src/libserver/worker_util.c b/src/libserver/worker_util.c
index 5ebae998c..71bbe4860 100644
--- a/src/libserver/worker_util.c
+++ b/src/libserver/worker_util.c
@@ -1916,6 +1916,7 @@ rspamd_controller_store_saved_stats (struct rspamd_main *rspamd_main,
ucl_object_t *top, *sub;
struct ucl_emitter_functions *efuncs;
gint i, fd;
+ FILE *fp;
gchar fpath[PATH_MAX];
if (cfg->stats_file == NULL) {
@@ -1931,6 +1932,7 @@ rspamd_controller_store_saved_stats (struct rspamd_main *rspamd_main,
return;
}
+ fp = fdopen (fd, "w");
stat = rspamd_main->stat;
top = ucl_object_typed_new (UCL_OBJECT);
@@ -1956,7 +1958,7 @@ rspamd_controller_store_saved_stats (struct rspamd_main *rspamd_main,
ucl_object_fromint (stat->control_connections_count),
"control_connections", 0, false);
- efuncs = ucl_object_emit_fd_funcs (fd);
+ efuncs = ucl_object_emit_file_funcs (fp);
if (!ucl_object_emit_full (top, UCL_EMIT_JSON_COMPACT,
efuncs, NULL)) {
msg_err_config ("cannot write stats to %s: %s",
@@ -1972,7 +1974,7 @@ rspamd_controller_store_saved_stats (struct rspamd_main *rspamd_main,
}
ucl_object_unref (top);
- close (fd);
+ fclose (fp);
ucl_object_emit_funcs_free (efuncs);
}
More information about the Commits
mailing list