On Fri, May 24, 2019 at 08:18:22AM +0100, Daniel Silverstone wrote:
On Sun, Apr 21, 2019 at 19:02:07 +0100, Richard Ipsum wrote:
> diff --git a/luxio.c b/luxio.c
> +
> +static struct {
> + lua_State *state;
> + lua_Hook orighook;
> + int orighookmask;
> + int orighookcount;
> + sigset_t origset;
> + int signo;
> + int handlers[512];
Is 512 a defined limit on handlers, or is this a magic number you've derived
from somewhere else? If the latter, can it be a define (LUXIO_MAX_SIGNAL) or
somesuch?
The platform I'm using defines NSIG to be 33. NSIG sadly isn't in POSIX,
on Linux NSIG is 65, since it's not portable I just picked a number
that's much larger than either of these, it wastes memory but wasting
a few ints to gain the convenience of an array seems fine to me.
I agree that it should be defined in a constant.
> +} luxio__signal_ctx;
Currently this approach means that only one Lua VM in a given process could
have signal handlers registered -- I'm "okay" with that, but it's
worth
documenting the limitation.
I hadn't thought about there being more than one VM, I'll try and have
a think about how best to address this.
> +static void luxio__sigaction_handler(int signo)
Is there value in being an `sa_sigaction` handler and saving / passing-to-lua
any of the siginfo_t ? If not, no worries.
I'd like to do that as well, just started with the basics to see if the
approach is reasonable.
> +static int
> +luxio_sigaction(lua_State *L)
Documentation comment for this please, so that the generated docs can
explain both what a signal is, what the limitations are on it, etc.
Ack
> +{
> + int signo;
> + struct sigaction sa = {
> + .sa_handler = luxio__sigaction_handler
> + };
> +
> + signo = luaL_checkinteger(L, 1);
This number can end up out of the range of valid signals (e.g. less than one
or more than your 512 above).
Good point
> +
> + if (!lua_isfunction(L, 2)) {
> + lua_pushinteger(L, -1);
> + lua_pushinteger(L, EINVAL);
> + return 2;
> + }
Would it make sense to support nil in this position to mean "deregister
handler" ?
Yeah I think that would be a good idea.
---
This looks like a reasonable approach over-all and I'd support merging it with
the above concerns resolved (such as deregistering handlers, dealing with the
limits, etc).
Thank you, and again I apologise for taking so long to respond.
Thanks for the feedback!
Richard