... | ... |
@@ -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 | 48 |
.PHONY: all |
40 | 49 |
all: $(NAME) modules |
41 | 50 |
|
51 |
+$(NAME): static_modules |
|
52 |
+ |
|
42 | 53 |
|
43 | 54 |
.PHONY: modules |
44 | 55 |
modules: |
... | ... |
@@ -47,6 +58,17 @@ modules: |
47 | 58 |
echo "" ; \ |
48 | 59 |
$(MAKE) -C $$r ; \ |
49 | 60 |
done |
61 |
+ |
|
62 |
+.PHONY: static_modules |
|
63 |
+static_modules: |
|
64 |
+ -@echo "Extra objs: $(extra_objs)" |
|
65 |
+ -@for r in $(static_modules_path); do \ |
|
66 |
+ echo "" ; \ |
|
67 |
+ echo "Making static module $r" ; \ |
|
68 |
+ $(MAKE) -C $$r static ; \ |
|
69 |
+ done |
|
70 |
+ |
|
71 |
+ |
|
50 | 72 |
|
51 | 73 |
dbg: ser |
52 | 74 |
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 |
... | ... |
@@ -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 | 15 |
{ |
15 | 16 |
va_list ap; |
16 | 17 |
|
17 |
- fprintf(stderr, "%2d(%d) ", process_no, pids[process_no]); |
|
18 |
+ fprintf(stderr, "%2d(%d) ", process_no, pids?pids[process_no]:0); |
|
18 | 19 |
va_start(ap, format); |
19 | 20 |
vfprintf(stderr,format,ap); |
20 | 21 |
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 | 543 |
goto error; |
541 | 544 |
} |
542 | 545 |
|
546 |
+ /*init builtin modules*/ |
|
547 |
+ init_builtin_modules(); |
|
548 |
+ |
|
543 | 549 |
yyin=cfg_stream; |
544 | 550 |
if ((yyparse()!=0)||(cfg_errors)){ |
545 | 551 |
fprintf(stderr, "ERROR: bad config file (%d errors)\n", cfg_errors); |
... | ... |
@@ -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 | 12 |
|
12 | 13 |
struct sr_module* modules=0; |
13 | 14 |
|
15 |
+#ifdef STATIC_TM |
|
16 |
+ extern struct module_exports* tm_mod_register(); |
|
17 |
+#endif |
|
18 |
+ |
|
19 |
+ |
|
20 |
+/* initializes statically built (compiled in) modules*/ |
|
21 |
+int init_builtin_modules() |
|
22 |
+{ |
|
23 |
+ #ifdef STATIC_TM |
|
24 |
+ register_module(tm_mod_register,"built-in", 0); |
|
25 |
+ #endif |
|
26 |
+} |
|
27 |
+ |
|
28 |
+ |
|
29 |
+ |
|
30 |
+/* registers a module, register_f= module register functions |
|
31 |
+ * returns <0 on error, 0 on success */ |
|
32 |
+int register_module(module_register register_f, char* path, void* handle) |
|
33 |
+{ |
|
34 |
+ int ret; |
|
35 |
+ struct module_exports* e; |
|
36 |
+ struct sr_module* t, *mod; |
|
37 |
+ |
|
38 |
+ ret=-1; |
|
39 |
+ e=(*register_f)(); |
|
40 |
+ if (e==0){ |
|
41 |
+ LOG(L_ERR, "ERROR: mod_register returned null\n"); |
|
42 |
+ goto error; |
|
43 |
+ } |
|
44 |
+ /* add module to the list */ |
|
45 |
+ if ((mod=malloc(sizeof(struct sr_module)))==0){ |
|
46 |
+ LOG(L_ERR, "load_module: memory allocation failure\n"); |
|
47 |
+ ret=E_OUT_OF_MEM; |
|
48 |
+ goto error; |
|
49 |
+ } |
|
50 |
+ memset(mod,0, sizeof(struct sr_module)); |
|
51 |
+ mod->path=path; |
|
52 |
+ mod->handle=handle; |
|
53 |
+ mod->exports=e; |
|
54 |
+ mod->next=modules; |
|
55 |
+ modules=mod; |
|
56 |
+ return 0; |
|
57 |
+error: |
|
58 |
+ return ret; |
|
59 |
+} |
|
60 |
+ |
|
14 | 61 |
|
15 | 62 |
|
16 | 63 |
/* returns 0 on success , <0 on error */ |
... | ... |
@@ -18,9 +65,8 @@ int load_module(char* path) |
18 | 65 |
{ |
19 | 66 |
void* handle; |
20 | 67 |
char* error; |
21 |
- struct sr_module* t, *mod; |
|
22 |
- struct module_exports* e; |
|
23 |
- struct module_exports* (*mod_register)(); |
|
68 |
+ module_register mod_register; |
|
69 |
+ struct sr_module* t; |
|
24 | 70 |
|
25 | 71 |
handle=dlopen(path, RTLD_NOW); /* resolve all symbols now */ |
26 | 72 |
if (handle==0){ |
... | ... |
@@ -42,23 +88,7 @@ int load_module(char* path) |
42 | 88 |
LOG(L_ERR, "ERROR: load_module: %s\n", error); |
43 | 89 |
goto error1; |
44 | 90 |
} |
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; |
|
91 |
+ if (register_module(mod_register, path, handle)<0) goto error1; |
|
62 | 92 |
return 0; |
63 | 93 |
|
64 | 94 |
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 | 40 |
|
40 | 41 |
struct sr_module* modules; /* global module list*/ |
41 | 42 |
|
43 |
+int init_builtin_modules(); |
|
44 |
+int register_module(module_register, char*, void*); |
|
42 | 45 |
int load_module(char* path); |
43 | 46 |
cmd_function find_export(char* name, int param_no); |
44 | 47 |
struct sr_module* find_module(void *f, int* r); |
... | ... |
@@ -46,7 +49,7 @@ void destroy_modules(); |
46 | 49 |
|
47 | 50 |
|
48 | 51 |
/* modules function prototypes: |
49 |
- * struct module_exports* mod_register(); |
|
52 |
+ * struct module_exports* mod_register(); (type module_register) |
|
50 | 53 |
* int foo_cmd(struct sip_msg* msg, char* param); |
51 | 54 |
* - returns >0 if ok , <0 on error, 0 to stop processing (==DROP) |
52 | 55 |
* int response_f(struct sip_msg* msg) |