diff --git a/daemon/state.c b/daemon/state.c
index 6c373c8..39f4497 100644
--- a/daemon/state.c
+++ b/daemon/state.c
@@ -894,6 +894,7 @@ static void *st_queue_handler(void *arg)
struct list_head *head;
struct list_head *p;
struct timespec wait;
+ struct timeval now;
int status, ret;
st_mutex_lock();
@@ -904,8 +905,9 @@ static void *st_queue_handler(void *arg)
* entry is added.
*/
head = &state_queue;
- wait.tv_sec = time(NULL) + 1;
- wait.tv_nsec = 0;
+ gettimeofday(&now, NULL);
+ wait.tv_sec = now.tv_sec + 1;
+ wait.tv_nsec = now.tv_usec * 1000;
while (list_empty(head)) {
status = pthread_cond_timedwait(&cond, &mutex, &wait);
@@ -939,8 +941,9 @@ static void *st_queue_handler(void *arg)
}
while (1) {
- wait.tv_sec = time(NULL) + 1;
- wait.tv_nsec = 0;
+ gettimeofday(&now, NULL);
+ wait.tv_sec = now.tv_sec + 1;
+ wait.tv_nsec = now.tv_usec * 1000;
signaled = 0;
while (!signaled) {
diff --git a/lib/alarm.c b/lib/alarm.c
index c6c4ba3..90bf7aa 100755
--- a/lib/alarm.c
+++ b/lib/alarm.c
@@ -192,12 +192,14 @@ static void *alarm_handler(void *arg)
now = time(NULL);
if (first->time > now) {
+ struct timeval usecs;
/*
* Wait for alarm to trigger or a new alarm
* to be added.
*/
+ gettimeofday(&usecs, NULL);
expire.tv_sec = first->time;
- expire.tv_nsec = 0;
+ expire.tv_nsec = usecs.tv_usec * 1000;
status = pthread_cond_timedwait(&cond, &mutex, &expire);
if (status && status != ETIMEDOUT)