This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

sigwait() and "sticky" signals (SIGWINCH...) in Cygwin 1.7

I observe strange behavior of sigwait() with SIGWINCH signal (and possibly
others... like SIGCHLD).

Look at a short program below. In a loop I wait for SIG{INT,WINCH} signals.
SIGWINCH, similarly to SIGCHLD is ignored by default, so I had to register a
dummy signal handler for it.

When the program (compiled with gcc-4) is running, SIGWINCH is never returned by
the sigwait() immediately after window's resize, but always along with
successive SIGINT when I press Ctrl+C.


My system is:

$ uname -a
CYGWIN_NT-6.0 wrachwal-PC 1.7.0(0.212/5/3) 2009-08-20 10:56 i686 Cygwin

running at rxvt + zsh


/* sigwait.c -- trying sigwait with various signals */

#include <signal.h>
#include <unistd.h>
#include <string.h> // strerror()
#include <stdlib.h> // exit()
#include <stdio.h>
#include <assert.h>


static void winch_signal_handler (int sig)
    static const char* msg = "!!! winch_signal_handler: unexpected call\n";
    /* async-signal safe "print" */
    ssize_t dont_care = write(/*stdout*/1, msg, sizeof(msg) - 1);
    dont_care = dont_care;


int main ()
    sigset_t ss;
    struct sigaction sa;
    int error;
    int status;
    int sigint_count = 0;

    sigaddset(&ss, SIGWINCH);
    sigaddset(&ss, SIGINT);

    error = pthread_sigmask(SIG_BLOCK, &ss, NULL);
    assert(0 == error);

    sa.sa_flags = 0;
    sa.sa_handler = &winch_signal_handler;

    status = sigaction(SIGWINCH, &sa, NULL);
    assert(-1 != status);

    printf("# entering sigwait() loop...\n");

    while (1) {
        int signo;
        error = sigwait(&ss, &signo);
        if (error == 0) {
            if (signo == SIGWINCH) {
                printf("Got SIGWINCH\n");
            if (signo == SIGINT) {
                printf("Got SIGINT (#%d)\n", sigint_count);
                if (sigint_count == 5) {
        else {
            printf("sigwait: %s\n", strerror(error));

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]