From 1c0c583216c3fd7dd638f504bc32d2cb0a7b2f95 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 21 Nov 2008 18:36:33 +0100 Subject: state_file: save state_file every 5 minutes When MPD quits in a non-clean way, the state file isn't written, and on the next start, MPD time warps to the previous clean shutdown. Save the state file every 5 minutes; this will probably be configurable at a later time. Note that we don't set a wakeup timer for that: when there is no MPD traffic, MPD won't wake up to save the state file. This minor bug is tolerated, because usually there is no change in MPD's state when the main thread is idle. --- src/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main.c b/src/main.c index a42655f68..6d752f5a2 100644 --- a/src/main.c +++ b/src/main.c @@ -383,6 +383,7 @@ int main(int argc, char *argv[]) { Options options; clock_t start; + GTimer *save_state_timer; #ifdef HAVE_LOCALE /* initialize locale */ @@ -446,6 +447,8 @@ int main(int argc, char *argv[]) player_create(); read_state_file(); + save_state_timer = g_timer_new(); + while (COMMAND_RETURN_KILL != client_manager_io() && COMMAND_RETURN_KILL != handlePendingSignals()) { unsigned flags; @@ -459,6 +462,12 @@ int main(int argc, char *argv[]) flags = idle_get(); if (flags != 0) client_manager_idle_add(flags); + + if (g_timer_elapsed(save_state_timer, NULL) >= 5 * 60) { + g_debug("Saving state file\n"); + write_state_file(); + g_timer_start(save_state_timer); + } } write_state_file(); -- cgit v1.2.3