[libvirt] [PATCH] Cygwin's GCC doesn't like this .sa_handler initialization for some reason

Eric Blake eblake at redhat.com
Mon Apr 26 16:41:21 UTC 2010


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:

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.

-- 
Eric Blake   eblake at redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20100426/1585dbd9/attachment-0001.sig>


More information about the libvir-list mailing list