From: Guus Sliepen Date: Mon, 28 Jul 2003 22:06:09 +0000 (+0000) Subject: More checks for missing functions. X-Git-Tag: release-1.0~40 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=0e945413315c9d15a3eb013fa3731dd978a8c7b8;p=tinc More checks for missing functions. --- diff --git a/configure.in b/configure.in index 7850ac97..def2423a 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ dnl Process this file with autoconf to produce a configure script. -dnl $Id: configure.in,v 1.13.2.71 2003/07/21 15:51:00 guus Exp $ +dnl $Id: configure.in,v 1.13.2.72 2003/07/28 22:06:08 guus Exp $ AC_PREREQ(2.53) AC_INIT(src/tincd.c) @@ -155,7 +155,7 @@ dnl Checks for library functions. AC_FUNC_MEMCMP AC_FUNC_ALLOCA AC_TYPE_SIGNAL -AC_CHECK_FUNCS([asprintf daemon fcloseall flock ftime get_current_dir_name putenv select strdup strerror strsignal strtol unsetenv mlockall vsyslog]) +AC_CHECK_FUNCS([asprintf daemon fcloseall flock ftime fork get_current_dir_name gettimeofday mlockall putenv select strdup strerror strsignal strtol unsetenv vsyslog]) jm_FUNC_MALLOC jm_FUNC_REALLOC diff --git a/lib/dropin.c b/lib/dropin.c index 0a8ae6ef..c92c0b81 100644 --- a/lib/dropin.c +++ b/lib/dropin.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: dropin.c,v 1.1.2.16 2003/07/21 13:14:02 guus Exp $ + $Id: dropin.c,v 1.1.2.17 2003/07/28 22:06:09 guus Exp $ */ #include "system.h" @@ -40,6 +40,7 @@ */ int daemon(int nochdir, int noclose) { +#ifdef HAVE_FORK pid_t pid; int fd; @@ -82,6 +83,9 @@ int daemon(int nochdir, int noclose) } return 0; +#else + return -1; +#endif } #endif @@ -147,3 +151,11 @@ int asprintf(char **buf, const char *fmt, ...) return status; } #endif + +#ifndef HAVE_GETTIMEOFDAY +int gettimeofday(struct timeval *tv, void *tz) { + tv->tv_sec = time(NULL); + tv->tv_usec = 0; + return 0; +} +#endif diff --git a/lib/pidfile.c b/lib/pidfile.c index 2dea70b9..4a7276de 100644 --- a/lib/pidfile.c +++ b/lib/pidfile.c @@ -27,6 +27,7 @@ #include "system.h" +#ifndef HAVE_MINGW /* read_pid * * Reads the specified pidfile and returns the read pid. @@ -68,6 +69,7 @@ int check_pid (char *pidfile) errno = 0; if (kill(pid, 0) && errno == ESRCH) return(0); +#endif return pid; } @@ -127,4 +129,4 @@ int remove_pid (char *pidfile) { return unlink (pidfile); } - +#endif diff --git a/lib/pidfile.h b/lib/pidfile.h index 19d19c16..d428d48c 100644 --- a/lib/pidfile.h +++ b/lib/pidfile.h @@ -19,6 +19,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ +#ifndef HAVE_MINGW /* read_pid * * Reads the specified pidfile and returns the read pid. @@ -48,3 +49,4 @@ int write_pid (char *pidfile); * is returned */ int remove_pid (char *pidfile); +#endif diff --git a/src/logger.c b/src/logger.c index 032349d1..1f7785f2 100644 --- a/src/logger.c +++ b/src/logger.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: logger.c,v 1.1.2.5 2003/07/22 20:55:19 guus Exp $ + $Id: logger.c,v 1.1.2.6 2003/07/28 22:06:09 guus Exp $ */ #include "system.h" @@ -37,8 +37,6 @@ void openlogger(const char *ident, logmode_t mode) { logmode = mode; switch(mode) { - case LOGMODE_NULL: - break; case LOGMODE_STDERR: logpid = getpid(); break; @@ -49,8 +47,12 @@ void openlogger(const char *ident, logmode_t mode) { logmode = LOGMODE_NULL; break; case LOGMODE_SYSLOG: +#ifdef HAVE_SYSLOG openlog(logident, LOG_CONS | LOG_PID, LOG_DAEMON); break; +#endif + case LOGMODE_NULL: + break; } } @@ -60,8 +62,6 @@ void logger(int priority, const char *format, ...) { va_start(ap, format); switch(logmode) { - case LOGMODE_NULL: - break; case LOGMODE_STDERR: vfprintf(stderr, format, ap); fprintf(stderr, "\n"); @@ -72,6 +72,7 @@ void logger(int priority, const char *format, ...) { fprintf(logfile, "\n"); break; case LOGMODE_SYSLOG: +#ifdef HAVE_SYSLOG #ifdef HAVE_VSYSLOG vsyslog(priority, format, ap); #else @@ -82,6 +83,9 @@ void logger(int priority, const char *format, ...) { } #endif break; +#endif + case LOGMODE_NULL: + break; } va_end(ap); @@ -89,14 +93,17 @@ void logger(int priority, const char *format, ...) { void closelogger(void) { switch(logmode) { - case LOGMODE_NULL: - case LOGMODE_STDERR: - break; case LOGMODE_FILE: fclose(logfile); break; case LOGMODE_SYSLOG: +#ifdef HAVE_SYSLOG closelog(); break; +#endif + case LOGMODE_NULL: + case LOGMODE_STDERR: + break; + break; } } diff --git a/src/logger.h b/src/logger.h index eb02fb87..c2672c66 100644 --- a/src/logger.h +++ b/src/logger.h @@ -20,6 +20,19 @@ typedef enum logmode_t { LOGMODE_SYSLOG } logmode_t; +#ifndef HAVE_SYSLOG +enum { + LOG_EMERG, + LOG_ALERT, + LOG_CRIT, + LOG_ERR, + LOG_WARNING, + LOG_NOTICE, + LOG_INFO, + LOG_DEBUG, +}; +#endif + extern debug_t debug_level; extern void openlogger(const char *, logmode_t); extern void logger(int, const char *, ...) __attribute__ ((format(printf, 2, 3))); diff --git a/src/net_socket.c b/src/net_socket.c index aa7d3d99..5f9e2173 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net_socket.c,v 1.1.2.31 2003/07/24 12:08:15 guus Exp $ + $Id: net_socket.c,v 1.1.2.32 2003/07/28 22:06:09 guus Exp $ */ #include "system.h" @@ -34,6 +34,10 @@ #include "utils.h" #include "xalloc.h" +#ifdef WSAEINPROGRESS +#define EINPROGRESS WSAEINPROGRESS +#endif + int addressfamily = AF_UNSPEC; int maxtimeout = 900; int seconds_till_retry = 5; @@ -49,7 +53,9 @@ int setup_listen_socket(const sockaddr_t *sa) char *addrstr; int option; char *iface; +#ifdef SO_BINDTODEVICE struct ifreq ifr; +#endif cp(); @@ -60,6 +66,7 @@ int setup_listen_socket(const sockaddr_t *sa) return -1; } +#ifdef O_NONBLOCK flags = fcntl(nfd, F_GETFL); if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) { @@ -68,6 +75,7 @@ int setup_listen_socket(const sockaddr_t *sa) strerror(errno)); return -1; } +#endif /* Optimize TCP settings */ @@ -138,6 +146,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) return -1; } +#ifdef O_NONBLOCK flags = fcntl(nfd, F_GETFL); if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) { close(nfd); @@ -145,6 +154,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) strerror(errno)); return -1; } +#endif option = 1; setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)); @@ -280,11 +290,13 @@ begin: /* Non-blocking */ +#ifdef O_NONBLOCK flags = fcntl(c->socket, F_GETFL); if(fcntl(c->socket, F_SETFL, flags | O_NONBLOCK) < 0) { logger(LOG_ERR, _("fcntl for %s: %s"), c->hostname, strerror(errno)); } +#endif /* Connect */ diff --git a/src/process.c b/src/process.c index 218df760..36b21461 100644 --- a/src/process.c +++ b/src/process.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: process.c,v 1.1.2.57 2003/07/22 20:55:20 guus Exp $ + $Id: process.c,v 1.1.2.58 2003/07/28 22:06:09 guus Exp $ */ #include "system.h" @@ -88,6 +88,7 @@ void cleanup_and_exit(int c) exit(c); } +#ifndef HAVE_MINGW /* check for an existing tinc for this net, and write pid to pidfile */ @@ -114,12 +115,14 @@ static bool write_pidfile(void) return true; } +#endif /* kill older tincd for this net */ bool kill_other(int signal) { +#ifndef HAVE_MINGW int pid; cp(); @@ -148,6 +151,7 @@ bool kill_other(int signal) fprintf(stderr, _("Removing stale lock file.\n")); remove_pid(pidfilename); } +#endif return true; } @@ -163,13 +167,16 @@ bool detach(void) /* First check if we can open a fresh new pidfile */ +#ifndef HAVE_MINGW if(!write_pidfile()) return false; +#endif /* If we succeeded in doing that, detach */ closelogger(); +#ifdef HAVE_FORK if(do_detach) { if(daemon(0, 0)) { fprintf(stderr, _("Couldn't detach from terminal: %s"), @@ -182,6 +189,7 @@ bool detach(void) if(!write_pid(pidfilename)) return false; } +#endif openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR)); @@ -193,6 +201,7 @@ bool detach(void) return true; } +#ifdef HAVE_FORK /* Execute the program name, with sane environment. */ @@ -224,12 +233,14 @@ static void _execute_script(const char *scriptname, char **envp) strerror(save_errno)); exit(save_errno); } +#endif /* Fork and execute the program pointed to by name. */ bool execute_script(const char *name, char **envp) { +#ifdef HAVE_FORK pid_t pid; int status; struct stat s; @@ -287,6 +298,9 @@ bool execute_script(const char *name, char **envp) /* Child here */ _execute_script(scriptname, envp); +#else + return true; +#endif } @@ -294,6 +308,7 @@ bool execute_script(const char *name, char **envp) Signal handlers. */ +#ifndef HAVE_MINGW static RETSIGTYPE sigterm_handler(int a) { logger(LOG_NOTICE, _("Got TERM signal")); @@ -415,9 +430,11 @@ static struct { {SIGWINCH, sigwinch_handler}, {0, NULL} }; +#endif void setup_signals(void) { +#ifndef HAVE_MINGW int i; struct sigaction act; @@ -449,4 +466,5 @@ void setup_signals(void) sighandlers[i].signal, strsignal(sighandlers[i].signal), strerror(errno)); } +#endif } diff --git a/src/tincd.c b/src/tincd.c index b9f9f4f4..d2179ab1 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: tincd.c,v 1.10.4.76 2003/07/22 20:55:20 guus Exp $ + $Id: tincd.c,v 1.10.4.77 2003/07/28 22:06:09 guus Exp $ */ #include "system.h" @@ -147,6 +147,7 @@ static void parse_options(int argc, char **argv, char **envp) break; case 'k': /* kill old tincds */ +#ifndef HAVE_MINGW if(optarg) { if(!strcasecmp(optarg, "HUP")) kill_tincd = SIGHUP; @@ -175,6 +176,7 @@ static void parse_options(int argc, char **argv, char **envp) } } else kill_tincd = SIGTERM; +#endif break; case 'n': /* net name given */