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_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
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"
*/
int daemon(int nochdir, int noclose)
{
+#ifdef HAVE_FORK
pid_t pid;
int fd;
}
return 0;
+#else
+ return -1;
+#endif
}
#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
#include "system.h"
+#ifndef HAVE_MINGW
/* read_pid
*
* Reads the specified pidfile and returns the read pid.
errno = 0;
if (kill(pid, 0) && errno == ESRCH)
return(0);
+#endif
return pid;
}
{
return unlink (pidfile);
}
-
+#endif
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.
* is returned
*/
int remove_pid (char *pidfile);
+#endif
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"
logmode = mode;
switch(mode) {
- case LOGMODE_NULL:
- break;
case LOGMODE_STDERR:
logpid = getpid();
break;
logmode = LOGMODE_NULL;
break;
case LOGMODE_SYSLOG:
+#ifdef HAVE_SYSLOG
openlog(logident, LOG_CONS | LOG_PID, LOG_DAEMON);
break;
+#endif
+ case LOGMODE_NULL:
+ break;
}
}
va_start(ap, format);
switch(logmode) {
- case LOGMODE_NULL:
- break;
case LOGMODE_STDERR:
vfprintf(stderr, format, ap);
fprintf(stderr, "\n");
fprintf(logfile, "\n");
break;
case LOGMODE_SYSLOG:
+#ifdef HAVE_SYSLOG
#ifdef HAVE_VSYSLOG
vsyslog(priority, format, ap);
#else
}
#endif
break;
+#endif
+ case LOGMODE_NULL:
+ break;
}
va_end(ap);
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;
}
}
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)));
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 "utils.h"
#include "xalloc.h"
+#ifdef WSAEINPROGRESS
+#define EINPROGRESS WSAEINPROGRESS
+#endif
+
int addressfamily = AF_UNSPEC;
int maxtimeout = 900;
int seconds_till_retry = 5;
char *addrstr;
int option;
char *iface;
+#ifdef SO_BINDTODEVICE
struct ifreq ifr;
+#endif
cp();
return -1;
}
+#ifdef O_NONBLOCK
flags = fcntl(nfd, F_GETFL);
if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
strerror(errno));
return -1;
}
+#endif
/* Optimize TCP settings */
return -1;
}
+#ifdef O_NONBLOCK
flags = fcntl(nfd, F_GETFL);
if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
close(nfd);
strerror(errno));
return -1;
}
+#endif
option = 1;
setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
/* 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 */
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"
exit(c);
}
+#ifndef HAVE_MINGW
/*
check for an existing tinc for this net, and write pid to pidfile
*/
return true;
}
+#endif
/*
kill older tincd for this net
*/
bool kill_other(int signal)
{
+#ifndef HAVE_MINGW
int pid;
cp();
fprintf(stderr, _("Removing stale lock file.\n"));
remove_pid(pidfilename);
}
+#endif
return true;
}
/* 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"),
if(!write_pid(pidfilename))
return false;
}
+#endif
openlogger(identname, use_logfile?LOGMODE_FILE:(do_detach?LOGMODE_SYSLOG:LOGMODE_STDERR));
return true;
}
+#ifdef HAVE_FORK
/*
Execute the program name, with sane environment.
*/
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;
/* Child here */
_execute_script(scriptname, envp);
+#else
+ return true;
+#endif
}
Signal handlers.
*/
+#ifndef HAVE_MINGW
static RETSIGTYPE sigterm_handler(int a)
{
logger(LOG_NOTICE, _("Got TERM signal"));
{SIGWINCH, sigwinch_handler},
{0, NULL}
};
+#endif
void setup_signals(void)
{
+#ifndef HAVE_MINGW
int i;
struct sigaction act;
sighandlers[i].signal, strsignal(sighandlers[i].signal),
strerror(errno));
}
+#endif
}
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"
break;
case 'k': /* kill old tincds */
+#ifndef HAVE_MINGW
if(optarg) {
if(!strcasecmp(optarg, "HUP"))
kill_tincd = SIGHUP;
}
} else
kill_tincd = SIGTERM;
+#endif
break;
case 'n': /* net name given */