diff options
author | Karel Zak | 2018-10-24 12:28:13 +0200 |
---|---|---|
committer | Karel Zak | 2018-12-03 11:23:33 +0100 |
commit | 6df5acf970852a94b254800dc69569bd1f4c9ae8 (patch) | |
tree | 18751217f934f0dd328edd69fe4da5b6bfb0428c /misc-utils/uuidd.c | |
parent | build-sys: make sure HAVE_TIMER_CREATE defined (diff) | |
download | kernel-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 'misc-utils/uuidd.c')
-rw-r--r-- | misc-utils/uuidd.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/misc-utils/uuidd.c b/misc-utils/uuidd.c index 8b83d91c0..e0be809dd 100644 --- a/misc-utils/uuidd.c +++ b/misc-utils/uuidd.c @@ -298,7 +298,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 errx(EXIT_FAILURE, _("timed out")); } @@ -327,18 +329,18 @@ static void server_loop(const char *socket_path, const char *pidfile_path, if (!uuidd_cxt->no_sock) /* no_sock implies no_fork and no_pid */ #endif { - static timer_t t_id; + struct ul_timer timer; struct itimerval timeout; memset(&timeout, 0, sizeof timeout); timeout.it_value.tv_sec = 30; - if (setup_timer(&t_id, &timeout, &timeout_handler)) + if (setup_timer(&timer, &timeout, &timeout_handler)) err(EXIT_FAILURE, _("cannot set up timer")); if (pidfile_path) fd_pidfile = create_pidfile(uuidd_cxt, pidfile_path); ret = call_daemon(socket_path, UUIDD_OP_GETPID, reply_buf, sizeof(reply_buf), 0, NULL); - cancel_timer(&t_id); + cancel_timer(&timer); if (ret > 0) { if (!uuidd_cxt->quiet) warnx(_("uuidd daemon is already running at pid %s"), |