diff options
author | akir <akir> | 2004-10-19 08:59:44 (GMT) |
---|---|---|
committer | akir <akir> | 2004-10-19 08:59:44 (GMT) |
commit | 45726d3016ed9b4a9e3a135d5b30246245bbaf92 (patch) | |
tree | b152fd329ec0b8250db8adf07954c8e71d19799f /src | |
parent | 1ace87ac15fa056bdd1af783fa9b4f86e3221ff7 (diff) | |
download | fluxbox-45726d3016ed9b4a9e3a135d5b30246245bbaf92.zip fluxbox-45726d3016ed9b4a9e3a135d5b30246245bbaf92.tar.bz2 |
if the systemtime is set back the timers wont be updated.
solution: add the delta to all of our timers too.
Diffstat (limited to 'src')
-rw-r--r-- | src/FbTk/Timer.cc | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/src/FbTk/Timer.cc b/src/FbTk/Timer.cc index ddc24ea..335d247 100644 --- a/src/FbTk/Timer.cc +++ b/src/FbTk/Timer.cc | |||
@@ -110,6 +110,7 @@ void Timer::updateTimers(int fd) { | |||
110 | FD_ZERO(&rfds); | 110 | FD_ZERO(&rfds); |
111 | FD_SET(fd, &rfds); | 111 | FD_SET(fd, &rfds); |
112 | 112 | ||
113 | |||
113 | if (m_timerlist.size() > 0) { | 114 | if (m_timerlist.size() > 0) { |
114 | gettimeofday(&now, 0); | 115 | gettimeofday(&now, 0); |
115 | 116 | ||
@@ -142,13 +143,27 @@ void Timer::updateTimers(int fd) { | |||
142 | 143 | ||
143 | select(fd + 1, &rfds, 0, 0, timeout); | 144 | select(fd + 1, &rfds, 0, 0, timeout); |
144 | 145 | ||
146 | TimerList::iterator it; | ||
147 | |||
148 | // someone set the date of the machine BACK | ||
149 | // so we have to adjust the start_time | ||
150 | static time_t last_time = time(0); | ||
151 | if (time(0) < last_time) { | ||
152 | |||
153 | time_t delta = time(0) - last_time; | ||
154 | |||
155 | for (it = m_timerlist.begin(); it != m_timerlist.end(); it++) { | ||
156 | (*it)->m_start.tv_sec += delta; | ||
157 | } | ||
158 | } | ||
159 | |||
160 | |||
145 | // check for timer timeout | 161 | // check for timer timeout |
146 | gettimeofday(&now, 0); | 162 | gettimeofday(&now, 0); |
147 | 163 | ||
148 | TimerList::iterator it = m_timerlist.begin(); | ||
149 | //must check end ...the timer might remove | 164 | //must check end ...the timer might remove |
150 | //it self from the list (should be fixed in the future) | 165 | //it self from the list (should be fixed in the future) |
151 | for(; it != m_timerlist.end(); ++it) { | 166 | for(it = m_timerlist.begin(); it != m_timerlist.end(); ++it) { |
152 | //This is to make sure we don't get an invalid iterator | 167 | //This is to make sure we don't get an invalid iterator |
153 | //when we do fireTimeout | 168 | //when we do fireTimeout |
154 | Timer &t = *(*it); | 169 | Timer &t = *(*it); |
@@ -157,8 +172,8 @@ void Timer::updateTimers(int fd) { | |||
157 | tm.tv_usec = t.getStartTime().tv_usec + | 172 | tm.tv_usec = t.getStartTime().tv_usec + |
158 | t.getTimeout().tv_usec; | 173 | t.getTimeout().tv_usec; |
159 | 174 | ||
160 | if ((now.tv_sec < tm.tv_sec) || | 175 | if (((now.tv_sec < tm.tv_sec) || |
161 | (now.tv_sec == tm.tv_sec && now.tv_usec < tm.tv_usec)) | 176 | (now.tv_sec == tm.tv_sec && now.tv_usec < tm.tv_usec))) |
162 | break; | 177 | break; |
163 | 178 | ||
164 | t.fireTimeout(); | 179 | t.fireTimeout(); |
@@ -170,6 +185,8 @@ void Timer::updateTimers(int fd) { | |||
170 | it--; | 185 | it--; |
171 | } | 186 | } |
172 | } | 187 | } |
188 | |||
189 | last_time = time(0); | ||
173 | } | 190 | } |
174 | 191 | ||
175 | void Timer::addTimer(Timer *timer) { | 192 | void Timer::addTimer(Timer *timer) { |