From d6b45d005530496e48325a6174ecdd889a17bfc1 Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sun, 21 Oct 2018 16:23:45 +0200 Subject: [PATCH] Fix warnings when compiling for Windows. --- src/dropin.c | 5 ++++- src/event.c | 8 ++++---- src/ifconfig.c | 4 +++- src/meta.c | 6 ++++-- src/mingw/device.c | 6 +++++- src/names.c | 3 ++- src/net_packet.c | 9 ++++----- src/net_socket.c | 7 +++++-- src/process.c | 8 ++++++-- src/route.c | 6 +++--- src/script.c | 11 ++++++++--- src/tincd.c | 7 +++++++ src/upnp.c | 18 ++++++++++++++++-- 13 files changed, 71 insertions(+), 27 deletions(-) diff --git a/src/dropin.c b/src/dropin.c index 74e5676f..0cde7a03 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-2016 Guus Sliepen + 2000-2018 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 @@ -82,6 +82,8 @@ int daemon(int nochdir, int noclose) { return 0; #else + (void)nochdir; + (void)noclose; return -1; #endif } @@ -144,6 +146,7 @@ int gettimeofday(struct timeval *tv, void *tz) { #ifndef HAVE_NANOSLEEP int nanosleep(const struct timespec *req, struct timespec *rem) { + (void)rem; struct timeval tv = {req->tv_sec, req->tv_nsec / 1000}; return select(0, NULL, NULL, NULL, &tv); } diff --git a/src/event.c b/src/event.c index 47adb181..1283edd3 100644 --- a/src/event.c +++ b/src/event.c @@ -1,6 +1,6 @@ /* event.c -- I/O, timeout and signal event handling - Copyright (C) 2012-2013 Guus Sliepen + Copyright (C) 2012-2018 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 @@ -378,7 +378,7 @@ bool event_loop(void) { while(running) { struct timeval diff; struct timeval *tv = get_time_remaining(&diff); - DWORD timeout_ms = tv ? (tv->tv_sec * 1000 + tv->tv_usec / 1000 + 1) : WSA_INFINITE; + DWORD timeout_ms = tv ? (DWORD)(tv->tv_sec * 1000 + tv->tv_usec / 1000 + 1) : WSA_INFINITE; if(!event_count) { Sleep(timeout_ms); @@ -435,12 +435,12 @@ bool event_loop(void) { break; } - if(result < WSA_WAIT_EVENT_0 || result >= WSA_WAIT_EVENT_0 + event_count - event_offset) { + if(result >= event_count - event_offset) { return(false); } /* Look up io in the map by index. */ - event_index = result - WSA_WAIT_EVENT_0 + event_offset; + event_index = result - event_offset; io_t *io = io_map[event_index]; if(io->fd == -1) { diff --git a/src/ifconfig.c b/src/ifconfig.c index 76092a7b..742d2ebe 100644 --- a/src/ifconfig.c +++ b/src/ifconfig.c @@ -1,6 +1,6 @@ /* ifconfig.c -- Generate platform specific interface configuration commands - Copyright (C) 2016-2017 Guus Sliepen + Copyright (C) 2016-2018 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 @@ -71,10 +71,12 @@ void ifconfig_dhcp(FILE *out) { } void ifconfig_dhcp6(FILE *out) { + (void)out; fprintf(stderr, "DHCPv6 requested, but not supported by tinc on this platform\n"); } void ifconfig_slaac(FILE *out) { + (void)out; // It's the default? } diff --git a/src/meta.c b/src/meta.c index 0089ac82..4282a4e6 100644 --- a/src/meta.c +++ b/src/meta.c @@ -1,6 +1,6 @@ /* meta.c -- handle the meta communication - Copyright (C) 2000-2014 Guus Sliepen , + Copyright (C) 2000-2018 Guus Sliepen , 2000-2005 Ivo Timmermans 2006 Scott Lamb @@ -31,7 +31,9 @@ #include "xalloc.h" #ifndef MIN -#define MIN(x, y) (((x)<(y))?(x):(y)) +static ssize_t MIN(ssize_t x, ssize_t y) { + return x < y ? x : y; +} #endif bool send_meta_sptps(void *handle, uint8_t type, const void *buffer, size_t length) { diff --git a/src/mingw/device.c b/src/mingw/device.c index 183641ba..bf8ae137 100644 --- a/src/mingw/device.c +++ b/src/mingw/device.c @@ -1,7 +1,7 @@ /* device.c -- Interaction with Windows tap driver in a MinGW environment Copyright (C) 2002-2005 Ivo Timmermans, - 2002-2014 Guus Sliepen + 2002-2018 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 @@ -71,6 +71,9 @@ static void device_issue_read() { } static void device_handle_read(void *data, int flags) { + (void)data; + (void)flags; + DWORD len; if(!GetOverlappedResult(device_handle, &device_read_overlapped, &len, FALSE)) { @@ -300,6 +303,7 @@ static void close_device(void) { } static bool read_packet(vpn_packet_t *packet) { + (void)packet; return false; } diff --git a/src/names.c b/src/names.c index 6db364e0..603b5363 100644 --- a/src/names.c +++ b/src/names.c @@ -1,7 +1,7 @@ /* names.c -- generate commonly used (file)names Copyright (C) 1998-2005 Ivo Timmermans - 2000-2017 Guus Sliepen + 2000-2018 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 @@ -93,6 +93,7 @@ void make_names(bool daemon) { } #ifdef HAVE_MINGW + (void)daemon; if(!logfilename) { xasprintf(&logfilename, "%s" SLASH "log", confbase); diff --git a/src/net_packet.c b/src/net_packet.c index d589228d..5a856429 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -1,7 +1,7 @@ /* net_packet.c -- Handles in- and outgoing VPN packets Copyright (C) 1998-2005 Ivo Timmermans, - 2000-2017 Guus Sliepen + 2000-2018 Guus Sliepen 2010 Timothy Redaelli 2010 Brandon Black @@ -1228,9 +1228,8 @@ static length_t choose_initial_maxmtu(node_t *n) { return mtu; #else - + (void)n; return MTU; - #endif } @@ -1775,13 +1774,13 @@ void handle_incoming_vpn_data(void *data, int flags) { #else vpn_packet_t pkt; - sockaddr_t addr = {}; + sockaddr_t addr = {0}; socklen_t addrlen = sizeof(addr); pkt.offset = 0; int len = recvfrom(ls->udp.fd, (void *)DATA(&pkt), MAXSIZE, 0, &addr.sa, &addrlen); - if(len <= 0 || len > MAXSIZE) { + if(len <= 0 || (size_t)len > MAXSIZE) { if(!sockwouldblock(sockerrno)) { logger(DEBUG_ALWAYS, LOG_ERR, "Receiving packet failed: %s", sockstrerror(sockerrno)); } diff --git a/src/net_socket.c b/src/net_socket.c index dcf8372c..a6961279 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -1,7 +1,7 @@ /* net_socket.c -- Handle various kinds of sockets. Copyright (C) 1998-2005 Ivo Timmermans, - 2000-2017 Guus Sliepen + 2000-2018 Guus Sliepen 2006 Scott Lamb 2009 Florian Forster @@ -122,6 +122,7 @@ static bool bind_to_interface(int sd) { } #else /* if !defined(SOL_SOCKET) || !defined(SO_BINDTODEVICE) */ + (void)sd; logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "BindToInterface"); #endif @@ -387,7 +388,7 @@ void finish_connecting(connection_t *c) { send_id(c); } -static void do_outgoing_pipe(connection_t *c, char *command) { +static void do_outgoing_pipe(connection_t *c, const char *command) { #ifndef HAVE_MINGW int fd[2]; @@ -435,6 +436,8 @@ static void do_outgoing_pipe(connection_t *c, char *command) { exit(result); #else + (void)c; + (void)command; logger(DEBUG_ALWAYS, LOG_ERR, "Proxy type exec not supported on this platform!"); return; #endif diff --git a/src/process.c b/src/process.c index c6cb5360..b6d4e124 100644 --- a/src/process.c +++ b/src/process.c @@ -1,7 +1,7 @@ /* process.c -- process management functions Copyright (C) 1999-2005 Ivo Timmermans, - 2000-2013 Guus Sliepen + 2000-2018 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 @@ -115,7 +115,11 @@ static bool install_service(void) { io_t stop_io; -DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID boe, LPVOID bah) { +DWORD WINAPI controlhandler(DWORD request, DWORD type, LPVOID data, LPVOID context) { + (void)type; + (void)data; + (void)context; + switch(request) { case SERVICE_CONTROL_INTERROGATE: SetServiceStatus(statushandle, &status); diff --git a/src/route.c b/src/route.c index 461ba14a..fc08f5f7 100644 --- a/src/route.c +++ b/src/route.c @@ -1,7 +1,7 @@ /* route.c -- routing Copyright (C) 2000-2005 Ivo Timmermans, - 2000-2013 Guus Sliepen + 2000-2018 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 @@ -165,7 +165,7 @@ static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, length_ addr.sin_family = AF_INET; socklen_t addrlen = sizeof(addr); - if(!getsockname(sockfd, (struct sockaddr *) &addr, &addrlen) && addrlen <= sizeof(addr)) { + if(!getsockname(sockfd, (struct sockaddr *) &addr, &addrlen) && (size_t)addrlen <= sizeof(addr)) { ip_dst = addr.sin_addr; } } @@ -270,7 +270,7 @@ static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, length_ addr.sin6_family = AF_INET6; socklen_t addrlen = sizeof(addr); - if(!getsockname(sockfd, (struct sockaddr *) &addr, &addrlen) && addrlen <= sizeof(addr)) { + if(!getsockname(sockfd, (struct sockaddr *) &addr, &addrlen) && (size_t)addrlen <= sizeof(addr)) { pseudo.ip6_src = addr.sin6_addr; } } diff --git a/src/script.c b/src/script.c index 81216a3a..e465ab7b 100644 --- a/src/script.c +++ b/src/script.c @@ -1,7 +1,7 @@ /* script.c -- call an external script Copyright (C) 1999-2005 Ivo Timmermans, - 2000-2017 Guus Sliepen + 2000-2018 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 @@ -50,7 +50,7 @@ static void unputenv(const char *p) { #else // We must keep what we putenv() around in memory. // To do this without memory leaks, keep things in a list and reuse if possible. - static list_t list = {}; + static list_t list = {0}; for list_each(char, data, &list) { if(!strcmp(data, var)) { @@ -142,7 +142,12 @@ bool execute_script(const char *name, environment_t *env) { #ifdef HAVE_MINGW if(!*scriptextension) { - const char *pathext = getenv("PATHEXT") ? : ".COM;.EXE;.BAT;.CMD"; + const char *pathext = getenv("PATHEXT"); + + if(!pathext) { + pathext = ".COM;.EXE;.BAT;.CMD"; + } + size_t pathlen = strlen(pathext); size_t scriptlen = strlen(scriptname); char fullname[scriptlen + pathlen + 1]; diff --git a/src/tincd.c b/src/tincd.c index dbf6bc82..1e111a25 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -344,10 +344,15 @@ static bool drop_privs(void) { # define setpriority(level) !SetPriorityClass(GetCurrentProcess(), (level)) static void stop_handler(void *data, int flags) { + (void)data; + (void)flags; + event_exit(); } static BOOL WINAPI console_ctrl_handler(DWORD type) { + (void)type; + logger(DEBUG_ALWAYS, LOG_NOTICE, "Got console shutdown request"); if(WSASetEvent(stop_io.event) == FALSE) { @@ -481,6 +486,8 @@ int main(int argc, char **argv) { } int main2(int argc, char **argv) { + (void)argc; + (void)argv; #endif char *priority = NULL; diff --git a/src/upnp.c b/src/upnp.c index 5e41d1b6..553630e8 100644 --- a/src/upnp.c +++ b/src/upnp.c @@ -1,6 +1,6 @@ /* upnp.c -- UPnP-IGD client - Copyright (C) 2015 Guus Sliepen , + Copyright (C) 2015-2018 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 @@ -19,7 +19,9 @@ #include "upnp.h" +#ifndef HAVE_MINGW #include +#endif #include "miniupnpc/miniupnpc.h" #include "miniupnpc/upnpcommands.h" @@ -159,7 +161,9 @@ static void *upnp_thread(void *data) { time_t now = time(NULL); if(now < refresh_time) { - sleep(refresh_time - now); + nanosleep(&(struct timespec) { + refresh_time - now, 0 + }, NULL); } } @@ -176,10 +180,20 @@ void upnp_init(bool tcp, bool udp) { get_config_int(lookup_config(config_tree, "UPnPDiscoverWait"), &upnp_discover_wait); get_config_int(lookup_config(config_tree, "UPnPRefreshPeriod"), &upnp_refresh_period); +#ifdef HAVE_MINGW + HANDLE handle = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)upnp_thread, NULL, 0, NULL); + + if(!handle) { + logger(DEBUG_ALWAYS, LOG_ERR, "Unable to start UPnP-IGD client thread"); + } + +#else pthread_t thread; int error = pthread_create(&thread, NULL, upnp_thread, NULL); if(error) { logger(DEBUG_ALWAYS, LOG_ERR, "Unable to start UPnP-IGD client thread: [%d] %s", error, strerror(error)); } + +#endif } -- 2.20.1