Commit c1b0dd2b authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

[OPENBUS-2918] Serviços passam a liberar recursos ao serem abortados

- Desfazendo commit 171223 por ser uma solução incorreta devido a condição de corrida ao acessar um lua_State a partir de um tratador de sinal do sistema.


git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/trunk@171401 ae0415b3-e90b-0410-900d-d0be9363c56b
parent b340124d
......@@ -9,7 +9,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <lua.h>
#include <lauxlib.h>
......@@ -74,6 +73,20 @@ static const char *callerchunk =
static void lstop (lua_State *L, lua_Debug *ar) {
(void)ar; /* unused arg. */
lua_sethook(L, NULL, 0, 0);
luaL_error(L, "interrupted!");
}
static void laction (int i) {
signal(i, SIG_DFL); /* if another SIGINT happens before lstop,
terminate process (default action) */
lua_sethook(globalL, lstop, LUA_MASKCALL | LUA_MASKRET | LUA_MASKCOUNT, 1);
}
static int traceback (lua_State *L) {
const char *msg = lua_tostring(L, 1);
if (msg)
......@@ -122,41 +135,6 @@ LUALIB_API int openbuslua_report (lua_State *L, int status) {
}
/*
** By default, Lua uses gmtime/localtime, except when POSIX is available,
** where it uses gmtime_r/localtime_r
*/
#if defined(LUA_USE_GMTIME_R)
#define l_localtime(t,r) localtime_r(t,r)
#elif !defined(l_gmtime)
#define l_localtime(t,r) ((void)r, localtime(t))
#endif
static void laction (int i) {
struct tm tmr, *stm;
time_t t;
lua_close(globalL);
globalL = NULL;
t = time(NULL);
stm = l_localtime(&t, &tmr);
if (stm == NULL) {
openbuslua_logmessage(NULL,
"--/--/---- --:--:-- [uptime] process terminated forcefully");
} else {
char buff[63];
strftime(buff, sizeof(buff),
"%d/%m/%Y %H:%M:%S [uptime] process terminated forcefully", stm);
openbuslua_logmessage(NULL, buff);
}
exit(1);
}
LUALIB_API int openbuslua_call (lua_State *L, int narg, int nres) {
int status;
int base = lua_gettop(L) - narg; /* function index */
......@@ -164,10 +142,8 @@ LUALIB_API int openbuslua_call (lua_State *L, int narg, int nres) {
lua_insert(L, base); /* put it under chunk and args */
globalL = L; /* to be available to 'laction' */
signal(SIGINT, laction);
signal(SIGTERM, laction);
status = lua_pcall(L, narg, nres, base);
signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
lua_remove(L, base); /* remove traceback function */
return status;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment