浏览代码

- converted to autoconf compatible format (replaced some os specific ifdefs with HAVE_xxx a.s.o)

Andrei Pelinescu-Onciul 23 年之前
父节点
当前提交
087d09764c
共有 8 个文件被更改,包括 51 次插入36 次删除
  1. 1 1
      INSTALL
  2. 24 12
      Makefile.defs
  3. 6 6
      fastlock.h
  4. 6 6
      ip_addr.h
  5. 5 5
      main.c
  6. 1 3
      mem/shm_mem.c
  7. 5 3
      resolve.h
  8. 3 0
      sr_module.c

+ 1 - 1
INSTALL

@@ -4,7 +4,7 @@ $Id$
 Installation Notes
 Installation Notes
 
 
 Supported arhitectures: Linux/i386, Linux/armv4l, FreeBSD/i386,
 Supported arhitectures: Linux/i386, Linux/armv4l, FreeBSD/i386,
-Solaris/sparc64, Win*/i386 (CYGWIN) - only the core
+Solaris/sparc64 
 (for other arhitectures the Makefile must be edited)
 (for other arhitectures the Makefile must be edited)
 
 
 There are various configuration options defined in the Makefile.
 There are various configuration options defined in the Makefile.

+ 24 - 12
Makefile.defs

@@ -12,7 +12,8 @@ EXTRAVERSION =
 
 
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
-ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/ )
+ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc/  \
+			-e s/armv4l/arm/)
 
 
  # install location
  # install location
 PREFIX = /usr/local
 PREFIX = /usr/local
@@ -126,7 +127,7 @@ YACC := $(shell echo "$${YACC}")
 #  		forking (done at the top of main_loop). Needed if you want
 #  		forking (done at the top of main_loop). Needed if you want
 #  		to use the snmp module.
 #  		to use the snmp module.
 DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
 DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
-	 -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"' \
+	 -DOS='"$(OS)"' -DCOMPILER='"$(CC_VER)"' -D__CPU_$(ARCH)\
 	 -DCFG_DIR='"$(cfg-target)"'\
 	 -DCFG_DIR='"$(cfg-target)"'\
 	 -DPKG_MALLOC \
 	 -DPKG_MALLOC \
 	 -DSHM_MEM  -DSHM_MMAP \
 	 -DSHM_MEM  -DSHM_MMAP \
@@ -214,7 +215,7 @@ $(warning	Unknown compiler $(CC)\; supported compilers: \
 endif
 endif
 
 
 # find ldname (gnu or solaris)
 # find ldname (gnu or solaris)
-ifeq ($(ARCH), sparc64)
+ifeq ($(ARCH), sparc)
 ifeq ($(CC_NAME), gcc)
 ifeq ($(CC_NAME), gcc)
 		LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
 		LDGCC=$(shell $(CC) -v 2>&1 | grep with-ld| \
 				   sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
 				   sed -e 's/.*--with-ld=\([^ ][^ ]*\).*/\1/' )
@@ -245,13 +246,13 @@ ifeq ($(ARCH), i386)
 	DEFS+= -DFAST_LOCK
 	DEFS+= -DFAST_LOCK
 endif
 endif
 
 
-ifeq ($(ARCH), sparc64)
+ifeq ($(ARCH), sparc)
 ifeq 	($(CC_NAME), gcc)
 ifeq 	($(CC_NAME), gcc)
 		DEFS+= -DFAST_LOCK
 		DEFS+= -DFAST_LOCK
 endif
 endif
 endif
 endif
 
 
-ifeq ($(ARCH), armv4l)
+ifeq ($(ARCH), arm)
 	DEFS+= -DFAST_LOCK
 	DEFS+= -DFAST_LOCK
 endif
 endif
 
 
@@ -302,8 +303,8 @@ endif		#CC_NAME, gcc
 endif	#ARCH, i386
 endif	#ARCH, i386
 
 
 
 
-	#if sparc64
-ifeq	($(ARCH), sparc64)
+	#if sparc
+ifeq	($(ARCH), sparc)
 			#if gcc
 			#if gcc
 ifeq		($(CC_NAME), gcc)
 ifeq		($(CC_NAME), gcc)
 				#common stuff
 				#common stuff
@@ -344,10 +345,10 @@ else
 $(error 			Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
 $(error 			Unsupported compiler ($(CC):$(CC_NAME)), try gcc)
 endif		#CC_NAME, suncc
 endif		#CC_NAME, suncc
 endif		#CC_NAME, gcc
 endif		#CC_NAME, gcc
-endif	#ARCH, sparc64
+endif	#ARCH, sparc
 
 
 	#if ipaq/netwinder
 	#if ipaq/netwinder
-ifeq	($(ARCH), armv4l)
+ifeq	($(ARCH), arm)
 		# if gcc 
 		# if gcc 
 ifeq		($(CC_NAME), gcc)
 ifeq		($(CC_NAME), gcc)
 				#common stuff
 				#common stuff
@@ -383,7 +384,7 @@ endif	#ARCH, i386
 LDFLAGS=
 LDFLAGS=
 # setting LDFLAGS
 # setting LDFLAGS
 ifeq	($(CC_NAME), gcc)
 ifeq	($(CC_NAME), gcc)
-ifeq		($(ARCH), sparc64)
+ifeq		($(ARCH), sparc)
 ifeq			($(LDTYPE), solaris)
 ifeq			($(LDTYPE), solaris)
 					# solaris ld
 					# solaris ld
 					LDFLAGS+=-O2 $(PROFILE)
 					LDFLAGS+=-O2 $(PROFILE)
@@ -414,7 +415,7 @@ endif
 else	#mode,release
 else	#mode,release
 ifeq	($(CC_NAME), gcc)
 ifeq	($(CC_NAME), gcc)
 		CFLAGS=-g -Wcast-align -Winline $(PROFILE)
 		CFLAGS=-g -Wcast-align -Winline $(PROFILE)
-ifeq		($(ARCH), sparc64)
+ifeq		($(ARCH), sparc)
 			CFLAGS+= -mcpu=ultrasparc 
 			CFLAGS+= -mcpu=ultrasparc 
 endif
 endif
 ifeq		($(LDTYPE), solaris)
 ifeq		($(LDTYPE), solaris)
@@ -462,6 +463,10 @@ YACC_FLAGS=-d -b cfg
 # on solaris add -lxnet (e.g. LIBS= -lxnet)
 # on solaris add -lxnet (e.g. LIBS= -lxnet)
 LIBS= -lfl -ldl -lresolv
 LIBS= -lfl -ldl -lresolv
 
 
+ifneq ($(OS), solaris)
+	DEFS+=-DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN
+endif
+
 
 
 #os specific stuff
 #os specific stuff
 ifeq ($(OS), Linux)
 ifeq ($(OS), Linux)
@@ -469,6 +474,7 @@ ifeq ($(OS), Linux)
 endif
 endif
 
 
 ifeq  ($(OS), solaris)
 ifeq  ($(OS), solaris)
+	DEFS+= -DHAVE_GETIPNODEBYNAME -DHAVE_SYS_SOCKIO_H
 	ifeq ($(mode), release)
 	ifeq ($(mode), release)
 		#use these only if you're using gcc with Solaris ld
 		#use these only if you're using gcc with Solaris ld
 		#LDFLAGS=-O2 $(PROFILE)
 		#LDFLAGS=-O2 $(PROFILE)
@@ -488,11 +494,17 @@ endif
 endif
 endif
 
 
 ifeq ($(OS), freebsd)
 ifeq ($(OS), freebsd)
-
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN
 	YACC=yacc
 	YACC=yacc
 	LIBS= -lfl  #dlopen is in libc
 	LIBS= -lfl  #dlopen is in libc
+endif
 
 
+ifeq ($(OS), openbsd)
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN
+	YACC=yacc
+	LIBS= -lfl  -lc_r
 endif
 endif
+	
 
 
 ifneq (,$(findstring CYGWIN, $(OS)))
 ifneq (,$(findstring CYGWIN, $(OS)))
 	#cygwin is the same as common
 	#cygwin is the same as common

+ 6 - 6
fastlock.h

@@ -54,7 +54,7 @@ inline static int tsl(fl_lock_t* lock)
 {
 {
 	int val;
 	int val;
 
 
-#ifdef __i386
+#ifdef __CPU_i386
 
 
 #ifdef NOSMP
 #ifdef NOSMP
 	val=0;
 	val=0;
@@ -69,7 +69,7 @@ inline static int tsl(fl_lock_t* lock)
 		" xchg %b1, %0" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"
 		" xchg %b1, %0" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"
 	);
 	);
 #endif /*NOSMP*/
 #endif /*NOSMP*/
-#elif defined __sparc
+#elif defined __CPU_sparc
 	asm volatile(
 	asm volatile(
 			"ldstub [%1], %0 \n\t"
 			"ldstub [%1], %0 \n\t"
 #ifndef NOSMP
 #ifndef NOSMP
@@ -78,7 +78,7 @@ inline static int tsl(fl_lock_t* lock)
 			: "=r"(val) : "r"(lock):"memory"
 			: "=r"(val) : "r"(lock):"memory"
 	);
 	);
 	
 	
-#elif defined __arm__
+#elif defined __CPU_arm
 	asm volatile(
 	asm volatile(
 			"# here \n\t"
 			"# here \n\t"
 			"swpb %0, %1, [%2] \n\t"
 			"swpb %0, %1, [%2] \n\t"
@@ -115,14 +115,14 @@ inline static void get_lock(fl_lock_t* lock)
 
 
 inline static void release_lock(fl_lock_t* lock)
 inline static void release_lock(fl_lock_t* lock)
 {
 {
-#ifdef __i386
+#ifdef __CPU_i386
 	char val;
 	char val;
 	val=0;
 	val=0;
 	asm volatile(
 	asm volatile(
 		" movb $0, (%0)" : /*no output*/ : "r"(lock): "memory"
 		" movb $0, (%0)" : /*no output*/ : "r"(lock): "memory"
 		/*" xchg %b0, %1" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"*/
 		/*" xchg %b0, %1" : "=q" (val), "=m" (*lock) : "0" (val) : "memory"*/
 	); 
 	); 
-#elif defined __sparc
+#elif defined __CPU_sparc
 	asm volatile(
 	asm volatile(
 #ifndef NOSMP
 #ifndef NOSMP
 			"membar #LoadStore | #StoreStore \n\t" /*is this really needed?*/
 			"membar #LoadStore | #StoreStore \n\t" /*is this really needed?*/
@@ -132,7 +132,7 @@ inline static void release_lock(fl_lock_t* lock)
 			: "r" (lock)
 			: "r" (lock)
 			: "memory"
 			: "memory"
 	);
 	);
-#elif defined __arm__
+#elif defined __CPU_arm
 	asm volatile(
 	asm volatile(
 		" str %0, [%1] \n\r" 
 		" str %0, [%1] \n\r" 
 		: /*no outputs*/ 
 		: /*no outputs*/ 

+ 6 - 6
ip_addr.h

@@ -84,7 +84,7 @@ struct socket_info{
 
 
 
 
 /* len of the sockaddr */
 /* len of the sockaddr */
-#ifdef __FreeBSD__
+#ifdef HAVE_SOCKADDR_SA_LEN
 #define sockaddru_len(su)	((su).s.sa_len)
 #define sockaddru_len(su)	((su).s.sa_len)
 #else
 #else
 #ifdef USE_IPV6
 #ifdef USE_IPV6
@@ -94,7 +94,7 @@ struct socket_info{
 #else
 #else
 #define sockaddru_len(su)	sizeof(struct sockaddr_in)
 #define sockaddru_len(su)	sizeof(struct sockaddr_in)
 #endif /*USE_IPV6*/
 #endif /*USE_IPV6*/
-#endif /*__FreeBSD__*/
+#endif /* HAVE_SOCKADDR_SA_LEN*/
 	
 	
 /* inits an ip_addr with the addr. info from a hostent structure
 /* inits an ip_addr with the addr. info from a hostent structure
  * ip = struct ip_addr*
  * ip = struct ip_addr*
@@ -217,7 +217,7 @@ static inline int init_su( union sockaddr_union* su,
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 	case	AF_INET6:
 	case	AF_INET6:
 		memcpy(&su->sin6.sin6_addr, ip->u.addr, ip->len); 
 		memcpy(&su->sin6.sin6_addr, ip->u.addr, ip->len); 
-		#ifdef __FreeBSD__
+		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
 		#endif
 		#endif
 		su->sin6.sin6_port=port;
 		su->sin6.sin6_port=port;
@@ -225,7 +225,7 @@ static inline int init_su( union sockaddr_union* su,
 #endif
 #endif
 	case AF_INET:
 	case AF_INET:
 		memcpy(&su->sin.sin_addr, ip->u.addr, ip->len);
 		memcpy(&su->sin.sin_addr, ip->u.addr, ip->len);
-		#ifdef __FreeBSD__
+		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin.sin_len=sizeof(struct sockaddr_in);
 			su->sin.sin_len=sizeof(struct sockaddr_in);
 		#endif
 		#endif
 		su->sin.sin_port=port;
 		su->sin.sin_port=port;
@@ -254,7 +254,7 @@ static inline int hostent2su( union sockaddr_union* su,
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 	case	AF_INET6:
 	case	AF_INET6:
 		memcpy(&su->sin6.sin6_addr, he->h_addr_list[idx], he->h_length);
 		memcpy(&su->sin6.sin6_addr, he->h_addr_list[idx], he->h_length);
-		#ifdef __FreeBSD__
+		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
 			su->sin6.sin6_len=sizeof(struct sockaddr_in6);
 		#endif
 		#endif
 		su->sin6.sin6_port=port;
 		su->sin6.sin6_port=port;
@@ -262,7 +262,7 @@ static inline int hostent2su( union sockaddr_union* su,
 #endif
 #endif
 	case AF_INET:
 	case AF_INET:
 		memcpy(&su->sin.sin_addr, he->h_addr_list[idx], he->h_length);
 		memcpy(&su->sin.sin_addr, he->h_addr_list[idx], he->h_length);
-		#ifdef __FreeBSD__
+		#ifdef HAVE_SOCKADDR_SA_LEN
 			su->sin.sin_len=sizeof(struct sockaddr_in);
 			su->sin.sin_len=sizeof(struct sockaddr_in);
 		#endif
 		#endif
 		su->sin.sin_port=port;
 		su->sin.sin_port=port;

+ 5 - 5
main.c

@@ -48,7 +48,7 @@
 
 
 #include <sys/ioctl.h>
 #include <sys/ioctl.h>
 #include <net/if.h>
 #include <net/if.h>
-#ifdef __sun
+#ifdef HAVE_SYS_SOCKIO_H
 #include <sys/sockio.h>
 #include <sys/sockio.h>
 #endif
 #endif
 
 
@@ -82,7 +82,7 @@
 
 
 static char id[]="@(#) $Id$";
 static char id[]="@(#) $Id$";
 static char version[]=  NAME " " VERSION " (" ARCH "/" OS ")" ;
 static char version[]=  NAME " " VERSION " (" ARCH "/" OS ")" ;
-static char compiled[]= __TIME__ " " __DATE__ ;
+static char compiled[]= __TIME__ __DATE__ ;
 static char flags[]=
 static char flags[]=
 "STATS:"
 "STATS:"
 #ifdef STATS
 #ifdef STATS
@@ -389,7 +389,7 @@ int daemonize(char*  name)
 	}
 	}
 	
 	
 	if (log_stderr==0)
 	if (log_stderr==0)
-		openlog(name, LOG_PID|LOG_CONS, LOG_LOCAL1 /*LOG_DAEMON*/);
+		openlog(name, LOG_PID|LOG_CONS, LOG_DAEMON);
 		/* LOG_CONS, LOG_PERRROR ? */
 		/* LOG_CONS, LOG_PERRROR ? */
 	return  0;
 	return  0;
 
 
@@ -757,7 +757,7 @@ int add_interfaces(char* if_name, int family, unsigned short port)
 	struct ip_addr addr;
 	struct ip_addr addr;
 	int ret;
 	int ret;
 
 
-#ifdef __FreeBSD__
+#ifdef HAVE_SOCKADDR_SA_LEN
 	#define MAX(a,b) ( ((a)>(b))?(a):(b))
 	#define MAX(a,b) ( ((a)>(b))?(a):(b))
 #endif
 #endif
 	/* ipv4 or ipv6 only*/
 	/* ipv4 or ipv6 only*/
@@ -787,7 +787,7 @@ int add_interfaces(char* if_name, int family, unsigned short port)
 	last=(char*)ifc.ifc_req+ifc.ifc_len;
 	last=(char*)ifc.ifc_req+ifc.ifc_len;
 	for(ifr=ifc.ifc_req; (char*)ifr<last;
 	for(ifr=ifc.ifc_req; (char*)ifr<last;
 			ifr=(struct ifreq*)((char*)ifr+sizeof(ifr->ifr_name)+
 			ifr=(struct ifreq*)((char*)ifr+sizeof(ifr->ifr_name)+
-			#ifdef  __FreeBSD__
+			#ifdef  HAVE_SOCKADDR_SA_LEN
 				MAX(ifr->ifr_addr.sa_len, sizeof(struct sockaddr))
 				MAX(ifr->ifr_addr.sa_len, sizeof(struct sockaddr))
 			#else
 			#else
 				( (ifr->ifr_addr.sa_family==AF_INET)?
 				( (ifr->ifr_addr.sa_family==AF_INET)?

+ 1 - 3
mem/shm_mem.c

@@ -53,10 +53,9 @@
 
 
 
 
 /* define semun */
 /* define semun */
-#if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
+#if defined(HAVE_UNION_SEMUN) && !defined(_SEM_SEMUN_UNDEFINED)
 	/* union semun is defined by including <sys/sem.h> */
 	/* union semun is defined by including <sys/sem.h> */
 #else
 #else
-#ifndef __FreeBSD__
 	/* according to X/OPEN we have to define it ourselves */
 	/* according to X/OPEN we have to define it ourselves */
 	union semun {
 	union semun {
 		int val;                    /* value for SETVAL */
 		int val;                    /* value for SETVAL */
@@ -65,7 +64,6 @@
 		struct seminfo *__buf;      /* buffer for IPC_INFO */
 		struct seminfo *__buf;      /* buffer for IPC_INFO */
 	};
 	};
 #endif
 #endif
-#endif
 
 
 
 
 
 

+ 5 - 3
resolve.h

@@ -250,7 +250,7 @@ struct hostent* sip_resolvehost(char* name, unsigned short* port);
 static inline struct hostent* resolvehost(const char* name)
 static inline struct hostent* resolvehost(const char* name)
 {
 {
 	static struct hostent* he=0;
 	static struct hostent* he=0;
-#ifdef __sun
+#ifdef HAVE_GETIPNODEBYNAME 
 	int err;
 	int err;
 	static struct hostent* he2=0;
 	static struct hostent* he2=0;
 #endif
 #endif
@@ -275,14 +275,16 @@ static inline struct hostent* resolvehost(const char* name)
 #ifdef USE_IPV6
 #ifdef USE_IPV6
 	if(he==0){
 	if(he==0){
 		/*try ipv6*/
 		/*try ipv6*/
-	#ifdef __sun
+	#ifdef HAVE_GETHOSTBYNAME2
+		he=gethostbyname2(name, AF_INET6);
+	#elif defined HAVE_GETIPNODEBYNAME
 		/* on solaris 8 getipnodebyname has a memory leak,
 		/* on solaris 8 getipnodebyname has a memory leak,
 		 * after some time calls to it will fail with err=3
 		 * after some time calls to it will fail with err=3
 		 * solution: patch your solaris 8 installation */
 		 * solution: patch your solaris 8 installation */
 		if (he2) freehostent(he2);
 		if (he2) freehostent(he2);
 		he=he2=getipnodebyname(name, AF_INET6, 0, &err);
 		he=he2=getipnodebyname(name, AF_INET6, 0, &err);
 	#else
 	#else
-		he=gethostbyname2(name, AF_INET6);
+		#error neither gethostbyname2 or getipnodebyname present
 	#endif
 	#endif
 	}
 	}
 #endif
 #endif

+ 3 - 0
sr_module.c

@@ -166,6 +166,9 @@ int load_module(char* path)
 	struct module_exports* exp;
 	struct module_exports* exp;
 	struct sr_module* t;
 	struct sr_module* t;
 	
 	
+#ifndef RTLD_NOW
+#define RTLD_NOW DL_LAZY
+#endif
 	handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */
 	handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */
 	if (handle==0){
 	if (handle==0){
 		LOG(L_ERR, "ERROR: load_module: could not open module <%s>: %s\n",
 		LOG(L_ERR, "ERROR: load_module: could not open module <%s>: %s\n",