[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Is the registry needed?
- From: Patrick Donnelly <batrick@...>
- Date: Thu, 1 Oct 2015 10:25:07 -0400
On Wed, Sep 30, 2015 at 4:54 PM, Sean Conner <firstname.lastname@example.org> wrote:
> It was thus said that the Great Soni L. once stated:
>> This is VERY unsafe! You're potentially breaking a sandbox by doing a
>> sethook. And you don't reset it, either.
> If you mean "I don't call lua_sethook(L,NULL,0,0)" then you have misread
> the code---I do call that. But if you mean "I don't restore the previous
> hooks" then you're right, I don't. When I first started this implementation
> of the signal module, I was concerned about that. And I tried. And it was
> very fragile. I then decided to check how other signal modules handled this
> and guess what? NONE OF THEM RESTORE THE HOOKS! Not even the standalone
> Lua interpeter bothers with restoring any hooks.
>> And you're doing it from a separate thread.
> Potentially a different thread. If you don't create coroutines, then
> everything works just fine (for various values for fine ). Yes,
> attempting to handle signals with Lua coroutines is ... challenging. One
> solution I tried was keeping track of every lua_State that went through
> signal.catch(), and then setting a hook in every one and that didn't go very
> well because it doesn't work when a new coroutine created in the meantime is
> started and ...
One solution is to set the hook on the main thread during startup and
that hook is inherited by all child coroutines. Unfortunately, the
cost for that is somewhat high. I did that back in 2010:
I ultimately removed it because nobody liked the penalty. [We really
need a way to interrupt/hook all threads in Lua...]