[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: os.execute() side effect for signal handling
- From: Michal Kolodziejczyk <miko@...>
- Date: Sat, 26 Feb 2011 17:00:02 +0100
Hello,
consider those 2 lua programs:
while true do end
and
while true do os.execute() end
When run from the standard lua interpreter, the first one can be stopped
by pressing CTRL+C (sending SIGINT), while the second one cannot.
The reason is that os.execute() calls system(), and my manual page for
system() says:
"During execution of the command, SIGCHLD will be blocked, and SIGINT
and SIGQUIT will be ignored."
and also:
"As mentioned, system() ignores SIGINT and SIGQUIT. This may make pro‐
grams that call it from a loop uninterruptible, unless they take care
themselves to check the exit status of the child. E.g.
while (something) {
int ret = system("foo");
if (WIFSIGNALED(ret) &&
(WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))
break;
}"
So, either this side effect should be mentioned in Lua reference manual
for os.execute() (so the equivalent program snippet would be
"ret=os.execute(); if ret>0 then os.exit(ret) end"), or os.execute()
should check for the return code itself and call exit() for SIGINT/SIGQUIT.
Regards,
miko