diff options
author | Jonas 'Sortie' Termansen <sortie@maxsi.org> | 2014-08-29 09:42:41 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-08-29 12:25:28 -0700 |
commit | 0950f08806208b4e3d0aff5f4f7d497637ba4cab (patch) | |
tree | 44b527aef45080dafb1c051dbd12ee59fd18201c /progress.c | |
parent | 710cdba60d50745bde8e86ff0b06490a4d24efcf (diff) | |
download | git-jt/timer-settime.tar.gz |
use timer_settime() for new platformsjt/timer-settime
setitimer() is an obsolescent XSI interface and may be removed in a
future standard. New applications should use the core POSIX
timer_settime() instead.
It's important that code doesn't simply check if timer_settime() is
available as it can give false positives. Some systems like
contemporary OpenBSD provides the function, but it unconditionally
fails with ENOSYS at runtime.
Clean up the progress reporting and change it to use timer_settime(),
which will fall back to setitimer() automatically if timer_settime()
is not supported. (see git-compat-util.h for how it does this). If
both functions are not present, then git-compat-util.h provides
replacements which will always fail with ENOSYS.
The approach used here enables us to use a single API (timer_settime)
without having to worry about checking for #ifdefs or if blocks which
make it an unreadable nightmare. The major downside is for systems
without timer_settime() support, they may fall back on a wrapped
implementation which could have subtle differences. This should be a
minor issue as almost all modern systems provide timer_settime()
support.
Note that this change means that git should never use setitimer()
on its own now, as the fallback implementation of timer_settime()
assumes that it is the sole user of ITIMER_REAL, and timer_delete()
will reset the ITIMER_REAL.
Signed-off-by: Jonas 'Sortie' Termansen <sortie@maxsi.org>
Signed-off-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'progress.c')
-rw-r--r-- | progress.c | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/progress.c b/progress.c index 412e6b1ecc..2321143db0 100644 --- a/progress.c +++ b/progress.c @@ -38,6 +38,7 @@ struct progress { struct throughput *throughput; }; +static timer_t progress_timer; static volatile sig_atomic_t progress_update; static void progress_interval(int signum) @@ -48,7 +49,8 @@ static void progress_interval(int signum) static void set_progress_signal(void) { struct sigaction sa; - struct itimerval v; + struct sigevent sev; + struct itimerspec value; progress_update = 0; @@ -58,16 +60,20 @@ static void set_progress_signal(void) sa.sa_flags = SA_RESTART; sigaction(SIGALRM, &sa, NULL); - v.it_interval.tv_sec = 1; - v.it_interval.tv_usec = 0; - v.it_value = v.it_interval; - setitimer(ITIMER_REAL, &v, NULL); + memset(&sev, 0, sizeof(sev)); + sev.sigev_notify = SIGEV_SIGNAL; + sev.sigev_signo = SIGALRM; + timer_create(CLOCK_MONOTONIC, &sev, &progress_timer); + + value.it_interval.tv_sec = 1; + value.it_interval.tv_nsec = 0; + value.it_value = value.it_interval; + timer_settime(progress_timer, 0, &value, NULL); } static void clear_progress_signal(void) { - struct itimerval v = {{0,},}; - setitimer(ITIMER_REAL, &v, NULL); + timer_delete(progress_timer); signal(SIGALRM, SIG_IGN); progress_update = 0; } |