diff options
author | Salvatore Sanfilippo <antirez@gmail.com> | 2019-10-16 11:13:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-16 11:13:12 +0200 |
commit | b8e02f2b4005febbdaa11ff978c4f98b664464c9 (patch) | |
tree | c5e5e70614a8cb402c6f33e9e50ac2b1a58946e2 /src | |
parent | dd29d441364236992ce89230556526c707c3c960 (diff) | |
parent | 283d6cfd58600a8c9e90584a67f1ca90d85f5669 (diff) | |
download | redis-b8e02f2b4005febbdaa11ff978c4f98b664464c9.tar.gz |
Merge pull request #5926 from JimB123/unstable
Addition of RedisModule_OnUnload hook
Diffstat (limited to 'src')
-rw-r--r-- | src/module.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/module.c b/src/module.c index 82ba9f86c..7e0a419b6 100644 --- a/src/module.c +++ b/src/module.c @@ -5698,6 +5698,23 @@ int moduleUnload(sds name) { errno = EPERM; return REDISMODULE_ERR; } + + /* Give module a chance to clean up. */ + int (*onunload)(void *); + onunload = (int (*)(void *))(unsigned long) dlsym(module->handle, "RedisModule_OnUnload"); + if (onunload) { + RedisModuleCtx ctx = REDISMODULE_CTX_INIT; + ctx.module = module; + ctx.client = moduleFreeContextReusedClient; + int unload_status = onunload((void*)&ctx); + moduleFreeContext(&ctx); + + if (unload_status == REDISMODULE_ERR) { + serverLog(LL_WARNING, "Module %s OnUnload failed. Unload canceled.", name); + errno = ECANCELED; + return REDISMODULE_ERR; + } + } moduleUnregisterCommands(module); moduleUnregisterSharedAPI(module); |