Merge branch 'features/mingw-win10-perror' into develop

This commit is contained in:
Willem Toorop 2017-10-20 16:07:46 +02:00
commit f26fd6c8ee
8 changed files with 121 additions and 44 deletions

View File

@ -254,7 +254,7 @@ esac
DEFAULT_EVENTLOOP=select_eventloop
AC_CHECK_HEADERS([sys/poll.h poll.h sys/resource.h sys/types.h],,, [AC_INCLUDES_DEFAULT])
AC_CHECK_HEADERS([signal.h sys/poll.h poll.h sys/resource.h sys/types.h],,, [AC_INCLUDES_DEFAULT])
AC_ARG_ENABLE(poll-eventloop, AC_HELP_STRING([--disable-poll-eventloop], [Disable default eventloop based on poll (default=enabled if available)]))
case "$enable_poll_eventloop" in
no)
@ -677,29 +677,29 @@ if test "$USE_WINSOCK" = 1; then
LIBS="$LIBS -lgdi32 -liphlpapi"
fi
dnl Check if -D_POSIX is needed for sigset_t
AC_CHECK_TYPE([sigset_t], [
AC_MSG_NOTICE(-D_POSIX is NOT needed for the sigset_t type)
], [
BACKCFLAGS="$CFLAGS"
CFLAGS="-D_POSIX $CFLAGS"
AC_CHECK_TYPE([sigset_t], [
AC_MSG_NOTICE(-D_POSIX is needed for the sigset_t type)
], [
AC_MSG_NOTICE(Unclear whether -D_POSIX is needed for the sigset_t type)
BACKCFLAGS="$CFLAGS"
], [AC_INCLUDES_DEFAULT
dnl sigset_t or _sigset_t? MinGW is latter by default.
AC_CHECK_TYPES([sigset_t],
[],
[AC_CHECK_TYPES([_sigset_t],
[],
[AC_MSG_ERROR([Can't find type `sigset_t' or type `_sigset_t'])],
[AC_INCLUDES_DEFAULT
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
])
], [AC_INCLUDES_DEFAULT
])
],
[AC_INCLUDES_DEFAULT
#ifdef HAVE_SIGNAL_H
#include <signal.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
])
AC_CHECK_FUNCS(sigemptyset sigfillset sigaddset)
my_with_libidn=1
@ -1376,12 +1376,6 @@ AH_BOTTOM([
# include <winsock2.h>
# endif
# ifndef USE_WINSOCK
# define ARG_LL "%ll"
# else
# define ARG_LL "%I64"
# endif
/* detect if we need to cast to unsigned int for FD_SET to avoid warnings */
# ifdef HAVE_WINSOCK2_H
# define FD_SET_T (u_int)
@ -1566,11 +1560,14 @@ struct tm;
char *strptime(const char *s, const char *format, struct tm *tm);
#endif
#if !defined(HAVE_SIGSET_T) && defined(HAVE__SIGSET_T)
typedef _sigset_t sigset_t;
#endif
#if !defined(HAVE_SIGEMPTYSET)
# define sigemptyset(pset) (*(pset) = 0)
#endif
#if !defined(HAVE_SIGFILLSET)
# define sigfillset(pset) (*(pset) = (_sigset_t)-1)
# define sigfillset(pset) (*(pset) = (sigset_t)-1)
#endif
#if !defined(HAVE_SIGADDSET)
# define sigaddset(pset, num) (*(pset) |= (1L<<(num)))

View File

@ -77,7 +77,7 @@ C99COMPATFLAGS=@C99COMPATFLAGS@
DEFAULT_EVENTLOOP_OBJ=@DEFAULT_EVENTLOOP@.lo
GETDNS_OBJ=const-info.lo convert.lo dict.lo dnssec.lo general.lo \
list.lo request-internal.lo pubkey-pinning.lo rr-dict.lo \
list.lo request-internal.lo platform.lo pubkey-pinning.lo rr-dict.lo \
rr-iter.lo server.lo stub.lo sync.lo ub_loop.lo util-internal.lo \
mdns.lo
@ -386,6 +386,8 @@ mdns.lo mdns.o: $(srcdir)/mdns.c \
$(srcdir)/gldns/pkthdr.h $(srcdir)/anchor.h $(srcdir)/general.h $(srcdir)/gldns/rrdef.h $(srcdir)/util-internal.h \
$(srcdir)/platform.h $(srcdir)/mdns.h $(srcdir)/util/auxiliary/util/fptr_wlist.h $(srcdir)/util/lookup3.h \
$(srcdir)/util/orig-headers/lookup3.h
platform.lo platform.o: $(srcdir)/platform.c $(srcdir)/platform.h \
config.h
pubkey-pinning.lo pubkey-pinning.o: $(srcdir)/pubkey-pinning.c \
config.h \
$(srcdir)/debug.h \
@ -588,7 +590,8 @@ select_eventloop.lo select_eventloop.o: $(srcdir)/extension/select_eventloop.c \
$(srcdir)/debug.h $(srcdir)/types-internal.h \
getdns/getdns.h \
getdns/getdns_extra.h \
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/extension/select_eventloop.h
$(srcdir)/util/rbtree.h $(srcdir)/util/orig-headers/rbtree.h $(srcdir)/platform.h \
$(srcdir)/extension/select_eventloop.h
stubby.lo stubby.o: $(stubbysrcdir)/src/stubby.c \
config.h \
getdns/getdns.h \

View File

@ -59,6 +59,20 @@
fprintf(stderr, "[%s.%.6d] ", buf_dEbUgSyM, (int)tv_dEbUgSyM.tv_usec); \
fprintf(stderr, __VA_ARGS__); \
} while (0)
#define DEBUG_NL(...) do { \
struct timeval tv_dEbUgSyM; \
struct tm tm_dEbUgSyM; \
char buf_dEbUgSyM[10]; \
time_t tsec_dEbUgSyM; \
\
gettimeofday(&tv_dEbUgSyM, NULL); \
tsec_dEbUgSyM = (time_t) tv_dEbUgSyM.tv_sec; \
gmtime_s(&tm_dEbUgSyM, (const time_t *) &tsec_dEbUgSyM); \
strftime(buf_dEbUgSyM, 10, "%H:%M:%S", &tm_dEbUgSyM); \
fprintf(stderr, "[%s.%.6d] ", buf_dEbUgSyM, (int)tv_dEbUgSyM.tv_usec); \
fprintf(stderr, __VA_ARGS__); \
} while (0)
#else
#define DEBUG_ON(...) do { \
struct timeval tv_dEbUgSyM; \
@ -71,9 +85,8 @@
fprintf(stderr, "[%s.%.6d] ", buf_dEbUgSyM, (int)tv_dEbUgSyM.tv_usec); \
fprintf(stderr, __VA_ARGS__); \
} while (0)
#endif
#define DEBUG_NL(...) do { \
#define DEBUG_NL(...) do { \
struct timeval tv_dEbUgSyM; \
struct tm tm_dEbUgSyM; \
char buf_dEbUgSyM[10]; \
@ -85,7 +98,7 @@
fprintf(stderr, __VA_ARGS__); \
fprintf(stderr, "\n"); \
} while (0)
#endif
#define DEBUG_OFF(...) do {} while (0)

View File

@ -408,7 +408,7 @@ poll_eventloop_run_once(getdns_eventloop *loop, int blocking)
} else
#endif
if (_getdns_poll(poll_loop->pfds, poll_loop->fd_events_free, poll_timeout) < 0) {
perror("poll() failed");
_getdns_perror("poll() failed");
exit(EXIT_FAILURE);
}
now = get_now_plus(0);

View File

@ -29,6 +29,7 @@
#include "debug.h"
#include "types-internal.h"
#include "platform.h"
#include "extension/select_eventloop.h"
static uint64_t get_now_plus(uint64_t amount)
@ -244,7 +245,7 @@ select_eventloop_run_once(getdns_eventloop *loop, int blocking)
#endif
if (select(max_fd + 1, &readfds, &writefds, NULL,
(timeout == TIMEOUT_FOREVER ? NULL : &tv)) < 0) {
perror("select() failed");
_getdns_perror("select() failed");
exit(EXIT_FAILURE);
}
#ifdef USE_WINSOCK

View File

@ -1059,11 +1059,7 @@ int gldns_wire2str_tsigtime_scan(uint8_t** d, size_t* dl, char** s, size_t* sl)
d4 = (*d)[4];
d5 = (*d)[5];
tsigtime = (d0<<40) | (d1<<32) | (d2<<24) | (d3<<16) | (d4<<8) | d5;
#ifndef USE_WINSOCK
w = gldns_str_print(s, sl, "%llu", (long long)tsigtime);
#else
w = gldns_str_print(s, sl, "%I64u", (long long)tsigtime);
#endif
w = gldns_str_print(s, sl, "%"PRIu64, (uint64_t)tsigtime);
(*d)+=6;
(*dl)-=6;
return w;
@ -1746,13 +1742,8 @@ int gldns_wire2str_edns_llq_print(char** s, size_t* sl, uint8_t* data,
if(error_code < llq_errors_num)
w += gldns_str_print(s, sl, " %s", llq_errors[error_code]);
else w += gldns_str_print(s, sl, " error %d", (int)error_code);
#ifndef USE_WINSOCK
w += gldns_str_print(s, sl, " id %llx lease-life %lu",
(unsigned long long)llq_id, (unsigned long)lease_life);
#else
w += gldns_str_print(s, sl, " id %I64x lease-life %lu",
(unsigned long long)llq_id, (unsigned long)lease_life);
#endif
w += gldns_str_print(s, sl, " id %"PRIx64" lease-life %lu",
(uint64_t)llq_id, (unsigned long)lease_life);
return w;
}

69
src/platform.c Normal file
View File

@ -0,0 +1,69 @@
/**
*
* \file platform.c
* @brief general functions with platform-dependent implementations
*
*/
/*
* Copyright (c) 2017, NLnet Labs, Sinodun
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* * Neither the names of the copyright holders nor the
* names of its contributors may be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL Verisign, Inc. BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "platform.h"
#include <stdio.h>
#ifdef USE_WINSOCK
void _getdns_perror(const char *str)
{
char msg[256];
int errid = WSAGetLastError();
*msg = '\0';
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
errid,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
msg,
sizeof(msg),
NULL);
if (*msg == '\0')
sprintf(msg, "Unknown error: %d", errid);
if (str && *str != '\0')
fprintf(stderr, "%s: ", str);
fputs(msg, stderr);
}
#else
void _getdns_perror(const char *str)
{
perror(str);
}
#endif

View File

@ -1,6 +1,7 @@
/**
*
* /brief general functions with platform-dependent implementations
* \file platform.h
* @brief general functions with platform-dependent implementations
*
*/
@ -78,4 +79,6 @@ typedef u_short sa_family_t;
#define _getdns_socketerror() (errno)
#endif
void _getdns_perror(const char *str);
#endif