From b9c99800f6556157a93333540ae24cbefb67bf49 Mon Sep 17 00:00:00 2001 From: Alon Levy Date: Mon, 30 Jan 2012 20:44:47 +0200 Subject: [PATCH 5/6] fix case where we stat the file after change by an external editor and the stat fails due to the file being still locked (conjecture) --- multitalk.cpp | 17 ++++++++++++----- 1 files changed, 12 insertions(+), 5 deletions(-) diff --git a/multitalk.cpp b/multitalk.cpp index 32ea719..be12854 100644 --- a/multitalk.cpp +++ b/multitalk.cpp @@ -972,10 +972,19 @@ int part_offscreen_y(slide *sl) int talk_modified() { struct stat st; - int ret; + int ret = -1; time_t mod_time; + int retries = 5; + int retry_timeout_us = 100 * 1000; - ret = stat(config->talk_path, &st); + // if the file is locked by an editor retry for a short while (0.5 second) + // TODO: inotify? + while (ret != 0 && --retries > 0) { + ret = stat(config->talk_path, &st); + if (ret != 0) { + usleep(retry_timeout_us); + } + } if(ret != 0) error("Can't check talk file for modifications."); mod_time = st.st_mtime; @@ -1283,7 +1292,6 @@ int mainloop() SDL_KeyboardEvent *key; SDLKey sym; SDLMod mod; - Uint16 code; Uint8 raw; SDL_MouseButtonEvent *click; @@ -1320,6 +1328,7 @@ int mainloop() { SDL_TimerID id; id = SDL_AddTimer(WATCH_INTERVAL, timer_callback_func, NULL); + (void)id; // TODO: store id for cleanup gettimeofday(&tv_watched, NULL); } while(1) @@ -1381,7 +1390,6 @@ int mainloop() case SDL_KEYDOWN: key = &event.key; sym = key->keysym.sym; - code = key->keysym.unicode; mod = key->keysym.mod; raw = key->keysym.scancode; if(gyro) @@ -1654,7 +1662,6 @@ int mainloop() case SDL_KEYUP: key = &event.key; sym = key->keysym.sym; - code = key->keysym.unicode; mod = key->keysym.mod; raw = key->keysym.scancode; if(gyro) -- 1.7.9.1