Browse code

- added module static link option

Andrei Pelinescu-Onciul authored on 13/12/2001 03:21:09
Showing 11 changed files
... ...
@@ -11,8 +11,17 @@ auto_gen=lex.yy.c cfg.tab.c   #lexx, yacc etc
11 11
 include Makefile.sources
12 12
 
13 13
 exclude_modules=CVS usrloc
14
-modules=$(filter-out $(addprefix modules/, $(exclude_modules)), \
15
-						$(wildcard modules/*))
14
+static_modules=
15
+static_modules_path=$(addprefix modules/, $(static_modules))
16
+extra_sources=$(wildcard $(addsuffix /*.c, $(static_modules_path)))
17
+extra_objs=$(extra_sources:.c=.o)
18
+
19
+static_defs= $(foreach  mod, $(static_modules), \
20
+		-DSTATIC_$(shell echo $(mod) | tr a-z A-Z) )
21
+DEFS+=$(static_defs)
22
+modules=$(filter-out $(addprefix modules/, \
23
+			$(exclude_modules) $(static_modules)), \
24
+			$(wildcard modules/*))
16 25
 
17 26
 NAME=ser
18 27
 
... ...
@@ -39,6 +48,8 @@ cfg.tab.c: cfg.y $(ALLDEP)
39 39
 .PHONY: all
40 40
 all: $(NAME) modules
41 41
 
42
+$(NAME): static_modules
43
+
42 44
 
43 45
 .PHONY: modules
44 46
 modules:
... ...
@@ -47,6 +58,17 @@ modules:
47 47
 		echo  "" ; \
48 48
 		$(MAKE) -C $$r ; \
49 49
 	done
50
+
51
+.PHONY: static_modules
52
+static_modules:
53
+	-@echo "Extra objs: $(extra_objs)"
54
+	-@for r in $(static_modules_path); do \
55
+		echo  "" ; \
56
+		echo  "Making static module $r" ; \
57
+		$(MAKE) -C $$r static ; \
58
+	done
59
+
60
+
50 61
 	
51 62
 dbg: ser
52 63
 	gdb -command debug.gdb
... ...
@@ -44,7 +44,7 @@ ARCH = $(shell uname -s)
44 44
 #		extra error checking (trying to free the same pointer
45 45
 #		twice, trying to free a pointer alloc'ed with a different
46 46
 #		malloc etc.)
47
-DEFS= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
47
+DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
48 48
 	 -DDNS_IP_HACK  -DPKG_MALLOC -DSHM_MEM  -DSHM_MMAP \
49 49
 	 -DDBG_QM_MALLOC -DNO_DEBUG #
50 50
 #-DEXTRA_DEBUG
... ...
@@ -4,7 +4,7 @@
4 4
 # module Makefile
5 5
 #(to be included from each module)
6 6
 #
7
-
7
+MOD_NAME=$(NAME:.so=)
8 8
 
9 9
 ALLDEP=Makefile ../../Makefile.sources ../../Makefile.rules \
10 10
  ../../Makefile.modules
... ...
@@ -25,7 +25,9 @@ endif
25 25
 
26 26
 include ../../Makefile.sources
27 27
 
28
+ifeq (,$(filter $(MOD_NAME), $(static_modules)))
28 29
 CFLAGS:=$(MOD_CFLAGS)
29 30
 LDFLAGS:=$(MOD_LDFLAGS)
31
+endif
30 32
 
31 33
 include ../../Makefile.rules
... ...
@@ -24,7 +24,7 @@
24 24
 
25 25
 # normal rules
26 26
 $(NAME): $(objs) $(ALLDEP)
27
-	$(LD) $(LDFLAGS) $(objs) $(LIBS) -o $(NAME) 
27
+	$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(LIBS) -o $(NAME) 
28 28
 
29 29
 
30 30
 .PHONY: all
... ...
@@ -33,6 +33,9 @@ all: $(NAME) modules
33 33
 .PHONY: dep
34 34
 dep: $(depends)
35 35
 
36
+.PHONY: static
37
+static: $(objs)
38
+
36 39
 .PHONY: clean
37 40
 clean:
38 41
 	-@rm $(objs) $(NAME) 2>/dev/null
... ...
@@ -13,5 +13,6 @@
13 13
 
14 14
 sources=$(filter-out $(auto_gen), $(wildcard *.c)) $(auto_gen)
15 15
 objs=$(sources:.c=.o)
16
+extra_objs=
16 17
 depends=$(sources:.c=.d)
17 18
 modules=
... ...
@@ -6,6 +6,7 @@
6 6
  */
7 7
  
8 8
 #include "dprint.h"
9
+#include "globals.h"
9 10
  
10 11
 #include <stdarg.h>
11 12
 #include <stdio.h>
... ...
@@ -14,7 +15,7 @@ void dprint(char * format, ...)
14 14
 {
15 15
 	va_list ap;
16 16
 
17
-	fprintf(stderr, "%2d(%d) ", process_no, pids[process_no]);
17
+	fprintf(stderr, "%2d(%d) ", process_no, pids?pids[process_no]:0);
18 18
 	va_start(ap, format);
19 19
 	vfprintf(stderr,format,ap);
20 20
 	fflush(stderr);
... ...
@@ -148,7 +148,7 @@ unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE; /* maximum buffer size we do not
148 148
 				      		durig the auto-probing procedure; may be
149 149
 				      		re-configured */
150 150
 int children_no = 0;           /* number of children processing requests */
151
-int *pids;		       /*array with childrens pids, 0= main proc,
151
+int *pids=0;		       /*array with childrens pids, 0= main proc,
152 152
 				alloc'ed in shared mem if possible*/
153 153
 int debug = 0;
154 154
 int dont_fork = 0;
... ...
@@ -356,8 +356,11 @@ static void sig_usr(int signo)
356 356
 		}
357 357
 #endif
358 358
 #ifdef SHM_MEM
359
-		if (is_main)
359
+		if (is_main){
360
+			/*zero all shmem  alloc vars, that will still use*/
361
+			pids=0;
360 362
 			shm_mem_destroy();
363
+		}
361 364
 #endif
362 365
 		dprint("Thank you for flying " NAME "\n");
363 366
 		exit(0);
... ...
@@ -540,6 +543,9 @@ int main(int argc, char** argv)
540 540
 		goto error;
541 541
 	}
542 542
 
543
+	/*init builtin  modules*/
544
+	init_builtin_modules();
545
+
543 546
 	yyin=cfg_stream;
544 547
 	if ((yyparse()!=0)||(cfg_errors)){
545 548
 		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);
... ...
@@ -78,7 +78,11 @@ static struct module_exports nm_exports= {
78 78
 
79 79
 
80 80
 
81
+#ifdef STATIC_TM
82
+struct module_exports* tm_mod_register()
83
+#else
81 84
 struct module_exports* mod_register()
85
+#endif
82 86
 {
83 87
 
84 88
 	DBG( "TM - registering...\n");
... ...
@@ -3,6 +3,7 @@
3 3
 
4 4
 #include "sr_module.h"
5 5
 #include "dprint.h"
6
+#include "error.h"
6 7
 
7 8
 #include <dlfcn.h>
8 9
 #include <strings.h>
... ...
@@ -11,6 +12,52 @@
11 11
 
12 12
 struct sr_module* modules=0;
13 13
 
14
+#ifdef STATIC_TM
15
+	extern struct module_exports* tm_mod_register();
16
+#endif
17
+
18
+
19
+/* initializes statically built (compiled in) modules*/
20
+int init_builtin_modules()
21
+{
22
+	#ifdef STATIC_TM
23
+		register_module(tm_mod_register,"built-in", 0);
24
+	#endif
25
+}
26
+
27
+
28
+
29
+/* registers a module,  register_f= module register  functions
30
+ * returns <0 on error, 0 on success */
31
+int register_module(module_register register_f, char* path, void* handle)
32
+{
33
+	int ret;
34
+	struct module_exports* e;
35
+	struct sr_module* t, *mod;
36
+	
37
+	ret=-1;
38
+	e=(*register_f)();
39
+	if (e==0){
40
+		LOG(L_ERR, "ERROR: mod_register returned null\n");
41
+		goto error;
42
+	}
43
+	/* add module to the list */
44
+	if ((mod=malloc(sizeof(struct sr_module)))==0){
45
+		LOG(L_ERR, "load_module: memory allocation failure\n");
46
+		ret=E_OUT_OF_MEM;
47
+		goto error;
48
+	}
49
+	memset(mod,0, sizeof(struct sr_module));
50
+	mod->path=path;
51
+	mod->handle=handle;
52
+	mod->exports=e;
53
+	mod->next=modules;
54
+	modules=mod;
55
+	return 0;
56
+error:
57
+	return ret;
58
+}
59
+
14 60
 
15 61
 
16 62
 /* returns 0 on success , <0 on error */
... ...
@@ -18,9 +65,8 @@ int load_module(char* path)
18 18
 {
19 19
 	void* handle;
20 20
 	char* error;
21
-	struct sr_module* t, *mod;
22
-	struct module_exports* e;
23
-	struct module_exports* (*mod_register)();
21
+	module_register	mod_register;
22
+	struct sr_module* t;
24 23
 	
25 24
 	handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */
26 25
 	if (handle==0){
... ...
@@ -42,23 +88,7 @@ int load_module(char* path)
42 42
 		LOG(L_ERR, "ERROR: load_module: %s\n", error);
43 43
 		goto error1;
44 44
 	}
45
-	
46
-	e=(*mod_register)();
47
-	if (e==0){
48
-		LOG(L_ERR, "ERROR: mod_register returned null\n");
49
-		goto error1;
50
-	}
51
-	/* add module to the list */
52
-	if ((mod=malloc(sizeof(struct sr_module)))==0){
53
-		LOG(L_ERR, "load_module: memory allocation failure\n");
54
-		goto error1;
55
-	}
56
-	memset(mod,0, sizeof(struct sr_module));
57
-	mod->path=path;
58
-	mod->handle=handle;
59
-	mod->exports=e;
60
-	mod->next=modules;
61
-	modules=mod;
45
+	if (register_module(mod_register, path, handle)<0) goto error1;
62 46
 	return 0;
63 47
 
64 48
 error1:
... ...
@@ -8,6 +8,7 @@
8 8
 
9 9
 #include "msg_parser.h" /* for sip_msg */
10 10
 
11
+typedef  struct module_exports* (*module_register)();
11 12
 typedef  int (*cmd_function)(struct sip_msg*, char*, char*);
12 13
 typedef  int (*fixup_function)(void** param, int param_no);
13 14
 typedef  int (*response_function)(struct sip_msg*);
... ...
@@ -39,6 +40,8 @@ struct sr_module{
39 39
  
40 40
 struct sr_module* modules; /* global module list*/
41 41
 
42
+int init_builtin_modules();
43
+int register_module(module_register, char*,  void*);
42 44
 int load_module(char* path);
43 45
 cmd_function find_export(char* name, int param_no);
44 46
 struct sr_module* find_module(void *f, int* r);
... ...
@@ -46,7 +49,7 @@ void destroy_modules();
46 46
 
47 47
 
48 48
 /* modules function prototypes:
49
- * struct module_exports* mod_register();
49
+ * struct module_exports* mod_register(); (type module_register)
50 50
  * int   foo_cmd(struct sip_msg* msg, char* param);
51 51
  *  - returns >0 if ok , <0 on error, 0 to stop processing (==DROP)
52 52
  * int   response_f(struct sip_msg* msg)
... ...
@@ -12,7 +12,7 @@ loop_checks=1
12 12
 
13 13
 #modules
14 14
 loadmodule "modules/print/print.so"
15
-loadmodule "modules/tm/tm.so"
15
+#loadmodule "modules/tm/tm.so"
16 16
 
17 17
 route{
18 18
 	#rewritehost("iptel.org");