From 710588fcfd0bd0b1aae397e1a724f8ce3b5a2608 Mon Sep 17 00:00:00 2001 From: "roberto@sirius" Date: Thu, 11 Feb 2010 09:55:02 +0100 Subject: [PATCH] fixed plugin initialization --- logging.c | 2 +- plugins/example/example_plugin.c | 6 +++--- plugins/lua/lua_plugin.c | 6 +++--- uwsgi_pymodule.c | 12 ++++++++++-- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/logging.c b/logging.c index bf10dfa6..2082d154 100644 --- a/logging.c +++ b/logging.c @@ -109,7 +109,7 @@ void get_memusage() { kv = kvm_open(NULL, NULL, NULL, O_RDONLY, NULL); if (kv) { -#ifdef __FreeBSD__ +#if defined(__FreeBSD__) || defined(__DragonFly__) struct kinfo_proc *kproc; int cnt ; kproc = kvm_getprocs(kv, KERN_PROC_PID, uwsgi.mypid, &cnt); diff --git a/plugins/example/example_plugin.c b/plugins/example/example_plugin.c index e58165a2..a83a654b 100644 --- a/plugins/example/example_plugin.c +++ b/plugins/example/example_plugin.c @@ -2,8 +2,9 @@ /* gcc `python2.5-config --cflags` -o example_plugin.so -fPIC -shared example_plugin.c */ -void uwsgi_init(struct uwsgi_server *uwsgi, char *args){ +int uwsgi_init(struct uwsgi_server *uwsgi, char *args){ fprintf(stderr,"i am the example plugin initialization function with arg: %s\n", args); + return 0; } int uwsgi_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req, char *buffer) { @@ -14,7 +15,6 @@ int uwsgi_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req, cha } -int uwsgi_after_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req, char *buffer) { +void uwsgi_after_request(struct uwsgi_server *uwsgi, struct wsgi_request *wsgi_req, char *buffer) { fprintf(stderr,"i am the example plugin after request function\n"); - return 0; } diff --git a/plugins/lua/lua_plugin.c b/plugins/lua/lua_plugin.c index 88351d86..2004fe6b 100644 --- a/plugins/lua/lua_plugin.c +++ b/plugins/lua/lua_plugin.c @@ -49,7 +49,7 @@ static int uwsgi_lua_input(lua_State *L) { return 1; } -void uwsgi_init(struct uwsgi_server *uwsgi, char *args){ +int uwsgi_init(struct uwsgi_server *uwsgi, char *args){ int fd, i; @@ -66,7 +66,7 @@ void uwsgi_init(struct uwsgi_server *uwsgi, char *args){ fd = open(args, O_RDONLY) ; if (fd < 0) { perror("open()"); - return ; + return -1 ; } @@ -80,7 +80,7 @@ void uwsgi_init(struct uwsgi_server *uwsgi, char *args){ fprintf(stderr,"%s\n", lua_typename(ulua.L, lua_type(ulua.L, -1))); // ok the lua engine is ready - return ; + return 0 ; } diff --git a/uwsgi_pymodule.c b/uwsgi_pymodule.c index 7de4a1d7..1d416e4c 100644 --- a/uwsgi_pymodule.c +++ b/uwsgi_pymodule.c @@ -552,7 +552,7 @@ PyObject *py_uwsgi_load_plugin(PyObject *self, PyObject *args) { char *pargs = NULL ; void *plugin_handle; - void (*plugin_init)(struct uwsgi_server *, char *); + int (*plugin_init)(struct uwsgi_server *, char *); int (*plugin_request)(struct uwsgi_server *, struct wsgi_request*, char*) ; void (*plugin_after_request)(struct uwsgi_server *, struct wsgi_request*, char*) ; @@ -567,7 +567,15 @@ PyObject *py_uwsgi_load_plugin(PyObject *self, PyObject *args) { else { plugin_init = dlsym(plugin_handle, "uwsgi_init"); if (plugin_init) { - (*plugin_init)(&uwsgi, pargs); + if ((*plugin_init)(&uwsgi, pargs)) { + fprintf(stderr,"plugin initialization returned error\n"); + if (dlclose(plugin_handle)) { + fprintf(stderr,"unable to unload plugin\n"); + } + + Py_INCREF(Py_None); + return Py_None; + } } plugin_request = dlsym(plugin_handle, "uwsgi_request");