41 int load_modules(pblock *pb, Session *sn, Request *rq) { |
41 int load_modules(pblock *pb, Session *sn, Request *rq) { |
42 char *shlib = pblock_findval("shlib", pb); |
42 char *shlib = pblock_findval("shlib", pb); |
43 char *funcs = pblock_findval("funcs", pb); |
43 char *funcs = pblock_findval("funcs", pb); |
44 |
44 |
45 if(shlib == NULL || funcs == NULL) { |
45 if(shlib == NULL || funcs == NULL) { |
46 fprintf(stderr, "load-modules: missing parameter\n"); |
46 log_ereport(LOG_MISCONFIG, "load-modules: missing parameters"); |
47 //log_ereport(LOG_MISCONFIG, "load-modules: missing parameters"); |
|
48 if(!shlib && funcs) { |
47 if(!shlib && funcs) { |
49 log_ereport( |
48 log_ereport( |
50 LOG_MISCONFIG, |
49 LOG_MISCONFIG, |
51 "load-modules: missing shlib parameter"); |
50 "load-modules: missing shlib parameter"); |
52 } else if(!shlib && !funcs) { |
51 } else if(!shlib && !funcs) { |
58 LOG_MISCONFIG, |
57 LOG_MISCONFIG, |
59 "load-modules: missing shlib and funcs parameters"); |
58 "load-modules: missing shlib and funcs parameters"); |
60 } |
59 } |
61 } |
60 } |
62 |
61 |
63 /* load lib */ |
62 // load lib |
64 void *lib = dlopen(shlib, RTLD_GLOBAL | RTLD_NOW); |
63 void *lib = dlopen(shlib, RTLD_GLOBAL | RTLD_NOW); |
65 if(lib == NULL) { |
64 if(lib == NULL) { |
66 char *dlerr = dlerror(); |
65 char *dlerr = dlerror(); |
67 fprintf(stderr, "Cannot load library %s %s\n", shlib, dlerr); |
66 fprintf(stderr, "Cannot load library %s %s\n", shlib, dlerr); |
68 |
67 |
69 log_ereport(LOG_FAILURE, "Cannot load library %s: %s", shlib, dlerr); |
68 log_ereport(LOG_FAILURE, "Cannot load library %s: %s", shlib, dlerr); |
70 |
69 |
71 return REQ_ABORTED; |
70 return REQ_ABORTED; |
72 } |
71 } |
73 |
72 |
74 /* load function symbols */ |
73 // load function symbols |
75 int b = 0; |
74 int b = 0; |
76 for(int i=0;;i++) { |
75 for(int i=0;;i++) { |
77 if(funcs[i] == ',' || funcs[i] == 0) { |
76 if(funcs[i] == ',' || funcs[i] == 0) { |
78 if(funcs[i] == 0) { |
77 if(funcs[i] == 0) { |
79 b = 1; |
78 b = 1; |
80 } |
79 } |
81 |
80 |
82 funcs[i] = 0; |
81 funcs[i] = 0; |
83 |
82 |
84 /* we have a function name */ |
83 // we have a function name |
85 void *sym = dlsym(lib, funcs); |
84 void *sym = dlsym(lib, funcs); |
86 if(sym == NULL) { |
85 if(sym == NULL) { |
87 fprintf(stderr, "Cannot load symbol %s\n", funcs); |
86 fprintf(stderr, "Cannot load symbol %s\n", funcs); |
88 return REQ_ABORTED; |
87 return REQ_ABORTED; |
89 } |
88 } |