From a36d71a8e33e817b1cc2fde5d0fd476ddc6ac560 Mon Sep 17 00:00:00 2001 From: NIIBE Yutaka Date: Tue, 5 Apr 2022 14:42:59 +0900 Subject: [PATCH] core: Don't use internal __assuan functions. * configure.ac (nanosleep): Detect. * src/assuan-support.c: Don't use __assuan_usleep. (my_socketpair): Don't use __assuan_socketpair. -- Signed-off-by: NIIBE Yutaka --- configure.ac | 2 +- src/assuan-support.c | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/configure.ac b/configure.ac index 8e66c7a0..6b80b6bb 100644 --- a/configure.ac +++ b/configure.ac @@ -739,7 +739,7 @@ fi # # Check for getgid etc -AC_CHECK_FUNCS(getgid getegid closefrom) +AC_CHECK_FUNCS(getgid getegid closefrom nanosleep) # Replacement functions. diff --git a/src/assuan-support.c b/src/assuan-support.c index 7f5b5da9..0bc003b9 100644 --- a/src/assuan-support.c +++ b/src/assuan-support.c @@ -30,7 +30,11 @@ #ifdef HAVE_SYS_TYPES_H # include #endif +#ifdef HAVE_SYS_TIME_H +# include +#endif #ifndef HAVE_W32_SYSTEM +#include #include #endif @@ -68,8 +72,28 @@ _gpgme_assuan_log_cb (assuan_context_t ctx, void *hook, static void my_usleep (assuan_context_t ctx, unsigned int usec) { - /* FIXME: Add to ath. */ - __assuan_usleep (ctx, usec); + (void)ctx; + + if (!usec) + return; + +#ifdef HAVE_W32_SYSTEM + Sleep (usec / 1000); +#else +# ifdef HAVE_NANOSLEEP + { + struct timespec req; + struct timespec rem; + + req.tv_sec = usec / 1000000; + req.tv_nsec = (usec % 1000000) * 1000; + while (nanosleep (&req, &rem) < 0 && errno == EINTR) + req = rem; + } +# else + usleep (usec); +# endif +#endif } @@ -312,8 +336,8 @@ static int my_socketpair (assuan_context_t ctx, int namespace, int style, int protocol, assuan_fd_t filedes[2]) { -#ifdef HAVE_W32_SYSTEM (void)ctx; +#ifdef HAVE_W32_SYSTEM (void)namespace; (void)style; (void)protocol; @@ -322,7 +346,7 @@ my_socketpair (assuan_context_t ctx, int namespace, int style, return -1; #else /* FIXME: Debug output missing. */ - return __assuan_socketpair (ctx, namespace, style, protocol, filedes); + return socketpair (namespace, style, protocol, filedes); #endif }