More checks for missing functions.
authorGuus Sliepen <guus@tinc-vpn.org>
Mon, 28 Jul 2003 22:06:09 +0000 (22:06 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Mon, 28 Jul 2003 22:06:09 +0000 (22:06 +0000)
configure.in
lib/dropin.c
lib/pidfile.c
lib/pidfile.h
src/logger.c
src/logger.h
src/net_socket.c
src/process.c
src/tincd.c

index 7850ac9..def2423 100644 (file)
@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 
 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)
 
 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_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
 
 jm_FUNC_MALLOC
 jm_FUNC_REALLOC
 
index 0a8ae6e..c92c0b8 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     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"
 */
 
 #include "system.h"
@@ -40,6 +40,7 @@
 */
 int daemon(int nochdir, int noclose)
 {
 */
 int daemon(int nochdir, int noclose)
 {
+#ifdef HAVE_FORK
        pid_t pid;
        int fd;
 
        pid_t pid;
        int fd;
 
@@ -82,6 +83,9 @@ int daemon(int nochdir, int noclose)
        }
 
        return 0;
        }
 
        return 0;
+#else
+       return -1;
+#endif
 }
 #endif
 
 }
 #endif
 
@@ -147,3 +151,11 @@ int asprintf(char **buf, const char *fmt, ...)
        return status;
 }
 #endif
        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
index 2dea70b..4a7276d 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "system.h"
 
 
 #include "system.h"
 
+#ifndef HAVE_MINGW
 /* read_pid
  *
  * Reads the specified pidfile and returns the read pid.
 /* 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);
   errno = 0;
   if (kill(pid, 0) && errno == ESRCH)
          return(0);
+#endif
 
   return pid;
 }
 
   return pid;
 }
@@ -127,4 +129,4 @@ int remove_pid (char *pidfile)
 {
   return unlink (pidfile);
 }
 {
   return unlink (pidfile);
 }
-  
+#endif
index 19d19c1..d428d48 100644 (file)
@@ -19,6 +19,7 @@
     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
 */
 
     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.
 /* 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);
  * is returned
  */
 int remove_pid (char *pidfile);
+#endif
index 032349d..1f7785f 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     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"
 */
 
 #include "system.h"
@@ -37,8 +37,6 @@ void openlogger(const char *ident, logmode_t mode) {
        logmode = mode;
        
        switch(mode) {
        logmode = mode;
        
        switch(mode) {
-               case LOGMODE_NULL:
-                       break;
                case LOGMODE_STDERR:
                        logpid = getpid();
                        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:
                                logmode = LOGMODE_NULL;
                        break;
                case LOGMODE_SYSLOG:
+#ifdef HAVE_SYSLOG
                        openlog(logident, LOG_CONS | LOG_PID, LOG_DAEMON);
                        break;
                        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) {
        va_start(ap, format);
 
        switch(logmode) {
-               case LOGMODE_NULL:
-                       break;
                case LOGMODE_STDERR:
                        vfprintf(stderr, format, ap);
                        fprintf(stderr, "\n");
                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:
                        fprintf(logfile, "\n");
                        break;
                case LOGMODE_SYSLOG:
+#ifdef HAVE_SYSLOG
 #ifdef HAVE_VSYSLOG
                        vsyslog(priority, format, ap);
 #else
 #ifdef HAVE_VSYSLOG
                        vsyslog(priority, format, ap);
 #else
@@ -82,6 +83,9 @@ void logger(int priority, const char *format, ...) {
                        }
 #endif
                        break;
                        }
 #endif
                        break;
+#endif
+               case LOGMODE_NULL:
+                       break;
        }
 
        va_end(ap);
        }
 
        va_end(ap);
@@ -89,14 +93,17 @@ void logger(int priority, const char *format, ...) {
 
 void closelogger(void) {
        switch(logmode) {
 
 void closelogger(void) {
        switch(logmode) {
-               case LOGMODE_NULL:
-               case LOGMODE_STDERR:
-                       break;
                case LOGMODE_FILE:
                        fclose(logfile);
                        break;
                case LOGMODE_SYSLOG:
                case LOGMODE_FILE:
                        fclose(logfile);
                        break;
                case LOGMODE_SYSLOG:
+#ifdef HAVE_SYSLOG
                        closelog();
                        break;
                        closelog();
                        break;
+#endif
+               case LOGMODE_NULL:
+               case LOGMODE_STDERR:
+                       break;
+                       break;
        }
 }
        }
 }
index eb02fb8..c2672c6 100644 (file)
@@ -20,6 +20,19 @@ typedef enum logmode_t {
        LOGMODE_SYSLOG
 } 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)));
 extern debug_t debug_level;
 extern void openlogger(const char *, logmode_t);
 extern void logger(int, const char *, ...) __attribute__ ((format(printf, 2, 3)));
index aa7d3d9..5f9e217 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     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"
 */
 
 #include "system.h"
 #include "utils.h"
 #include "xalloc.h"
 
 #include "utils.h"
 #include "xalloc.h"
 
+#ifdef WSAEINPROGRESS
+#define EINPROGRESS WSAEINPROGRESS
+#endif
+
 int addressfamily = AF_UNSPEC;
 int maxtimeout = 900;
 int seconds_till_retry = 5;
 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;
        char *addrstr;
        int option;
        char *iface;
+#ifdef SO_BINDTODEVICE
        struct ifreq ifr;
        struct ifreq ifr;
+#endif
 
        cp();
 
 
        cp();
 
@@ -60,6 +66,7 @@ int setup_listen_socket(const sockaddr_t *sa)
                return -1;
        }
 
                return -1;
        }
 
+#ifdef O_NONBLOCK
        flags = fcntl(nfd, F_GETFL);
 
        if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
        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;
        }
                           strerror(errno));
                return -1;
        }
+#endif
 
        /* Optimize TCP settings */
 
 
        /* Optimize TCP settings */
 
@@ -138,6 +146,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa)
                return -1;
        }
 
                return -1;
        }
 
+#ifdef O_NONBLOCK
        flags = fcntl(nfd, F_GETFL);
        if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
                close(nfd);
        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;
        }
                           strerror(errno));
                return -1;
        }
+#endif
 
        option = 1;
        setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
 
        option = 1;
        setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
@@ -280,11 +290,13 @@ begin:
 
        /* Non-blocking */
 
 
        /* 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));
        }
        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 */
 
 
        /* Connect */
 
index 218df76..36b2146 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     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"
 */
 
 #include "system.h"
@@ -88,6 +88,7 @@ void cleanup_and_exit(int c)
        exit(c);
 }
 
        exit(c);
 }
 
+#ifndef HAVE_MINGW
 /*
   check for an existing tinc for this net, and write pid to pidfile
 */
 /*
   check for an existing tinc for this net, and write pid to pidfile
 */
@@ -114,12 +115,14 @@ static bool write_pidfile(void)
 
        return true;
 }
 
        return true;
 }
+#endif
 
 /*
   kill older tincd for this net
 */
 bool kill_other(int signal)
 {
 
 /*
   kill older tincd for this net
 */
 bool kill_other(int signal)
 {
+#ifndef HAVE_MINGW
        int pid;
 
        cp();
        int pid;
 
        cp();
@@ -148,6 +151,7 @@ bool kill_other(int signal)
                fprintf(stderr, _("Removing stale lock file.\n"));
                remove_pid(pidfilename);
        }
                fprintf(stderr, _("Removing stale lock file.\n"));
                remove_pid(pidfilename);
        }
+#endif
 
        return true;
 }
 
        return true;
 }
@@ -163,13 +167,16 @@ bool detach(void)
 
        /* First check if we can open a fresh new pidfile */
 
 
        /* First check if we can open a fresh new pidfile */
 
+#ifndef HAVE_MINGW
        if(!write_pidfile())
                return false;
        if(!write_pidfile())
                return false;
+#endif
 
        /* If we succeeded in doing that, detach */
 
        closelogger();
 
 
        /* 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"),
        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;
        }
                if(!write_pid(pidfilename))
                        return false;
        }
+#endif
 
        openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR));
 
 
        openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR));
 
@@ -193,6 +201,7 @@ bool detach(void)
        return true;
 }
 
        return true;
 }
 
+#ifdef HAVE_FORK
 /*
   Execute the program name, with sane environment.
 */
 /*
   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);
 }
                   strerror(save_errno));
        exit(save_errno);
 }
+#endif
 
 /*
   Fork and execute the program pointed to by name.
 */
 bool execute_script(const char *name, char **envp)
 {
 
 /*
   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;
        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);
        /* Child here */
 
        _execute_script(scriptname, envp);
+#else
+       return true;
+#endif
 }
 
 
 }
 
 
@@ -294,6 +308,7 @@ bool execute_script(const char *name, char **envp)
   Signal handlers.
 */
 
   Signal handlers.
 */
 
+#ifndef HAVE_MINGW
 static RETSIGTYPE sigterm_handler(int a)
 {
        logger(LOG_NOTICE, _("Got TERM signal"));
 static RETSIGTYPE sigterm_handler(int a)
 {
        logger(LOG_NOTICE, _("Got TERM signal"));
@@ -415,9 +430,11 @@ static struct {
        {SIGWINCH, sigwinch_handler},
        {0, NULL}
 };
        {SIGWINCH, sigwinch_handler},
        {0, NULL}
 };
+#endif
 
 void setup_signals(void)
 {
 
 void setup_signals(void)
 {
+#ifndef HAVE_MINGW
        int i;
        struct sigaction act;
 
        int i;
        struct sigaction act;
 
@@ -449,4 +466,5 @@ void setup_signals(void)
                                        sighandlers[i].signal, strsignal(sighandlers[i].signal),
                                        strerror(errno));
        }
                                        sighandlers[i].signal, strsignal(sighandlers[i].signal),
                                        strerror(errno));
        }
+#endif
 }
 }
index b9f9f4f..d2179ab 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     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"
 */
 
 #include "system.h"
@@ -147,6 +147,7 @@ static void parse_options(int argc, char **argv, char **envp)
                                break;
 
                        case 'k':                               /* kill old tincds */
                                break;
 
                        case 'k':                               /* kill old tincds */
+#ifndef HAVE_MINGW
                                if(optarg) {
                                        if(!strcasecmp(optarg, "HUP"))
                                                kill_tincd = SIGHUP;
                                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;
                                        }
                                } else
                                        kill_tincd = SIGTERM;
+#endif
                                break;
 
                        case 'n':                               /* net name given */
                                break;
 
                        case 'n':                               /* net name given */