This is the mail archive of the
cygwin
mailing list for the Cygwin project.
sigwait() and "sticky" signals (SIGWINCH...) in Cygwin 1.7
- From: Waldemar Rachwal <waldemar dot rachwal at gmail dot com>
- To: cygwin at cygwin dot com
- Date: Wed, 26 Aug 2009 20:13:37 +0000 (UTC)
- Subject: 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.
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