From: Guus Sliepen Date: Thu, 14 Apr 2016 15:20:36 +0000 (+0200) Subject: Replace usleep() with nanosleep(). X-Git-Tag: release-1.1pre12~37 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=b5b04910b928c63a31a0859f04bf067ca9bd1cc2;p=oweals%2Ftinc.git Replace usleep() with nanosleep(). --- diff --git a/configure.ac b/configure.ac index d43bfa0..9691fd5 100644 --- a/configure.ac +++ b/configure.ac @@ -199,7 +199,7 @@ AC_CHECK_TYPES([socklen_t, struct ether_header, struct arphdr, struct ether_arp, dnl Checks for library functions. AC_TYPE_SIGNAL -AC_CHECK_FUNCS([asprintf daemon fchmod flock ftime fork get_current_dir_name gettimeofday mlockall putenv random recvmmsg select strdup strsignal usleep unsetenv vsyslog devname fdevname], +AC_CHECK_FUNCS([asprintf daemon fchmod flock ftime fork get_current_dir_name gettimeofday mlockall putenv random recvmmsg select strdup strsignal nanosleep unsetenv vsyslog devname fdevname], [], [], [#include "$srcdir/src/have.h"] ) diff --git a/src/dropin.c b/src/dropin.c index 6d40850..a229755 100644 --- a/src/dropin.c +++ b/src/dropin.c @@ -1,7 +1,7 @@ /* dropin.c -- a set of drop-in replacements for libc functions Copyright (C) 2000-2005 Ivo Timmermans, - 2000-2013 Guus Sliepen + 2000-2016 Guus Sliepen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -174,10 +174,9 @@ int gettimeofday(struct timeval *tv, void *tz) { } #endif -#ifndef HAVE_USLEEP -int usleep(long long usec) { - struct timeval tv = {usec / 1000000, (usec / 1000) % 1000}; - select(0, NULL, NULL, NULL, &tv); - return 0; +#ifndef HAVE_NANOSLEEP +int nanosleep(const struct timespec *req, struct timespec *rem) { + struct timeval tv = {req->tv_sec, req->tv_nsec / 1000}; + return select(0, NULL, NULL, NULL, &tv); } #endif diff --git a/src/dropin.h b/src/dropin.h index 5601a31..fff2d41 100644 --- a/src/dropin.h +++ b/src/dropin.h @@ -41,8 +41,8 @@ extern int vasprintf(char **, const char *, va_list ap); extern int gettimeofday(struct timeval *, void *); #endif -#ifndef HAVE_USLEEP -extern int usleep(long long usec); +#ifndef HAVE_NANOSLEEP +extern int nanosleep(const struct timespec *req, struct timespec *rem); #endif #ifndef timeradd diff --git a/src/net.c b/src/net.c index a539425..9094d61 100644 --- a/src/net.c +++ b/src/net.c @@ -181,7 +181,7 @@ static void periodic_handler(void *data) { if(contradicting_del_edge > 100 && contradicting_add_edge > 100) { logger(DEBUG_ALWAYS, LOG_WARNING, "Possible node with same Name as us! Sleeping %d seconds.", sleeptime); - usleep(sleeptime * 1000000LL); + nanosleep(&(struct timespec){sleeptime, 0}, NULL); sleeptime *= 2; if(sleeptime < 0) sleeptime = 3600;