moonbridge
changeset 293:b355e259c81e
Do not reuse child workers that have been SIGTERM'ed
author | jbe |
---|---|
date | Mon Jun 12 15:28:33 2017 +0200 (2017-06-12) |
parents | 7c67bdf99cb5 |
children | c78bb327ef6a |
files | moonbridge.c moonbridge_io.c moonbridge_io.h |
line diff
1.1 --- a/moonbridge.c Mon Jun 12 13:57:38 2017 +0200 1.2 +++ b/moonbridge.c Mon Jun 12 15:28:33 2017 +0200 1.3 @@ -755,13 +755,13 @@ 1.4 char controlmsg; 1.5 int fd; 1.6 struct itimerval notimer = { { 0, }, { 0, } }; 1.7 - moonbr_io_catch_sigterm(L); // NOTE: should not fail 1.8 lua_rawgetp(L, LUA_REGISTRYINDEX, moonbr_luakey_prepare_func(pool)); 1.9 if (lua_isnil(L, -1)) lua_pop(L, 1); 1.10 else if (lua_pcall(L, 0, 0, 1)) { 1.11 fprintf(stderr, "Error in \"prepare\" function: %s\n", lua_tostring(L, -1)); 1.12 exit(1); 1.13 } 1.14 + moonbr_io_catch_sigterm(L); // NOTE: should not fail 1.15 while (1) { 1.16 struct moonbr_listener *listener; 1.17 if (setitimer(ITIMER_REAL, ¬imer, NULL)) { 1.18 @@ -779,6 +779,7 @@ 1.19 moonbr_child_log_fatal("Received illegal control message from parent process"); 1.20 } 1.21 if (controlmsg == MOONBR_COMMAND_TERMINATE) break; 1.22 + moonbr_io_sigterm_flag = 0; /* ignore any prior SIGTERM (can't be handled in blocking recv anyway) */ 1.23 listener = moonbr_child_receive_pointer(MOONBR_FD_CONTROL); 1.24 if ( 1.25 listener->proto != MOONBR_PROTO_LOCAL && 1.26 @@ -814,7 +815,10 @@ 1.27 exit(1); 1.28 } 1.29 if (fd >= 0) moonbr_io_closehandle(L, -2, 0); /* attemt clean close */ 1.30 - if (lua_type(L, -1) != LUA_TBOOLEAN || !lua_toboolean(L, -1)) break; 1.31 + if ( 1.32 + moonbr_io_sigterm_flag || 1.33 + lua_type(L, -1) != LUA_TBOOLEAN || !lua_toboolean(L, -1) 1.34 + ) break; 1.35 #ifdef MOONBR_LUA_PANIC_BUG_WORKAROUND 1.36 lua_settop(L, 2); 1.37 #else
2.1 --- a/moonbridge_io.c Mon Jun 12 13:57:38 2017 +0200 2.2 +++ b/moonbridge_io.c Mon Jun 12 15:28:33 2017 +0200 2.3 @@ -116,7 +116,7 @@ 2.4 pid_t pid; 2.5 } moonbr_io_child_t; 2.6 2.7 -static volatile sig_atomic_t moonbr_io_sigterm_flag = 0; 2.8 +volatile sig_atomic_t moonbr_io_sigterm_flag = 0; 2.9 2.10 static int moonbr_io_yield(lua_State *L) { 2.11 return lua_yield(L, lua_gettop(L));
3.1 --- a/moonbridge_io.h Mon Jun 12 13:57:38 2017 +0200 3.2 +++ b/moonbridge_io.h Mon Jun 12 15:28:33 2017 +0200 3.3 @@ -1,4 +1,5 @@ 3.4 3.5 +volatile sig_atomic_t moonbr_io_sigterm_flag; 3.6 void moonbr_io_pushhandle(lua_State *L, int fd); 3.7 void moonbr_io_closehandle(lua_State *L, int idx, int reset); 3.8 int moonbr_io_catch_sigterm(lua_State *L);