More checks for missing functions.

This commit is contained in:
Guus Sliepen 2003-07-28 22:06:09 +00:00
parent c15e8a96bf
commit 0e94541331
9 changed files with 83 additions and 15 deletions

View file

@ -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

View 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.
$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

View file

@ -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

View file

@ -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

View 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.
$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;
}
}

View file

@ -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)));

View 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.
$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 */

View 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.
$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
}

View 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.
$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 */