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 43
 #		twice, trying to free a pointer alloc'ed with a different
44 44
 #		malloc etc.)
45 45
 DEFS= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
46
-	 -DDNS_IP_HACK  -DSHM_MEM \
47
-	 -DPKG_MALLOC #-DDBG_QM_MALLOC -DNODEBUG
46
+	 -DDNS_IP_HACK  -DSHM_MEM -DSHM_MMAP\
47
+	 -DPKG_MALLOC -DNO_DEBUG #-DDBG_QM_MALLOC 
48 48
 #-DEXTRA_DEBUG
49 49
 # -DUSE_SHM_MEM
50 50
 #-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 342
 		if (is_main)
343 343
 			shm_mem_destroy();
344 344
 #endif
345
-		goto bye;
345
+		DPrint("Thank you for flying " NAME "\n");
346
+		exit(0);
346 347
 	} else if (signo==SIGUSR1) { /* statistic */
347 348
 #ifdef STATS
348 349
 		dump_all_statistic();
... ...
@@ -356,9 +360,6 @@ static void sig_usr(int signo)
356 356
 		shm_status();
357 357
 #endif
358 358
 	}
359
-bye:
360
-	DPrint("Thank you for flying " NAME "\n");
361
-	exit(0);
362 359
 }
363 360
 
364 361
 
... ...
@@ -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 1223
   if ( is_in_timer_list( (&(Trans->wait_tl)) , WT_TIMER_LIST) )
1224 1224
   {
1225 1225
      DBG("DEBUG: t_put_on_wait: already on wait\n");
1226
-     return -1;
1226
+     return 1;
1227 1227
   }
1228 1228
 
1229 1229
    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 24
 
25 25
 
26 26
 
27
-
27
+#ifndef SHM_MMAP
28 28
 static int shm_shmid=-1; /*shared memory id*/
29
+#endif
29 30
 int shm_semid=-1; /*semaphore id*/
30 31
 static void* shm_mempool=(void*)-1;
31 32
 struct qm_block* shm_block;
... ...
@@ -36,15 +47,36 @@ struct qm_block* shm_block;
36 36
 int shm_mem_init()
37 37
 {
38 38
 
39
-	struct shmid_ds shm_info;
40 39
 	union semun su;
40
+#ifdef SHM_MMAP
41
+	int fd;
42
+#else
43
+	struct shmid_ds shm_info;
44
+#endif
41 45
 	int ret;
42 46
 
47
+#ifdef SHM_MMAP
48
+	if (shm_mempool && (shm_mempool!=(void*)-1)){
49
+#else
43 50
 	if ((shm_shmid!=-1)||(shm_semid!=-1)||(shm_mempool!=(void*)-1)){
51
+#endif
44 52
 		LOG(L_CRIT, "BUG: shm_mem_init: shm already initialized\n");
45 53
 		return -1;
46 54
 	}
47 55
 	
56
+#ifdef SHM_MMAP
57
+	fd=open("/dev/zero", O_RDONLY);
58
+	if (fd==-1){
59
+		LOG(L_CRIT, "ERROR: shm_mem_init: could not open /dev/zero: %s\n",
60
+				strerror(errno));
61
+		return -1;
62
+	}
63
+	shm_mempool=mmap(0, SHM_MEM_SIZE, PROT_READ|PROT_WRITE, MAP_PRIVATE,
64
+						fd ,0);
65
+	/* close /dev/zero */
66
+	close(fd);
67
+#else
68
+	
48 69
 	shm_shmid=shmget(IPC_PRIVATE, SHM_MEM_SIZE, 0700);
49 70
 	if (shm_shmid==-1){
50 71
 		LOG(L_CRIT, "ERROR: shm_mem_init: could not allocate shared memory"
... ...
@@ -52,6 +84,7 @@ int shm_mem_init()
52 52
 		return -1;
53 53
 	}
54 54
 	shm_mempool=shmat(shm_shmid, 0, 0);
55
+#endif
55 56
 	if (shm_mempool==(void*)-1){
56 57
 		LOG(L_CRIT, "ERROR: shm_mem_init: could not attach shared memory"
57 58
 				" segment: %s\n", strerror(errno));
... ...
@@ -93,17 +126,25 @@ int shm_mem_init()
93 93
 
94 94
 void shm_mem_destroy()
95 95
 {
96
+#ifndef SHM_MMAP
96 97
 	struct shmid_ds shm_info;
98
+#endif
97 99
 	
98 100
 	DBG("shm_mem_destroy\n");
99 101
 	if (shm_mempool && (shm_mempool!=(void*)-1)) {
102
+#ifdef SHM_MMAP
103
+		munmap(shm_mempool, SHM_MEM_SIZE);
104
+#else
100 105
 		shmdt(shm_mempool);
106
+#endif
101 107
 		shm_mempool=(void*)-1;
102 108
 	}
109
+#ifndef SHM_MMAP
103 110
 	if (shm_shmid!=-1) {
104 111
 		shmctl(shm_shmid, IPC_RMID, &shm_info);
105 112
 		shm_shmid=-1;
106 113
 	}
114
+#endif
107 115
 	if (shm_semid!=-1) {
108 116
 		semctl(shm_semid, 0, IPC_RMID, (union semun)0);
109 117
 		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