diff -ur lua-5.3.4/src/lua.c lua-5.3.4-sig_catch/src/lua.c --- lua-5.3.4/src/lua.c 2017年01月12日 17:14:26.000000000 +0000 +++ lua-5.3.4-sig_catch/src/lua.c 2017年03月20日 12:00:09.171170675 +0000 @@ -52,17 +52,28 @@ #include #define lua_stdin_is_tty() isatty(0) +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, NULL); /* ignore error: none possible */ +} + #elif defined(LUA_USE_WINDOWS) /* }{ */ #include #include #define lua_stdin_is_tty() _isatty(_fileno(stdin)) +#define sig_catch signal #else /* }{ */ /* ISO C definition */ #define lua_stdin_is_tty() 1 /* assume stdin is a tty */ +#define sig_catch signal #endif /* } */ @@ -201,9 +214,9 @@ lua_pushcfunction(L, msghandler); /* push message handler */ lua_insert(L, base); /* put it under function and args */ globalL = L; /* to be available to 'laction' */ - signal(SIGINT, laction); /* set C-signal handler */ + sig_catch(SIGINT, laction); /* set C-signal handler */ status = lua_pcall(L, narg, nres, base); - signal(SIGINT, SIG_DFL); /* reset C-signal handler */ + sig_catch(SIGINT, SIG_DFL); /* reset C-signal handler */ lua_remove(L, base); /* remove message handler from the stack */ return status; }

AltStyle によって変換されたページ (->オリジナル) /