Commit 9193435e authored by Renato Figueiro Maia's avatar Renato Figueiro Maia

Merge from branch 02_00_00 [171403]


git-svn-id: https://subversion.tecgraf.puc-rio.br/engdist/openbus/sdk/lua/branches/02_00_01@171404 ae0415b3-e90b-0410-900d-d0be9363c56b
parents 6bea7a52 10e980d4
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <time.h>
#define lua_c #define lua_c
...@@ -118,6 +117,19 @@ static const char *callerchunk = ...@@ -118,6 +117,19 @@ static const char *callerchunk =
static const char *setdebugchunk = static const char *setdebugchunk =
"table.insert(package.searchers, (table.remove(package.searchers, 1)))"; "table.insert(package.searchers, (table.remove(package.searchers, 1)))";
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 void print_usage (const char *badoption) { static void print_usage (const char *badoption) {
luai_writestringerror("%s: ", progname); luai_writestringerror("%s: ", progname);
...@@ -171,41 +183,6 @@ static void finalreport (lua_State *L, int status) { ...@@ -171,41 +183,6 @@ static void finalreport (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) {
l_message(NULL,
"--/--/---- --:--:-- [uptime] process terminated forcefully");
} else {
char buff[63];
strftime(buff, sizeof(buff),
"%d/%m/%Y %H:%M:%S [uptime] process terminated forcefully", stm);
l_message(NULL, buff);
}
exit(1);
}
static int traceback (lua_State *L) { static int traceback (lua_State *L) {
const char *msg = lua_tostring(L, 1); const char *msg = lua_tostring(L, 1);
if (msg) if (msg)
...@@ -227,10 +204,8 @@ static int docall (lua_State *L, int narg, int nres) { ...@@ -227,10 +204,8 @@ static int docall (lua_State *L, int narg, int nres) {
lua_insert(L, base); /* put it under chunk and args */ lua_insert(L, base); /* put it under chunk and args */
globalL = L; /* to be available to 'laction' */ globalL = L; /* to be available to 'laction' */
signal(SIGINT, laction); signal(SIGINT, laction);
signal(SIGTERM, laction);
status = lua_pcall(L, narg+1, nres, base); status = lua_pcall(L, narg+1, nres, base);
signal(SIGINT, SIG_DFL); signal(SIGINT, SIG_DFL);
signal(SIGTERM, SIG_DFL);
lua_remove(L, base); /* remove traceback function */ lua_remove(L, base); /* remove traceback function */
return status; 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