Browse code

- some free twice in case of load failure in sms module fixed (harmless) - experimental support for Darwin (Mac OS X) added: Make* changed, s/lock_set_t/gen_lock_set_t/ due to a type conflict with one of the Darwin includes, special include for resolve.h, MAP_ANON used for shared memory mmap (mmap /dev/zero doesn't work), a.s.o

Andrei Pelinescu-Onciul authored on 26/07/2004 23:18:34
Showing 11 changed files
... ...
@@ -81,7 +81,6 @@ modules_basenames=$(shell echo $(modules)| \
81 81
 #modules_names=$(patsubst modules/%, %.so, $(modules))
82 82
 modules_full_path=$(join  $(modules), $(addprefix /, $(modules_names)))
83 83
 
84
-NAME=ser
85 84
 
86 85
 ALLDEP=Makefile Makefile.sources Makefile.defs Makefile.rules
87 86
 
... ...
@@ -92,6 +91,8 @@ makefile_defs=0
92 91
 DEFS:=
93 92
 include Makefile.defs
94 93
 
94
+NAME=$(MAIN_NAME)
95
+
95 96
 #export relevant variables to the sub-makes
96 97
 export DEFS PROFILE CC  LD MKDEP MKTAGS CFLAGS LDFLAGS MOD_CFLAGS MOD_LDFLAGS
97 98
 export LEX YACC YACC_FLAGS
... ...
@@ -31,6 +31,7 @@
31 31
 #              code exists (sobomax)
32 32
 #  2003-11-08  mips1 support introduced (andrei)
33 33
 #  2003-11-24  openbsd 3.4 (elf) fixes (andrei)
34
+#  2004-07-27  darwin (mac os x) port  (andrei)
34 35
 
35 36
 
36 37
 # check if already included/exported
... ...
@@ -40,17 +41,19 @@ else
40 41
 makefile_defs=1
41 42
 export makefile_defs
42 43
 
44
+# main binary name
45
+MAIN_NAME=ser
43 46
 
44 47
 #version number
45 48
 VERSION = 0
46 49
 PATCHLEVEL = 8
47 50
 SUBLEVEL =   14
48
-EXTRAVERSION = -rc2
51
+EXTRAVERSION = -rc3
49 52
 
50 53
 RELEASE=$(VERSION).$(PATCHLEVEL).$(SUBLEVEL)$(EXTRAVERSION)
51 54
 OS = $(shell uname -s | sed -e s/SunOS/solaris/ | tr "[A-Z]" "[a-z]")
52 55
 ARCH = $(shell uname -m |sed -e s/i.86/i386/ -e s/sun4u/sparc64/  \
53
-			-e s/armv4l/arm/)
56
+			-e s/armv4l/arm/ -e "s/Power Macintosh/ppc/" )
54 57
 OSREL = $(shell uname -r)
55 58
 
56 59
 # TLS support
... ...
@@ -100,6 +103,10 @@ else
100 103
 ifeq ($(OS), netbsd)
101 104
 	doc-dir = share/doc/ser
102 105
 	man-dir = man/
106
+else
107
+ifeq ($(OS), darwin)
108
+	doc-dir = share/doc/ser/
109
+	man-dir = man/
103 110
 else
104 111
 	doc-dir = doc/ser/
105 112
 	man-dir = man/
... ...
@@ -107,6 +114,7 @@ endif
107 114
 endif
108 115
 endif
109 116
 endif
117
+endif
110 118
 ut-prefix = bin/
111 119
 # target dirs for various stuff
112 120
 cfg-target = $(prefix)/$(cfg-dir)
... ...
@@ -735,6 +743,26 @@ ifeq ($(OS), netbsd)
735 743
 	LIBS= -lfl 
736 744
 endif
737 745
 
746
+# OS X support, same as freebsd
747
+ifeq ($(OS), darwin)
748
+	DEFS+=-DHAVE_SOCKADDR_SA_LEN -DHAVE_GETHOSTBYNAME2 -DHAVE_UNION_SEMUN \
749
+		-DHAVE_SCHED_YIELD -DHAVE_MSGHDR_MSG_CONTROL \
750
+		-DUSE_ANON_MMAP \
751
+		-DNDEBUG
752
+	# -DNDEBUG used to turn off assert (assert wants to call
753
+	# eprintf which doesn't seem to be defined in any shared lib
754
+	ifneq ($(found_lock_method), yes)
755
+		DEFS+= -DUSE_PTHREAD_MUTEX  # try pthread sems
756
+		found_lock_method=yes
757
+		LIBS= -pthread -lfl -lresolv  #dlopen is in libc
758
+	else
759
+		LIBS= -lfl -lresolv  #dlopen is in libc
760
+	endif
761
+	LDFLAGS=        # darwin doesn't like -O2 or -E
762
+	MOD_LDFLAGS= -bundle -bundle_loader ../../$(MAIN_NAME)
763
+	YACC=yacc
764
+endif
765
+
738 766
 ifneq (,$(findstring CYGWIN, $(OS)))
739 767
 	#cygwin is the same as common
740 768
 	ifneq ($(found_lock_method), yes)
... ...
@@ -26,6 +26,8 @@ was created from the cvs stable tree (rel_0_8_12), so if you have an up-to-date
26 26
 New Features
27 27
 ============
28 28
 
29
+ - experimental OS X (darwin) support
30
+
29 31
 core:
30 32
  - basic avp support (no db conectivity yet)
31 33
 tm:
... ...
@@ -93,7 +93,7 @@ struct id_list{
93 93
 };
94 94
 
95 95
 extern int yylex();
96
-void yyerror(char* s);
96
+static void yyerror(char* s);
97 97
 static char* tmp;
98 98
 static int i_tmp;
99 99
 static void* f_tmp;
... ...
@@ -103,7 +103,7 @@ static str* str_tmp;
103 103
 static str s_tmp;
104 104
 static struct ip_addr* ip_tmp;
105 105
 
106
-void warn(char* s);
106
+static void warn(char* s);
107 107
  
108 108
 
109 109
 %}
... ...
@@ -1546,14 +1546,14 @@ cmd:		FORWARD LPAREN host RPAREN	{ $$=mk_action(	FORWARD_T,
1546 1546
 extern int line;
1547 1547
 extern int column;
1548 1548
 extern int startcolumn;
1549
-void warn(char* s)
1549
+static void warn(char* s)
1550 1550
 {
1551 1551
 	LOG(L_WARN, "cfg. warning: (%d,%d-%d): %s\n", line, startcolumn, 
1552 1552
 			column, s);
1553 1553
 	cfg_errors++;
1554 1554
 }
1555 1555
 
1556
-void yyerror(char* s)
1556
+static void yyerror(char* s)
1557 1557
 {
1558 1558
 	LOG(L_CRIT, "parse error (%d,%d-%d): %s\n", line, startcolumn, 
1559 1559
 			column, s);
... ...
@@ -28,9 +28,12 @@
28 28
 /*
29 29
  *   ser locking library
30 30
  *   WARNING: don't include this directly include instead locking.h!
31
- *
31
+ * History:
32
+ * --------
32 33
  *  2003-03-06  created by andrei (contains parts of the original locking.h)
33 34
  *  2003-03-17  fixed cast warning in shm_free (forced to void*) (andrei)
35
+ *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
36
+ *              on darwin (andrei)
34 37
  *
35 38
 Implements: (see also locking.h)
36 39
 
... ...
@@ -41,8 +44,8 @@ Implements: (see also locking.h)
41 44
 	
42 45
 	lock sets: [implemented only for FL & SYSV so far]
43 46
 	----------
44
-	lock_set_t* lock_set_alloc(no)               - allocs a lock set in shm.
45
-	void lock_set_dealloc(lock_set_t* s);        - deallocs the lock set shm.
47
+	gen_lock_set_t* lock_set_alloc(no)               - allocs a lock set in shm.
48
+	void lock_set_dealloc(gen_lock_set_t* s);        - deallocs the lock set shm.
46 49
 
47 50
 */
48 51
 
... ...
@@ -63,14 +66,14 @@ Implements: (see also locking.h)
63 66
 #define lock_dealloc(lock) shm_free((void*)lock)
64 67
 /* lock sets */
65 68
 
66
-inline static lock_set_t* lock_set_alloc(int n)
69
+inline static gen_lock_set_t* lock_set_alloc(int n)
67 70
 {
68
-	lock_set_t* ls;
69
-	ls=(lock_set_t*)shm_malloc(sizeof(lock_set_t)+n*sizeof(gen_lock_t));
71
+	gen_lock_set_t* ls;
72
+	ls=(gen_lock_set_t*)shm_malloc(sizeof(gen_lock_set_t)+n*sizeof(gen_lock_t));
70 73
 	if (ls==0){
71 74
 		LOG(L_CRIT, "ERROR: lock_set_alloc (FL): could not allocate lock_set\n");
72 75
 	}else{
73
-		ls->locks=(gen_lock_t*)((char*)ls+sizeof(lock_set_t));
76
+		ls->locks=(gen_lock_t*)((char*)ls+sizeof(gen_lock_set_t));
74 77
 		ls->size=n;
75 78
 	}
76 79
 	return ls;
... ...
@@ -85,10 +88,10 @@ inline static lock_set_t* lock_set_alloc(int n)
85 88
 #define lock_dealloc(lock) shm_free((void*)lock)
86 89
 /* lock sets */
87 90
 
88
-inline static lock_set_t* lock_set_alloc(int n)
91
+inline static gen_lock_set_t* lock_set_alloc(int n)
89 92
 {
90
-	lock_set_t* ls;
91
-	ls=(lock_set_t*)shm_malloc(sizeof(lock_set_t));
93
+	gen_lock_set_t* ls;
94
+	ls=(gen_lock_set_t*)shm_malloc(sizeof(gen_lock_set_t));
92 95
 	if (ls){
93 96
 		ls->size=n;
94 97
 		ls->semid=-1;
... ...
@@ -40,6 +40,8 @@
40 40
  *  2003-03-10  lock set support added also for PTHREAD_MUTEX & POSIX_SEM
41 41
  *               (andrei)
42 42
  *  2003-03-17  possible signal interruptions treated for sysv (andrei)
43
+ *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
44
+ *              on darwin (andrei)
43 45
  *
44 46
 Implements:
45 47
 
... ...
@@ -52,10 +54,10 @@ Implements:
52 54
 	
53 55
 	lock sets: [implemented only for FL & SYSV so far]
54 56
 	----------
55
-	lock_set_t* lock_set_init(lock_set_t* set);  - inits the lock set
56
-	void lock_set_destroy(lock_set_t* s);        - removes the lock set
57
-	void lock_set_get(lock_set_t* s, int i);     - locks sem i from the set
58
-	void lock_set_release(lock_set_t* s, int i)  - unlocks sem i from the set
57
+	gen_lock_set_t* lock_set_init(gen_lock_set_t* set);  - inits the lock set
58
+	void lock_set_destroy(gen_lock_set_t* s);        - removes the lock set
59
+	void lock_set_get(gen_lock_set_t* s, int i);     - locks sem i from the set
60
+	void lock_set_release(gen_lock_set_t* s, int i)  - unlocks sem i from the set
59 61
 
60 62
 WARNING: - lock_set_init may fail for large number of sems (e.g. sysv). 
61 63
          - signals are not treated! (some locks are "awakened" by the signals)
... ...
@@ -209,16 +211,16 @@ tryagain:
209 211
 #if defined(FAST_LOCK) || defined(USE_PTHREAD_MUTEX) || defined(USE_POSIX_SEM)
210 212
 #define GEN_LOCK_T_PREFERED
211 213
 
212
-struct lock_set_t_ {
214
+struct gen_lock_set_t_ {
213 215
 	long size;
214 216
 	gen_lock_t* locks;
215 217
 }; /* must be  aligned (32 bits or 64 depending on the arch)*/
216
-typedef struct lock_set_t_ lock_set_t;
218
+typedef struct gen_lock_set_t_ gen_lock_set_t;
217 219
 
218 220
 
219 221
 #define lock_set_destroy(lock_set) /* do nothing */
220 222
 
221
-inline static lock_set_t* lock_set_init(lock_set_t* s)
223
+inline static gen_lock_set_t* lock_set_init(gen_lock_set_t* s)
222 224
 {
223 225
 	int r;
224 226
 	for (r=0; r<s->size; r++) if (lock_init(&s->locks[r])==0) return 0;
... ...
@@ -232,14 +234,14 @@ inline static lock_set_t* lock_set_init(lock_set_t* s)
232 234
 #elif defined(USE_SYSV_SEM)
233 235
 #undef GEN_LOCK_T_PREFERED
234 236
 
235
-struct lock_set_t_ {
237
+struct gen_lock_set_t_ {
236 238
 	int size;
237 239
 	int semid;
238 240
 };
239 241
 
240 242
 
241
-typedef struct lock_set_t_ lock_set_t;
242
-inline static lock_set_t* lock_set_init(lock_set_t* s)
243
+typedef struct gen_lock_set_t_ gen_lock_set_t;
244
+inline static gen_lock_set_t* lock_set_init(gen_lock_set_t* s)
243 245
 {
244 246
 	union semun su;
245 247
 	int r;
... ...
@@ -262,12 +264,12 @@ inline static lock_set_t* lock_set_init(lock_set_t* s)
262 264
 	return s;
263 265
 }
264 266
 
265
-inline static void lock_set_destroy(lock_set_t* s)
267
+inline static void lock_set_destroy(gen_lock_set_t* s)
266 268
 {
267 269
 	semctl(s->semid, 0, IPC_RMID, (union semun)(int)0);
268 270
 }
269 271
 
270
-inline static void lock_set_get(lock_set_t* s, int n)
272
+inline static void lock_set_get(gen_lock_set_t* s, int n)
271 273
 {
272 274
 	struct sembuf sop;
273 275
 	sop.sem_num=n;
... ...
@@ -285,7 +287,7 @@ tryagain:
285 287
 	}
286 288
 }
287 289
 
288
-inline static void lock_set_release(lock_set_t* s, int n)
290
+inline static void lock_set_release(gen_lock_set_t* s, int n)
289 291
 {
290 292
 	struct sembuf sop;
291 293
 	sop.sem_num=n;
... ...
@@ -34,6 +34,8 @@
34 34
  *  2003-03-05  lock set support added for FAST_LOCK & SYSV (andrei)
35 35
  *  2003-03-06  splited in two: lock_ops.h & lock_alloc.h, to avoid
36 36
  *               shm_mem.h<->locking.h interdependency (andrei)
37
+ *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
38
+ *              on darwin (andrei)
37 39
  *
38 40
 Implements (in lock_ops.h & lock_alloc.h):
39 41
 
... ...
@@ -49,13 +51,13 @@ Implements (in lock_ops.h & lock_alloc.h):
49 51
 	
50 52
 	lock sets:
51 53
 	----------
52
-	type: lock_set_t
53
-	lock_set_t* lock_set_alloc(no)               - allocs a lock set in shm.
54
-	lock_set_t* lock_set_init(lock_set_t* set);  - inits the lock set
55
-	void lock_set_destroy(lock_set_t* s);        - removes the lock set
56
-	void lock_set_dealloc(lock_set_t* s);        - deallocs the lock set shm.
57
-	void lock_set_get(lock_set_t* s, int i);     - locks sem i from the set
58
-	void lock_set_release(lock_set_t* s, int i)  - unlocks sem i from the set
54
+	type: gen_lock_set_t
55
+	gen_lock_set_t* lock_set_alloc(no)               - allocs a lock set in shm.
56
+	gen_lock_set_t* lock_set_init(gen_lock_set_t* set);  - inits the lock set
57
+	void lock_set_destroy(gen_lock_set_t* s);        - removes the lock set
58
+	void lock_set_dealloc(gen_lock_set_t* s);        - deallocs the lock set shm.
59
+	void lock_set_get(gen_lock_set_t* s, int i);     - locks sem i from the set
60
+	void lock_set_release(gen_lock_set_t* s, int i)  - unlocks sem i from the set
59 61
 
60 62
 WARNING: - lock_set_init may fail for large number of sems (e.g. sysv). 
61 63
          - signals are not treated! (some locks are "awakened" by the signals)
... ...
@@ -30,6 +30,7 @@
30 30
  * --------
31 31
  *  2003-03-12  splited shm_mem_init in shm_getmem & shm_mem_init_mallocs
32 32
  *               (andrei)
33
+ *  2004-07-27  ANON mmap support, needed on darwin (andrei)
33 34
  */
34 35
 
35 36
 
... ...
@@ -140,6 +141,10 @@ int shm_getmem()
140 141
 	}
141 142
 	
142 143
 #ifdef SHM_MMAP
144
+#ifdef USE_ANON_MMAP
145
+	shm_mempool=mmap(0, shm_mem_size, PROT_READ|PROT_WRITE,
146
+					 MAP_ANON|MAP_SHARED, -1 ,0);
147
+#else
143 148
 	fd=open("/dev/zero", O_RDWR);
144 149
 	if (fd==-1){
145 150
 		LOG(L_CRIT, "ERROR: shm_mem_init: could not open /dev/zero: %s\n",
... ...
@@ -149,6 +154,7 @@ int shm_getmem()
149 154
 	shm_mempool=mmap(0, shm_mem_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd ,0);
150 155
 	/* close /dev/zero */
151 156
 	close(fd);
157
+#endif /* USE_ANON_MMAP */
152 158
 #else
153 159
 	
154 160
 	shm_shmid=shmget(IPC_PRIVATE, /* SHM_MEM_SIZE */ shm_mem_size , 0700);
... ...
@@ -28,6 +28,8 @@
28 28
  * History:
29 29
  * --------
30 30
  *  2003-03-17  converted to locking.h (andrei)
31
+ *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
32
+ *              on darwin (andrei)
31 33
  */
32 34
 
33 35
 
... ...
@@ -70,9 +72,9 @@
70 72
 
71 73
 /* and the maximum number of semaphores in the entry_semaphore set */
72 74
 static int sem_nr;
73
-lock_set_t* timer_semaphore=0;
74
-lock_set_t* entry_semaphore=0;
75
-lock_set_t* reply_semaphore=0;
75
+gen_lock_set_t* timer_semaphore=0;
76
+gen_lock_set_t* entry_semaphore=0;
77
+gen_lock_set_t* reply_semaphore=0;
76 78
 #endif
77 79
 
78 80
 /* timer group locks */
... ...
@@ -28,6 +28,8 @@
28 28
  * History:
29 29
  * --------
30 30
  *  2003-03-17  converted to locking.h (andrei)
31
+ *  2004-07-28  s/lock_set_t/gen_lock_set_t/ because of a type conflict
32
+ *              on darwin (andrei)
31 33
  */
32 34
 
33 35
 #include "defs.h"
... ...
@@ -47,7 +49,7 @@
47 49
 /* typedef to structure we use for mutexing;
48 50
    currently, index to a semaphore set identifier now */
49 51
 typedef struct {
50
-	lock_set_t* semaphore_set;
52
+	gen_lock_set_t* semaphore_set;
51 53
 	int semaphore_index;
52 54
 } ser_lock_t;
53 55
 #endif
... ...
@@ -29,6 +29,7 @@
29 29
 /* History:
30 30
  * --------
31 31
  *  2003-04-12  support for resolving ipv6 address references added (andrei)
32
+ *  2004-07-28  darwin needs nameser_compat.h (andrei)
32 33
  */
33 34
 
34 35
 
... ...
@@ -41,6 +42,10 @@
41 42
 #include <netdb.h>
42 43
 #include <arpa/nameser.h>
43 44
 
45
+#ifdef __OS_darwin
46
+#include <arpa/nameser_compat.h>
47
+#endif
48
+
44 49
 #include "ip_addr.h"
45 50
 
46 51