diff options
author | Karel Zak | 2017-04-28 13:02:02 +0200 |
---|---|---|
committer | Karel Zak | 2017-04-28 13:02:02 +0200 |
commit | ed1c112666e67dd9c1ae427a94acd1249fa8314f (patch) | |
tree | 89208b772bd4b4674dae1dc77e757efcc603dabb /lib/timer.c | |
parent | libmount: (docs) remove unwanted tag (diff) | |
parent | lib/timer.c: prevent pathological race condition (diff) | |
download | kernel-qcow2-util-linux-ed1c112666e67dd9c1ae427a94acd1249fa8314f.tar.gz kernel-qcow2-util-linux-ed1c112666e67dd9c1ae427a94acd1249fa8314f.tar.xz kernel-qcow2-util-linux-ed1c112666e67dd9c1ae427a94acd1249fa8314f.zip |
Merge branch 'timer' of https://github.com/Villemoes/util-linux
Diffstat (limited to 'lib/timer.c')
-rw-r--r-- | lib/timer.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/timer.c b/lib/timer.c index 05fbd92f5..813eade94 100644 --- a/lib/timer.c +++ b/lib/timer.c @@ -13,16 +13,18 @@ int setup_timer(timer_t * t_id, struct itimerval *timeout, void (*timeout_handler)(int, siginfo_t *, void *)) { + time_t sec = timeout->it_value.tv_sec; + long usec = timeout->it_value.tv_usec; struct sigaction sig_a; static struct sigevent sig_e = { .sigev_notify = SIGEV_SIGNAL, .sigev_signo = SIGALRM }; struct itimerspec val = { - .it_value.tv_sec = timeout->it_value.tv_sec, - .it_value.tv_nsec = timeout->it_value.tv_usec * 1000, - .it_interval.tv_sec = 0, - .it_interval.tv_nsec = 0 + .it_value.tv_sec = sec, + .it_value.tv_nsec = usec * 1000, + .it_interval.tv_sec = sec / 100, + .it_interval.tv_nsec = (sec ? sec % 100 : 1) * 10*1000*1000 }; if (sigemptyset(&sig_a.sa_mask)) @@ -35,7 +37,7 @@ int setup_timer(timer_t * t_id, struct itimerval *timeout, return 1; if (timer_create(CLOCK_MONOTONIC, &sig_e, t_id)) return 1; - if (timer_settime(*t_id, SA_SIGINFO, &val, NULL)) + if (timer_settime(*t_id, 0, &val, NULL)) return 1; return 0; } |