]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MEDIUM: lua-thread: No longer use locked context in initialization parts
authorThierry Fournier <thierry.fournier@ozon.io>
Sat, 28 Nov 2020 15:05:05 +0000 (16:05 +0100)
committerWilly Tarreau <w@1wt.eu>
Wed, 2 Dec 2020 20:53:16 +0000 (21:53 +0100)
The goal is to allow execution of one main lua state per thread.

Stop using locks in init part, we will use only in parts where
the parent lua state is known, so we could take decision about lock
according with the lua parent state.

src/hlua.c

index 6153ab76971d3cf13b964e201c779e71c586c544..94bbad7978f2e7ace1059dafe89e166c2853a16a 100644 (file)
@@ -8273,13 +8273,16 @@ int hlua_post_init_state(lua_State *L)
                hlua_global_allocator.limit = ~hlua_global_allocator.limit;
 
        /* Call post initialisation function in safe environment. */
-       if (!SET_SAFE_LJMP(L)) {
+       if (setjmp(safe_ljmp_env) != 0) {
+               lua_atpanic(L, hlua_panic_safe);
                if (lua_type(L, -1) == LUA_TSTRING)
                        error = lua_tostring(L, -1);
                else
                        error = "critical error";
                fprintf(stderr, "Lua post-init: %s.\n", error);
                exit(1);
+       } else {
+               lua_atpanic(L, hlua_panic_ljmp);
        }
 
        hlua_fcn_post_init(L);
@@ -8338,7 +8341,8 @@ int hlua_post_init_state(lua_State *L)
                if (!return_status)
                        break;
        }
-       RESET_SAFE_LJMP(L);
+
+       lua_atpanic(L, hlua_panic_safe);
        return return_status;
 }
 
@@ -8435,17 +8439,19 @@ lua_State *hlua_init_state(int thread_num)
         * process of HAProxy, this abort() is tolerated.
         */
 
-       /* Set safe environment for the initialisation. */
-       if (!SET_SAFE_LJMP(L)) {
+       /* Call post initialisation function in safe environment. */
+       if (setjmp(safe_ljmp_env) != 0) {
+               lua_atpanic(L, hlua_panic_safe);
                if (lua_type(L, -1) == LUA_TSTRING)
                        error_msg = lua_tostring(L, -1);
                else
                        error_msg = "critical error";
                fprintf(stderr, "Lua init: %s.\n", error_msg);
                exit(1);
+       } else {
+               lua_atpanic(L, hlua_panic_ljmp);
        }
 
-
        /* Initialise lua. */
        luaL_openlibs(L);
 #define HLUA_PREPEND_PATH_TOSTRING1(x) #x
@@ -8990,7 +8996,7 @@ lua_State *hlua_init_state(int thread_num)
        }
 #endif
 
-       RESET_SAFE_LJMP(L);
+       lua_atpanic(L, hlua_panic_safe);
 
        return L;
 }