src/server/safs/init.c

changeset 556
b036ccad4b49
parent 415
d938228c382e
equal deleted inserted replaced
555:66b0accda0a8 556:b036ccad4b49
29 #include <dlfcn.h> 29 #include <dlfcn.h>
30 #include <cx/string.h> 30 #include <cx/string.h>
31 31
32 #include "../daemon/func.h" 32 #include "../daemon/func.h"
33 #include "../daemon/log.h" 33 #include "../daemon/log.h"
34 #include "../daemon/config.h"
34 35
35 #include "init.h" 36 #include "init.h"
36 37
37 int init_test(pblock *pb, Session *sn, Request *rq) { 38 int init_test(pblock *pb, Session *sn, Request *rq) {
38 printf("init-test\n"); 39 printf("init-test\n");
70 71
71 return REQ_ABORTED; 72 return REQ_ABORTED;
72 } 73 }
73 74
74 // load function symbols 75 // load function symbols
76 pool_handle_t *init_pool = cfg_get_init_pool();
75 int b = 0; 77 int b = 0;
76 for(int i=0;;i++) { 78 for(int i=0;;i++) {
77 if(funcs[i] == '-') { 79 if(funcs[i] == '-') {
78 funcs[i] = '_'; 80 funcs[i] = '_';
79 } 81 }
80 if(funcs[i] == ',' || funcs[i] == 0) { 82 if(funcs[i] == ',' || funcs[i] == 0) {
81 if(funcs[i] == 0) { 83 if(funcs[i] == 0) {
82 b = 1; 84 b = 1;
83 } 85 }
84 86
87 // TODO: although this works fine, is not really clean to just
88 // destroy the string with random 0-bytes
89 // maybe use cxstr here
85 funcs[i] = 0; 90 funcs[i] = 0;
86 91
87 // we have a function name 92 // we have a function name
88 void *sym = dlsym(lib, funcs); 93 void *sym = dlsym(lib, funcs);
89 if(sym == NULL) { 94 if(sym == NULL) {
92 return REQ_ABORTED; 97 return REQ_ABORTED;
93 } 98 }
94 struct FuncStruct fc; 99 struct FuncStruct fc;
95 ZERO(&fc, sizeof(struct FuncStruct)); 100 ZERO(&fc, sizeof(struct FuncStruct));
96 fc.func = (FuncPtr)sym; 101 fc.func = (FuncPtr)sym;
97 fc.name = cx_strdup(cx_str(funcs)).ptr; 102 fc.name = pool_strdup(init_pool, funcs);
98 add_function(&fc); 103 add_function(&fc);
99 104
100 if(b) { 105 if(b) {
101 break; 106 break;
102 } 107 }

mercurial