2010/4/26 Eric Blake <eblake(a)redhat.com>:
On 04/25/2010 05:32 AM, Matthias Bolte wrote:
> ---
> examples/domain-events/events-c/event-test.c | 7 ++++---
> 1 files changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/examples/domain-events/events-c/event-test.c
b/examples/domain-events/events-c/event-test.c
> index 53a3195..74eabba 100644
> --- a/examples/domain-events/events-c/event-test.c
> +++ b/examples/domain-events/events-c/event-test.c
> @@ -380,10 +380,11 @@ int main(int argc, char **argv)
> int callback5ret = -1;
> int callback6ret = -1;
> int callback7ret = -1;
> + struct sigaction action_stop;
>
> - struct sigaction action_stop = {
> - .sa_handler = stop
> - };
> + memset(&action_stop, 0, sizeof action_stop);
> +
> + action_stop.sa_handler = stop;
ACK. By the way, the "for some reason" boils down to how sa_handler is
declared in <signal.h> on the two platforms. On cygwin, sa_handler
happens to be a member of an anonymous union (exploiting a gcc
extension); whereas on Linux, it is a macro that accesses a member of a
named union. If I read POSIX correctly, both behaviors for the
declaration of sa_handler are permitted. But dotted assignment only
works in the case of a named union. Whether it is a gcc bug that you
can't use dotted assignment to access a member of an anonymous union, or
a cygwin bug for having a header that does not allow compilation like
Linux (when cygwin's stated goal is to be Linux-compatible) is debatable.
By the way, this use of memset() to initialize action_stop assumes that
the null pointer is all 0 bits (which is probably okay for all platforms
that libvirt will ever run on). There is currently a discussion on
gnulib on the fact that to be portable to C99, where a null pointer
might not be all 0 bits, you would instead have to use the more
drawn-out sequence:
You say null pointer, but where's the pointer in this example?
Do you really refer to pointers or to the initialization of memory?
I wonder what's the use case for this.
static struct sigaction zero_sigaction = {0};
struct sigaction action_stop = zero_sigaction;
action_stop.sa_handler = stop;
But don't go changing this commit just for that theoretical platform.
Thanks, pushed.
Matthias