Skip to content

Commit

Permalink
Fixes: NB#260776 - Scheduled synchronization NOT working with all ac…
Browse files Browse the repository at this point in the history
…counts if device time set to past

    - use clock_gettime(clock_gettime(CLOCK_MONOTONIC, ...) instead of time()
  • Loading branch information
Raimo Vuonnala committed Jun 9, 2011
1 parent a7467b6 commit ab256dc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
2 changes: 1 addition & 1 deletion configure.ac
@@ -1,5 +1,5 @@
# Package name and version
AC_INIT(libiphb, 0.61.31)
AC_INIT(libiphb, 0.61.32)

AM_INIT_AUTOMAKE

Expand Down
7 changes: 7 additions & 0 deletions debian/changelog
@@ -1,3 +1,10 @@
libiphb (0.61.32) unstable; urgency=low

* Fixes: NB#260776 - Scheduled synchronization NOT working with all accounts if device time set to past
- use clock_gettime(clock_gettime(CLOCK_MONOTONIC, ...) instead of time()

-- Raimo Vuonnala <raimo.vuonnala@nokia.com> Thu, 09 Jun 2011 10:48:17 +0300

libiphb (0.61.31) unstable; urgency=low

* New defines for fixed periods (refix for #253041)
Expand Down
2 changes: 1 addition & 1 deletion iphbd/Makefile.am
Expand Up @@ -3,7 +3,7 @@
#
AM_CFLAGS = -Wall -Wmissing-prototypes -std=c99 -Os -g -fPIC
AM_CPPFLAGS = -D_GNU_SOURCE
AM_LDFLAGS = -g -Wl,--as-needed
AM_LDFLAGS = -g -lrt -Wl,--as-needed

ACLOCAL_AMFLAGS = -I m4

Expand Down
19 changes: 12 additions & 7 deletions iphbd/libiphb.c
Expand Up @@ -189,29 +189,34 @@ iphb_wait(iphb_t iphbh, unsigned short mintime, unsigned short maxtime, int must
return (time_t)0;

fd_set readfds;
struct timeval timeout;
time_t then = time(0);
time_t now;
struct timeval timeout;
struct timespec ts_then;
struct timespec ts_now;
int st;


(void)clock_gettime(CLOCK_MONOTONIC, &ts_then);

timeout.tv_sec = maxtime;
timeout.tv_usec = 0;

for (;;) {
FD_ZERO(&readfds);
FD_SET(HB_INST(iphbh)->fd, &readfds);
st = select(HB_INST(iphbh)->fd + 1, &readfds, NULL, NULL, &timeout);
now = time(0);

(void)clock_gettime(CLOCK_MONOTONIC, &ts_now);

if (st == -1 && errno == EINTR) {
if (now - then < maxtime) {
timeout.tv_sec = maxtime - (now - then);
if (ts_now.tv_sec - ts_then.tv_sec < maxtime) {
timeout.tv_sec = maxtime - (ts_now.tv_sec - ts_then.tv_sec);
continue;
}
}
break;
}
if (st == 0) /* timeout */
return now - then;
return ts_now.tv_sec - ts_then.tv_sec;

if (recv(HB_INST(iphbh)->fd, &resp, sizeof(resp), MSG_WAITALL) > 0)
return resp.waited;
Expand Down

0 comments on commit ab256dc

Please sign in to comment.