aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2015-07-04 15:43:45 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2015-07-04 15:45:27 +0200
commit4471e0c6cdba55e554e5c4ae4cd620afea2dc1f8 (patch)
treec350696e363617dbe5078e6e3cd9d7ea0abfb39c
parent94d495fbfa22acec500a8a0ef9dfcc5353def479 (diff)
downloadxK-4471e0c6cdba55e554e5c4ae4cd620afea2dc1f8.tar.gz
xK-4471e0c6cdba55e554e5c4ae4cd620afea2dc1f8.tar.xz
xK-4471e0c6cdba55e554e5c4ae4cd620afea2dc1f8.zip
degesch: periodically flush logs to disk
-rw-r--r--degesch.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/degesch.c b/degesch.c
index 193b898..d5ae36a 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1302,6 +1302,8 @@ struct app_context
struct poller_fd tty_event; ///< Terminal input event
struct poller_fd signal_event; ///< Signal FD event
+ struct poller_timer flush_timer; ///< Flush all open files (e.g. logs)
+
struct poller poller; ///< Manages polled descriptors
bool quitting; ///< User requested quitting
bool polling; ///< The event loop is running
@@ -8499,6 +8501,20 @@ on_tty_readable (const struct pollfd *fd, struct app_context *ctx)
}
static void
+rearm_flush_timer (struct app_context *ctx)
+{
+ poller_timer_set (&ctx->flush_timer, 60 * 1000);
+}
+
+static void
+on_flush_timer (struct app_context *ctx)
+{
+ // I guess we don't need to do anything more complicated
+ fflush (NULL);
+ rearm_flush_timer (ctx);
+}
+
+static void
init_poller_events (struct app_context *ctx)
{
poller_fd_init (&ctx->signal_event, &ctx->poller, g_signal_pipe[0]);
@@ -8510,6 +8526,11 @@ init_poller_events (struct app_context *ctx)
ctx->tty_event.dispatcher = (poller_fd_fn) on_tty_readable;
ctx->tty_event.user_data = ctx;
poller_fd_set (&ctx->tty_event, POLLIN);
+
+ poller_timer_init (&ctx->flush_timer, &ctx->poller);
+ ctx->flush_timer.dispatcher = (poller_timer_fn) on_flush_timer;
+ ctx->flush_timer.user_data = ctx;
+ rearm_flush_timer (ctx);
}
// --- Main program ------------------------------------------------------------