degesch: periodically flush logs to disk
This commit is contained in:
parent
94d495fbfa
commit
4471e0c6cd
21
degesch.c
21
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
|
||||
|
@ -8498,6 +8500,20 @@ on_tty_readable (const struct pollfd *fd, struct app_context *ctx)
|
|||
input_on_readable (&ctx->input);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
|
@ -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 ------------------------------------------------------------
|
||||
|
|
Loading…
Reference in New Issue