summaryrefslogtreecommitdiffstats
path: root/sys-utils/flock.c
diff options
context:
space:
mode:
authorKarel Zak2018-10-24 12:28:13 +0200
committerKarel Zak2018-12-03 11:23:33 +0100
commit6df5acf970852a94b254800dc69569bd1f4c9ae8 (patch)
tree18751217f934f0dd328edd69fe4da5b6bfb0428c /sys-utils/flock.c
parentbuild-sys: make sure HAVE_TIMER_CREATE defined (diff)
downloadkernel-qcow2-util-linux-6df5acf970852a94b254800dc69569bd1f4c9ae8.tar.gz
kernel-qcow2-util-linux-6df5acf970852a94b254800dc69569bd1f4c9ae8.tar.xz
kernel-qcow2-util-linux-6df5acf970852a94b254800dc69569bd1f4c9ae8.zip
lib/timer: add fallback if timer_create() not available
* add struct ul_timer as API abstraction to hide differences between timer_create() and setitimer() * add setitimer() detection to ./configure.ac * add fallback code to use setitimer() if timer_create() not available (for example on OSX) Addresses: https://github.com/karelzak/util-linux/issues/584 Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'sys-utils/flock.c')
-rw-r--r--sys-utils/flock.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/sys-utils/flock.c b/sys-utils/flock.c
index ed25230b9..57153c8d9 100644
--- a/sys-utils/flock.c
+++ b/sys-utils/flock.c
@@ -81,7 +81,9 @@ static void timeout_handler(int sig __attribute__((__unused__)),
siginfo_t *info,
void *context __attribute__((__unused__)))
{
+#ifdef HAVE_TIMER_CREATE
if (info->si_code == SI_TIMER)
+#endif
timeout_expired = 1;
}
@@ -124,7 +126,7 @@ static void __attribute__((__noreturn__)) run_program(char **cmd_argv)
int main(int argc, char *argv[])
{
- static timer_t t_id;
+ struct ul_timer timer;
struct itimerval timeout;
int have_timeout = 0;
int type = LOCK_EX;
@@ -268,7 +270,7 @@ int main(int argc, char *argv[])
have_timeout = 0;
block = LOCK_NB;
} else
- if (setup_timer(&t_id, &timeout, &timeout_handler))
+ if (setup_timer(&timer, &timeout, &timeout_handler))
err(EX_OSERR, _("cannot set up timer"));
}
@@ -321,7 +323,7 @@ int main(int argc, char *argv[])
}
if (have_timeout)
- cancel_timer(&t_id);
+ cancel_timer(&timer);
if (verbose) {
struct timeval delta;