Re: [PATCH] Use macro HANDLER_WRAPPER in sigchain to wrap clean function of sigchain

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



徐迪 <xudifsd@xxxxxxxxx> writes:

> The sigchain APIs require user to code like:
>
> void clean_foo_on_signal(int sig)
> {
>  clean_foo();
>  sigchain_pop(sig);
>  raise(sig);
> }

I can see the repetition, but I do not think your macro is a very good way
to reduce it.  Can't we fix the sigchain API a bit, perhaps first by
making a bit more state available to the sigchain stack?

	typedef void (*sigchain_fn)(int, void *);
        int sigchain_push(int sig, sigchain_fn fn, void *cb_data);
        int sigchain_pop(int sig);
        void sigchain_push_common(sigchain_fn fn, void *cb_data);

And then make the repetitive one into a single copy of a helper function,
while giving a new external interface to register a on_signal handler:

        static void relay_fn(int sig, void *cb_data)
        {
                void (*fn)(void) = cb_data; /* [*1*] */
        	fn();
                sigchain_pop(sig);
                raise(sig);
        }

        void sigchain_add_relayed(void (*fn)(void))
        {
		sigchain_push_common(relay_fn, fn);
        }

The code that wants to register a clean-up action would do:

	sigchain_add_relayed(clean_foo);

instead of

	sigchain_push_common(clean_foo_on_signal);

with repeated definition of clean_xxx_on_signal.

Hmm?

[Footnote]

*1* Yes, I know, this casts between a data pointer and a function pointer
that is not portable, but the purpose of this pseudo-code is primarily to
illustrate the high level view of the idea.  We would probably want to be
able to pass callback value to the clean_foo() function and at that point,
we would likely to be passing a pointer to a struct, and we could declare
the first element of such a struct is a pointer to a sigchain_fn, or
something.
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]