mirror of
https://github.com/lxsang/ant-http
synced 2024-11-18 01:08:21 +01:00
Unload plugin if pannic happen
All checks were successful
gitea-sync/ant-http/pipeline/head This commit looks good
All checks were successful
gitea-sync/ant-http/pipeline/head This commit looks good
This commit is contained in:
parent
6a483e188d
commit
bd0663ddf7
@ -112,6 +112,8 @@ name = fastcgi
|
||||
autoload = true
|
||||
; file handle
|
||||
file_type = php,pp
|
||||
;
|
||||
; The following example configurations are application specific
|
||||
; pluggin specific configurations here, for example
|
||||
socket = /var/php.sock
|
||||
bin = /usr/bin/phpfcgi
|
||||
|
@ -28,6 +28,9 @@
|
||||
#define ANTD_CLIENT_RQ_DATA_DECODE 0x7
|
||||
#define ANTD_CLIENT_PROXY_MONITOR 0x8
|
||||
|
||||
#define ANTD_PLUGIN_READY 0x0
|
||||
#define ANTD_PLUGIN_PANNIC 0x1
|
||||
|
||||
typedef enum
|
||||
{
|
||||
ANTD_CGZ,
|
||||
@ -111,6 +114,7 @@ typedef struct
|
||||
char* pdir;
|
||||
dictionary_t config;
|
||||
int raw_body;
|
||||
int status;
|
||||
} plugin_header_t;
|
||||
|
||||
int __attribute__((weak)) require_plugin(const char *);
|
||||
|
@ -33,6 +33,11 @@ void use_raw_body();
|
||||
STATIC PART, should be included in any plugin
|
||||
*/
|
||||
#ifdef PLUGIN_IMPLEMENT
|
||||
|
||||
#define PLUGIN_PANIC(a,...) \
|
||||
ERROR("%s: "a,__plugin__.name, ##__VA_ARGS__); \
|
||||
__plugin__.status = ANTD_PLUGIN_PANNIC;
|
||||
|
||||
static plugin_header_t __plugin__;
|
||||
// private function
|
||||
void __init_plugin__(const char* pl, dictionary_t* conf){
|
||||
@ -42,6 +47,7 @@ void __init_plugin__(const char* pl, dictionary_t* conf){
|
||||
tmpdir(&__plugin__.tmpdir);
|
||||
__plugin__.config = conf;
|
||||
__plugin__.raw_body = 0;
|
||||
__plugin__.status = ANTD_PLUGIN_READY;
|
||||
init();
|
||||
};
|
||||
void use_raw_body()
|
||||
|
@ -45,6 +45,9 @@ struct plugin_entry *plugin_load(char *name, dictionary_t config)
|
||||
char* pname = NULL;
|
||||
struct plugin_entry *np;
|
||||
unsigned hashval;
|
||||
plugin_header_t *(*metafn)();
|
||||
plugin_header_t *meta = NULL;
|
||||
char* error;
|
||||
if(config)
|
||||
{
|
||||
pname = dvalue(config, "name");
|
||||
@ -76,6 +79,24 @@ struct plugin_entry *plugin_load(char *name, dictionary_t config)
|
||||
LOG("The plugin %s id already loaded", name);
|
||||
}
|
||||
|
||||
// check if plugin is ready
|
||||
metafn = (plugin_header_t * (*)()) dlsym(np->handle, "meta");
|
||||
if ((error = dlerror()) != NULL)
|
||||
{
|
||||
ERROR("Unable to fetch plugin meta-data: [%s] %s", name, error);
|
||||
unload_plugin_by_name(name);
|
||||
free(np);
|
||||
return NULL;
|
||||
}
|
||||
meta = metafn();
|
||||
LOG("PLugin status: [%s] %d", name, meta->status);
|
||||
if(!meta || meta->status != ANTD_PLUGIN_READY)
|
||||
{
|
||||
ERROR("Plugin is not ready or error: [%s].", name);
|
||||
unload_plugin_by_name(name);
|
||||
free(np);
|
||||
return NULL;
|
||||
}
|
||||
return np;
|
||||
}
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user