From a05d84006712ac65c611d494b2b1f1d3bcb27207 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 17 Apr 2008 17:58:20 +0200 Subject: [PATCH] Fix select timeout. Under Linux, select() modifies the timeval pointed to by the last parameter; it contains the time that was not slept because an fd in one of the given fd sets became ready. It is hence necessary to reset the time to be slept in each iteration off dss' select loop. --- dss.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/dss.c b/dss.c index 6124060..b475ba7 100644 --- a/dss.c +++ b/dss.c @@ -747,19 +747,24 @@ static int select_loop(void) { int ret; /* check every 60 seconds for free disk space */ - struct timeval tv = {.tv_sec = 60, .tv_usec = 0}; + struct timeval tv; for (;;) { fd_set rfds; int low_disk_space; char **rsync_argv; - struct timeval now, *tvp = &tv; + struct timeval now, *tvp; if (rm_pid) tvp = NULL; /* sleep until rm process dies */ + else { /* sleep one minute */ + tv.tv_sec = 60; + tv.tv_usec = 0; + tvp = &tv; + } FD_ZERO(&rfds); FD_SET(signal_pipe, &rfds); - DSS_DEBUG_LOG("tvp: %p, tv_sec: %lu\n", tvp, (long unsigned) tv.tv_sec); + DSS_DEBUG_LOG("tvp: %p, tv_sec : %lu\n", tvp, (long unsigned) tv.tv_sec); ret = dss_select(signal_pipe + 1, &rfds, NULL, tvp); if (ret < 0) return ret; -- 2.30.2