Browse Source

- added module static link option

Andrei Pelinescu-Onciul 24 years ago
parent
commit
404073d31a
11 changed files with 102 additions and 30 deletions
  1. 24 2
      Makefile
  2. 1 1
      Makefile.defs
  3. 3 1
      Makefile.modules
  4. 4 1
      Makefile.rules
  5. 1 0
      Makefile.sources
  6. 2 1
      dprint.c
  7. 8 2
      main.c
  8. 4 0
      modules/tm/tm.c
  9. 50 20
      sr_module.c
  10. 4 1
      sr_module.h
  11. 1 1
      t_debug.cfg

+ 24 - 2
Makefile

@@ -11,8 +11,17 @@ auto_gen=lex.yy.c cfg.tab.c   #lexx, yacc etc
 include Makefile.sources
 
 exclude_modules=CVS usrloc
-modules=$(filter-out $(addprefix modules/, $(exclude_modules)), \
-						$(wildcard modules/*))
+static_modules=
+static_modules_path=$(addprefix modules/, $(static_modules))
+extra_sources=$(wildcard $(addsuffix /*.c, $(static_modules_path)))
+extra_objs=$(extra_sources:.c=.o)
+
+static_defs= $(foreach  mod, $(static_modules), \
+		-DSTATIC_$(shell echo $(mod) | tr a-z A-Z) )
+DEFS+=$(static_defs)
+modules=$(filter-out $(addprefix modules/, \
+			$(exclude_modules) $(static_modules)), \
+			$(wildcard modules/*))
 
 NAME=ser
 
@@ -39,6 +48,8 @@ cfg.tab.c: cfg.y $(ALLDEP)
 .PHONY: all
 all: $(NAME) modules
 
+$(NAME): static_modules
+
 
 .PHONY: modules
 modules:
@@ -47,6 +58,17 @@ modules:
 		echo  "" ; \
 		$(MAKE) -C $$r ; \
 	done
+
+.PHONY: static_modules
+static_modules:
+	-@echo "Extra objs: $(extra_objs)"
+	-@for r in $(static_modules_path); do \
+		echo  "" ; \
+		echo  "Making static module $r" ; \
+		$(MAKE) -C $$r static ; \
+	done
+
+
 	
 dbg: ser
 	gdb -command debug.gdb

+ 1 - 1
Makefile.defs

@@ -44,7 +44,7 @@ ARCH = $(shell uname -s)
 #		extra error checking (trying to free the same pointer
 #		twice, trying to free a pointer alloc'ed with a different
 #		malloc etc.)
-DEFS= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
+DEFS+= -DNAME='"$(NAME)"' -DVERSION='"$(RELEASE)"' -DARCH='"$(ARCH)"' \
 	 -DDNS_IP_HACK  -DPKG_MALLOC -DSHM_MEM  -DSHM_MMAP \
 	 -DDBG_QM_MALLOC -DNO_DEBUG #
 #-DEXTRA_DEBUG

+ 3 - 1
Makefile.modules

@@ -4,7 +4,7 @@
 # module Makefile
 #(to be included from each module)
 #
-
+MOD_NAME=$(NAME:.so=)
 
 ALLDEP=Makefile ../../Makefile.sources ../../Makefile.rules \
  ../../Makefile.modules
@@ -25,7 +25,9 @@ endif
 
 include ../../Makefile.sources
 
+ifeq (,$(filter $(MOD_NAME), $(static_modules)))
 CFLAGS:=$(MOD_CFLAGS)
 LDFLAGS:=$(MOD_LDFLAGS)
+endif
 
 include ../../Makefile.rules

+ 4 - 1
Makefile.rules

@@ -24,7 +24,7 @@
 
 # normal rules
 $(NAME): $(objs) $(ALLDEP)
-	$(LD) $(LDFLAGS) $(objs) $(LIBS) -o $(NAME) 
+	$(LD) $(LDFLAGS) $(objs) $(extra_objs) $(LIBS) -o $(NAME) 
 
 
 .PHONY: all
@@ -33,6 +33,9 @@ all: $(NAME) modules
 .PHONY: dep
 dep: $(depends)
 
+.PHONY: static
+static: $(objs)
+
 .PHONY: clean
 clean:
 	-@rm $(objs) $(NAME) 2>/dev/null

+ 1 - 0
Makefile.sources

@@ -13,5 +13,6 @@
 
 sources=$(filter-out $(auto_gen), $(wildcard *.c)) $(auto_gen)
 objs=$(sources:.c=.o)
+extra_objs=
 depends=$(sources:.c=.d)
 modules=

+ 2 - 1
dprint.c

@@ -6,6 +6,7 @@
  */
  
 #include "dprint.h"
+#include "globals.h"
  
 #include <stdarg.h>
 #include <stdio.h>
@@ -14,7 +15,7 @@ void dprint(char * format, ...)
 {
 	va_list ap;
 
-	fprintf(stderr, "%2d(%d) ", process_no, pids[process_no]);
+	fprintf(stderr, "%2d(%d) ", process_no, pids?pids[process_no]:0);
 	va_start(ap, format);
 	vfprintf(stderr,format,ap);
 	fflush(stderr);

+ 8 - 2
main.c

@@ -148,7 +148,7 @@ unsigned int maxbuffer = MAX_RECV_BUFFER_SIZE; /* maximum buffer size we do not
 				      		durig the auto-probing procedure; may be
 				      		re-configured */
 int children_no = 0;           /* number of children processing requests */
-int *pids;		       /*array with childrens pids, 0= main proc,
+int *pids=0;		       /*array with childrens pids, 0= main proc,
 				alloc'ed in shared mem if possible*/
 int debug = 0;
 int dont_fork = 0;
@@ -356,8 +356,11 @@ static void sig_usr(int signo)
 		}
 #endif
 #ifdef SHM_MEM
-		if (is_main)
+		if (is_main){
+			/*zero all shmem  alloc vars, that will still use*/
+			pids=0;
 			shm_mem_destroy();
+		}
 #endif
 		dprint("Thank you for flying " NAME "\n");
 		exit(0);
@@ -540,6 +543,9 @@ int main(int argc, char** argv)
 		goto error;
 	}
 
+	/*init builtin  modules*/
+	init_builtin_modules();
+
 	yyin=cfg_stream;
 	if ((yyparse()!=0)||(cfg_errors)){
 		fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors);

+ 4 - 0
modules/tm/tm.c

@@ -78,7 +78,11 @@ static struct module_exports nm_exports= {
 
 
 
+#ifdef STATIC_TM
+struct module_exports* tm_mod_register()
+#else
 struct module_exports* mod_register()
+#endif
 {
 
 	DBG( "TM - registering...\n");

+ 50 - 20
sr_module.c

@@ -3,6 +3,7 @@
 
 #include "sr_module.h"
 #include "dprint.h"
+#include "error.h"
 
 #include <dlfcn.h>
 #include <strings.h>
@@ -11,6 +12,52 @@
 
 struct sr_module* modules=0;
 
+#ifdef STATIC_TM
+	extern struct module_exports* tm_mod_register();
+#endif
+
+
+/* initializes statically built (compiled in) modules*/
+int init_builtin_modules()
+{
+	#ifdef STATIC_TM
+		register_module(tm_mod_register,"built-in", 0);
+	#endif
+}
+
+
+
+/* registers a module,  register_f= module register  functions
+ * returns <0 on error, 0 on success */
+int register_module(module_register register_f, char* path, void* handle)
+{
+	int ret;
+	struct module_exports* e;
+	struct sr_module* t, *mod;
+	
+	ret=-1;
+	e=(*register_f)();
+	if (e==0){
+		LOG(L_ERR, "ERROR: mod_register returned null\n");
+		goto error;
+	}
+	/* add module to the list */
+	if ((mod=malloc(sizeof(struct sr_module)))==0){
+		LOG(L_ERR, "load_module: memory allocation failure\n");
+		ret=E_OUT_OF_MEM;
+		goto error;
+	}
+	memset(mod,0, sizeof(struct sr_module));
+	mod->path=path;
+	mod->handle=handle;
+	mod->exports=e;
+	mod->next=modules;
+	modules=mod;
+	return 0;
+error:
+	return ret;
+}
+
 
 
 /* returns 0 on success , <0 on error */
@@ -18,9 +65,8 @@ int load_module(char* path)
 {
 	void* handle;
 	char* error;
-	struct sr_module* t, *mod;
-	struct module_exports* e;
-	struct module_exports* (*mod_register)();
+	module_register	mod_register;
+	struct sr_module* t;
 	
 	handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */
 	if (handle==0){
@@ -42,23 +88,7 @@ int load_module(char* path)
 		LOG(L_ERR, "ERROR: load_module: %s\n", error);
 		goto error1;
 	}
-	
-	e=(*mod_register)();
-	if (e==0){
-		LOG(L_ERR, "ERROR: mod_register returned null\n");
-		goto error1;
-	}
-	/* add module to the list */
-	if ((mod=malloc(sizeof(struct sr_module)))==0){
-		LOG(L_ERR, "load_module: memory allocation failure\n");
-		goto error1;
-	}
-	memset(mod,0, sizeof(struct sr_module));
-	mod->path=path;
-	mod->handle=handle;
-	mod->exports=e;
-	mod->next=modules;
-	modules=mod;
+	if (register_module(mod_register, path, handle)<0) goto error1;
 	return 0;
 
 error1:

+ 4 - 1
sr_module.h

@@ -8,6 +8,7 @@
 
 #include "msg_parser.h" /* for sip_msg */
 
+typedef  struct module_exports* (*module_register)();
 typedef  int (*cmd_function)(struct sip_msg*, char*, char*);
 typedef  int (*fixup_function)(void** param, int param_no);
 typedef  int (*response_function)(struct sip_msg*);
@@ -39,6 +40,8 @@ struct sr_module{
  
 struct sr_module* modules; /* global module list*/
 
+int init_builtin_modules();
+int register_module(module_register, char*,  void*);
 int load_module(char* path);
 cmd_function find_export(char* name, int param_no);
 struct sr_module* find_module(void *f, int* r);
@@ -46,7 +49,7 @@ void destroy_modules();
 
 
 /* modules function prototypes:
- * struct module_exports* mod_register();
+ * struct module_exports* mod_register(); (type module_register)
  * int   foo_cmd(struct sip_msg* msg, char* param);
  *  - returns >0 if ok , <0 on error, 0 to stop processing (==DROP)
  * int   response_f(struct sip_msg* msg)

+ 1 - 1
t_debug.cfg

@@ -12,7 +12,7 @@ loop_checks=1
 
 #modules
 loadmodule "modules/print/print.so"
-loadmodule "modules/tm/tm.so"
+#loadmodule "modules/tm/tm.so"
 
 route{
 	#rewritehost("iptel.org");