Browse code

- fixed minor Makefile bugs - added mmap shm support (-DSHM_MMAP) - etc

Andrei Pelinescu-Onciul authored on 11/12/2001 02:14:00
Showing 11 changed files
... ...
@@ -30,6 +30,8 @@ ARCH = $(shell uname -s)
30 30
 # -DSHM_MEM	
31 31
 #		compiles in shared mem. support, needed by some modules and
32 32
 #		by USE_SHM_MEM
33
+# -DSHM_MMAP
34
+#		use mmap instead of SYSV shared memory
33 35
 # -DPKG_MALLOC	
34 36
 #		uses a faster malloc (exclusive w/ USE_SHM_MEM)
35 37
 # -DUSE_SHM_MEM	
... ...
@@ -43,8 +45,8 @@ ARCH = $(shell uname -s)
43 45
 #		twice, trying to free a pointer alloc'ed with a different
44 46
 #		malloc etc.)
45 47
 DEFS= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
46
-	 -DDNS_IP_HACK  -DSHM_MEM \
47
-	 -DPKG_MALLOC #-DDBG_QM_MALLOC -DNODEBUG
48
+	 -DDNS_IP_HACK  -DSHM_MEM -DSHM_MMAP\
49
+	 -DPKG_MALLOC -DNO_DEBUG #-DDBG_QM_MALLOC 
48 50
 #-DEXTRA_DEBUG
49 51
 # -DUSE_SHM_MEM
50 52
 #-DNO_DEBUG 
... ...
@@ -19,7 +19,7 @@ ALLDEP+=../../Makefile.defs
19 19
 else
20 20
 # called by the main Makefile
21 21
 
22
-ALLDEP+=../../Makefile
22
+ALLDEP+=../../Makefile ../../Makefile.defs
23 23
 
24 24
 endif
25 25
 
... ...
@@ -23,7 +23,7 @@
23 23
 
24 24
 
25 25
 # normal rules
26
-$(NAME): $(objs)
26
+$(NAME): $(objs) $(ALLDEP)
27 27
 	$(LD) $(LDFLAGS) $(objs) $(LIBS) -o $(NAME) 
28 28
 
29 29
 
... ...
@@ -48,7 +48,7 @@
48 48
 #define PKG_MEM_POOL_SIZE 1024*1024
49 49
 
50 50
 /*used is SH_MEM is defined*/
51
-#define SHM_MEM_SIZE 1024*1024
51
+#define SHM_MEM_SIZE 128*1024*1024
52 52
 
53 53
 #define TIMER_TICK 1
54 54
 #define LONG_SLEEP	3600
... ...
@@ -66,6 +66,9 @@ static char flags[]=
66 66
 #ifdef SHM_MEM
67 67
 ", SHM_MEM"
68 68
 #endif
69
+#ifdef SHM_MMAP
70
+", SHM_MMAP"
71
+#endif
69 72
 #ifdef PKG_MALLOC
70 73
 ", PKG_MALLOC"
71 74
 #endif
... ...
@@ -342,7 +345,8 @@ static void sig_usr(int signo)
342 345
 		if (is_main)
343 346
 			shm_mem_destroy();
344 347
 #endif
345
-		goto bye;
348
+		DPrint("Thank you for flying " NAME "\n");
349
+		exit(0);
346 350
 	} else if (signo==SIGUSR1) { /* statistic */
347 351
 #ifdef STATS
348 352
 		dump_all_statistic();
... ...
@@ -356,9 +360,6 @@ static void sig_usr(int signo)
356 360
 		shm_status();
357 361
 #endif
358 362
 	}
359
-bye:
360
-	DPrint("Thank you for flying " NAME "\n");
361
-	exit(0);
362 363
 }
363 364
 
364 365
 
... ...
@@ -14,13 +14,16 @@
14 14
 
15 15
 #define sh_malloc(size)		shm_malloc((size))
16 16
 #define sh_free(ptr)		shm_free((ptr))
17
+#define sh_status()			shm_status()
17 18
 
18 19
 #else
19 20
 
20 21
 #include <stdlib.h>
21 22
 
22
-#define sh_malloc(size)		shm_malloc((size))
23
-#define sh_free(ptr)		shm_free((ptr))
23
+#warn "you should define SHM_MEM"
24
+#define sh_malloc(size)		malloc((size))
25
+#define sh_free(ptr)		free((ptr))
26
+#define sh_status()
24 27
 
25 28
 #endif
26 29
 
... ...
@@ -140,8 +140,11 @@ int t_add_transaction( struct sip_msg* p_msg, char* foo, char* bar )
140 140
 
141 141
    /* creates a new transaction */
142 142
    new_cell = build_cell( p_msg ) ;
143
-   if  ( !new_cell )
143
+   if  ( !new_cell ){
144
+	   LOG(L_ERR, "ERROR: add_transaction: out of mem:\n");
145
+	   sh_status();
144 146
       return -1;
147
+	}
145 148
    /*insert the transaction into hash table*/
146 149
    insert_into_hash_table( hash_table , new_cell );
147 150
    DBG("DEBUG: t_add_transaction: new transaction inserted, hash: %d\n", new_cell->hash_index );
... ...
@@ -1223,7 +1226,7 @@ int t_put_on_wait(  struct cell  *Trans  )
1223 1226
   if ( is_in_timer_list( (&(Trans->wait_tl)) , WT_TIMER_LIST) )
1224 1227
   {
1225 1228
      DBG("DEBUG: t_put_on_wait: already on wait\n");
1226
-     return -1;
1229
+     return 1;
1227 1230
   }
1228 1231
 
1229 1232
    DBG("DEBUG: t_put_on_wait: stopping timers (FR and RETR)\n");
... ...
@@ -1,4 +1,4 @@
1 1
 #!/bin/sh
2 2
 
3
-ipcrm sem `cat /proc/sysvipc/sem | awk '{ print $2; }'`
4
-ipcrm shm `ipcs -m | awk '{ print $2; }'` 
3
+ipcrm sem `ipcs -s |grep $(whoami) | awk '{ print $2; }'`
4
+ipcrm shm `ipcs -m | grep $(whoami) |awk '{ print $2; }'` 
... ...
@@ -8,6 +8,16 @@
8 8
 #include "shm_mem.h"
9 9
 #include "config.h"
10 10
 
11
+#ifdef  SHM_MMAP
12
+
13
+#include <unistd.h>
14
+#include <sys/mman.h>
15
+#include <sys/types.h> /*open*/
16
+#include <sys/stat.h>
17
+#include <fcntl.h>
18
+
19
+#endif
20
+
11 21
 
12 22
 /* define semun */
13 23
 #if defined(__GNU_LIBRARY__) && !defined(_SEM_SEMUN_UNDEFINED)
... ...
@@ -24,8 +34,9 @@
24 34
 
25 35
 
26 36
 
27
-
37
+#ifndef SHM_MMAP
28 38
 static int shm_shmid=-1; /*shared memory id*/
39
+#endif
29 40
 int shm_semid=-1; /*semaphore id*/
30 41
 static void* shm_mempool=(void*)-1;
31 42
 struct qm_block* shm_block;
... ...
@@ -36,15 +47,36 @@ struct qm_block* shm_block;
36 47
 int shm_mem_init()
37 48
 {
38 49
 
39
-	struct shmid_ds shm_info;
40 50
 	union semun su;
51
+#ifdef SHM_MMAP
52
+	int fd;
53
+#else
54
+	struct shmid_ds shm_info;
55
+#endif
41 56
 	int ret;
42 57
 
58
+#ifdef SHM_MMAP
59
+	if (shm_mempool && (shm_mempool!=(void*)-1)){
60
+#else
43 61
 	if ((shm_shmid!=-1)||(shm_semid!=-1)||(shm_mempool!=(void*)-1)){
62
+#endif
44 63
 		LOG(L_CRIT, "BUG: shm_mem_init: shm already initialized\n");
45 64
 		return -1;
46 65
 	}
47 66
 	
67
+#ifdef SHM_MMAP
68
+	fd=open("/dev/zero", O_RDONLY);
69
+	if (fd==-1){
70
+		LOG(L_CRIT, "ERROR: shm_mem_init: could not open /dev/zero: %s\n",
71
+				strerror(errno));
72
+		return -1;
73
+	}
74
+	shm_mempool=mmap(0, SHM_MEM_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE,
75
+						fd ,0);
76
+	/* close /dev/zero */
77
+	close(fd);
78
+#else
79
+	
48 80
 	shm_shmid=shmget(IPC_PRIVATE, SHM_MEM_SIZE, 0700);
49 81
 	if (shm_shmid==-1){
50 82
 		LOG(L_CRIT, "ERROR: shm_mem_init: could not allocate shared memory"
... ...
@@ -52,6 +84,7 @@ int shm_mem_init()
52 84
 		return -1;
53 85
 	}
54 86
 	shm_mempool=shmat(shm_shmid, 0, 0);
87
+#endif
55 88
 	if (shm_mempool==(void*)-1){
56 89
 		LOG(L_CRIT, "ERROR: shm_mem_init: could not attach shared memory"
57 90
 				" segment: %s\n", strerror(errno));
... ...
@@ -93,17 +126,25 @@ int shm_mem_init()
93 126
 
94 127
 void shm_mem_destroy()
95 128
 {
129
+#ifndef SHM_MMAP
96 130
 	struct shmid_ds shm_info;
131
+#endif
97 132
 	
98 133
 	DBG("shm_mem_destroy\n");
99 134
 	if (shm_mempool && (shm_mempool!=(void*)-1)) {
135
+#ifdef SHM_MMAP
136
+		munmap(shm_mempool, SHM_MEM_SIZE);
137
+#else
100 138
 		shmdt(shm_mempool);
139
+#endif
101 140
 		shm_mempool=(void*)-1;
102 141
 	}
142
+#ifndef SHM_MMAP
103 143
 	if (shm_shmid!=-1) {
104 144
 		shmctl(shm_shmid, IPC_RMID, &shm_info);
105 145
 		shm_shmid=-1;
106 146
 	}
147
+#endif
107 148
 	if (shm_semid!=-1) {
108 149
 		semctl(shm_semid, 0, IPC_RMID, (union semun)0);
109 150
 		shm_semid=-1;
... ...
@@ -12,7 +12,13 @@
12 12
 #include <errno.h>
13 13
 #include <sys/types.h>
14 14
 #include <sys/ipc.h>
15
+
16
+#ifndef SHM_MMAP
17
+
15 18
 #include <sys/shm.h>
19
+
20
+#endif
21
+
16 22
 #include <sys/sem.h>
17 23
 #include <string.h>
18 24
 #include <errno.h>
... ...
@@ -1,12 +1,12 @@
1
-debug=9          # debug level (cmd line: -dddddddddd)
1
+debug=3          # debug level (cmd line: -dddddddddd)
2 2
 check_via=yes     # (cmd. line: -v)
3 3
 dns=on           # (cmd. line: -r)
4 4
 rev_dns=yes      # (cmd. line: -R)
5
-fork=no          # (cmd. line: -D)
6
-#children=5
5
+fork=yes          # (cmd. line: -D)
6
+children=4
7 7
 log_stderror=yes # (cmd line: -E)
8 8
 #port=5080
9
-#listen=192.168.99.100
9
+listen=127.0.0.1
10 10
 loop_checks=1
11 11
 # for more info: sip_router -h
12 12
 
... ...
@@ -16,35 +16,58 @@ loadmodule "modules/tm/tm.so"
16 16
 
17 17
 route{
18 18
 	#rewritehost("iptel.org");
19
-	log("trying forward to uri");
20 19
 #	forward(uri:host,uri:port);
21 20
 #	forward(127.0.0.1, 5090);
22
-	log("after forward");
21
+#	sethost("127.0.0.1");
22
+#	setport("5090");
23 23
 
24 24
 	if ( t_lookup_request()) {
25 25
 		if ( method=="ACK" )	{
26 26
 			log("SER: ACK received -> t_release\n");
27
-			t_forward("iptel.org", "5060" );
28
-			t_release();
27
+			if (! t_forward("127.0.0.1", "5090" )) {
28
+				log("SER: WARNING: bad forward\n");
29
+			};
30
+			if (! t_release()) {
31
+				log("SER: WARNING: bad t_release\n");
32
+			};
29 33
 		} else {
30
-			t_retransmit_reply();
34
+			if (! t_retransmit_reply()) {
35
+				log("SER: WARNING: bad t_retransmit_reply\n");
36
+			};
31 37
 			log("SER: yet another annoying retranmission\n");
32 38
 		};
33 39
 	} else {
34
-		t_add_transaction();
40
+		if (! t_add_transaction()){
41
+			log("SER: ERROR: t_add_transaction\n");
42
+		};
35 43
 		if (method=="CANCEL") {
36 44
 			log("SER: new CANCEL\n");
37 45
 			# XXX ... it wants me to put status code in ""
38
-			t_send_reply( "200", "glad to cancel");
46
+			if (! t_send_reply( "200", "glad to cancel")){
47
+				log("SER:ERROR: t_send_reply\n");
48
+			};
39 49
 		} else {
40 50
 			log("SER: new transaction\n");
41
-			t_send_reply("100", "trying -- your call is important to us");
51
+			if (! t_send_reply("100", "trying -- your call is important to us")
52
+				){
53
+				log("SER: ERROR: t_send_reply (100)\n");
54
+			};
42 55
 		};
43 56
 		#rewritehost("iptel.org");
44 57
 		# XXX ... it wants me to put port nr in ""
45 58
 		#t_forward("benetnash.fokus.gmd.de", "5080" );
46
-		#t_forward("iptel.org", "5060" );
47
-		t_forward_uri();
59
+		if (method=="BYE") {
60
+			log("SER: BYE received, HACK: forwarding to client\n");
61
+			if (! t_forward("127.0.0.1", "5000")){
62
+				log("SER:ERROR: t_forward (..., 5000)\n");
63
+			};
64
+				
65
+		}else{
66
+			if (! t_forward("127.0.0.1", "5090" )){
67
+				log("SER:ERROR: t_forward (..., 5090)\n");
68
+			};
69
+		};
70
+		#t_forward_uri();
48 71
 		# XXX ... it doesn't like default port numbers
49 72
 		# t_forward("fox.iptel.org" );
50 73
 		# XXX t_forward_uri ... not done yet