bugfix ltls init #1314 (#1318)

* bugfix ltls init #1314

* 修改init失败信息

* fix destructor

Co-authored-by: zixun <lvzxiun@gmail.com>
This commit is contained in:
子熏
2021-01-11 15:15:25 +08:00
committed by GitHub
parent b164e3a8a9
commit c0e3421462
2 changed files with 42 additions and 9 deletions

View File

@@ -378,9 +378,11 @@ lnew_tls(lua_State* L) {
return 1;
}
int
luaopen_ltls_c(lua_State* L) {
if(!TLS_IS_INIT) {
luaL_error(L, "ltls need init, Put enablessl = true in you config file.");
}
luaL_Reg l[] = {
{"newctx", lnew_ctx},
{"newtls", lnew_tls},
@@ -391,18 +393,24 @@ luaopen_ltls_c(lua_State* L) {
return 1;
}
void __attribute__((constructor)) ltls_init(void) {
// for ltls init
static int
ltls_init_constructor(lua_State* L) {
#ifndef OPENSSL_EXTERNAL_INITIALIZATION
SSL_library_init();
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
TLS_IS_INIT = true;
if(!TLS_IS_INIT) {
SSL_library_init();
SSL_load_error_strings();
ERR_load_BIO_strings();
OpenSSL_add_all_algorithms();
}
#endif
TLS_IS_INIT = true;
return 0;
}
void __attribute__((destructor)) ltls_destory(void) {
static int
ltls_init_destructor(lua_State* L) {
#ifndef OPENSSL_EXTERNAL_INITIALIZATION
if(TLS_IS_INIT) {
ENGINE_cleanup();
CONF_modules_unload(1);
@@ -411,4 +419,19 @@ void __attribute__((destructor)) ltls_destory(void) {
sk_SSL_COMP_free(SSL_COMP_get_compression_methods());
CRYPTO_cleanup_all_ex_data();
}
#endif
TLS_IS_INIT = false;
return 0;
}
int
luaopen_ltls_init_c(lua_State* L) {
luaL_Reg l[] = {
{"constructor", ltls_init_constructor},
{"destructor", ltls_init_destructor},
{NULL, NULL},
};
luaL_checkversion(L);
luaL_newlib(L, l);
return 1;
}

View File

@@ -1,5 +1,6 @@
local skynet = require "skynet"
local harbor = require "skynet.harbor"
local service = require "skynet.service"
require "skynet.manager" -- import skynet.launch, ...
skynet.start(function()
@@ -39,6 +40,15 @@ skynet.start(function()
skynet.name("DATACENTER", datacenter)
end
skynet.newservice "service_mgr"
local enablessl = skynet.getenv "enablessl"
if enablessl then
service.new("ltls_holder", function ()
local c = require "ltls.init.c"
c.constructor()
end)
end
pcall(skynet.newservice,skynet.getenv "start" or "main")
skynet.exit()
end)