delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/08/26/16:14:17

X-Recipient: archive-cygwin AT delorie DOT com
X-SWARE-Spam-Status: No, hits=-2.3 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_33,SPF_HELO_PASS,SPF_PASS
X-Spam-Check-By: sourceware.org
To: cygwin AT cygwin DOT com
From: Waldemar Rachwal <waldemar DOT rachwal AT gmail DOT com>
Subject: sigwait() and "sticky" signals (SIGWINCH...) in Cygwin 1.7
Date: Wed, 26 Aug 2009 20:13:37 +0000 (UTC)
Lines: 91
Message-ID: <loom.20090826T214123-598@post.gmane.org>
Mime-Version: 1.0
User-Agent: Loom/3.14 (http://gmane.org/)
X-IsSubscribed: yes
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com

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.

Regards,
Waldemar.

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;

    sigemptyset(&ss);
    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;
    sigemptyset(&sa.sa_mask);

    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");
            }
            else
            if (signo == SIGINT) {
                ++sigint_count;
                printf("Got SIGINT (#%d)\n", sigint_count);
                if (sigint_count == 5) {
                    printf("End.\n");
                    exit(0);
                }
            }
        }
        else {
            printf("sigwait: %s\n", strerror(error));
        }
    }
}
 


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019