diff -Nur lua-5.2.3/src/lua.c lua-5.2.3-sig_catch/src/lua.c --- lua-5.2.3/src/lua.c 2013年04月12日 19:48:47.000000000 +0100 +++ lua-5.2.3-sig_catch/src/lua.c 2013年12月24日 14:04:02.197666881 +0000 @@ -169,15 +167,25 @@ } +static void sig_catch(int sig, void (*handler)(int)) +{ + struct sigaction sa; + sa.sa_handler = handler; + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); + sigaction(sig, &sa, 0); /* XXX ignores errors */ +} + + static int docall (lua_State *L, int narg, int nres) { int status; int base = lua_gettop(L) - narg; /* function index */ lua_pushcfunction(L, traceback); /* push traceback function */ lua_insert(L, base); /* put it under chunk and args */ globalL = L; /* to be available to 'laction' */ - signal(SIGINT, laction); + sig_catch(SIGINT, laction); status = lua_pcall(L, narg, nres, base); - signal(SIGINT, SIG_DFL); + sig_catch(SIGINT, SIG_DFL); lua_remove(L, base); /* remove traceback function */ return status; }