PROBLEM - Signals not handled while waiting on semphores

Gabi Davar Gabid@emblazesemi.com
Mon Feb 23 12:45:00 GMT 2004


Hi,

I'm unable to receive signals while waiting on semaphores. The following 
short program illustrates the problem. Sending SIGUSR1 when in semop 
does not result in "sig handler!!!" print.

Attached strace dump & cygcheck.

Anyone can help me out is making this work or explain what's going on?

======================================================================
#include <signal.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <unistd.h>
#include <sys/fcntl.h>
#include <sys/sem.h>
#include <errno.h>

void GIntHandler( int bogus )
{
    printf( "sig handler!!!\n" );
}


#define PERMS (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH)

int main()
{
    struct sigaction gintact;
    int semid;
    union semun {
        int val;
        struct semid_ds *buf;
        unsigned short *array;
    } arg;
    
    gintact.sa_handler = &GIntHandler;
    gintact.sa_flags = SA_RESTART;
    
    if (sigemptyset( &gintact.sa_mask ) < 0) {
          perror("Failed to initialize the signal mask");
          return 1;
    }

    if (sigaction( SIGUSR1, &gintact, NULL ) < 0) {
        perror("Failed to install the handler");
        return 1;
    }
    
    if ((semid = semget( (key_t)1997, 1, PERMS | IPC_CREAT )) == -1 ) {
        perror( "Failed to create sempahore" );
        return 1;
    }
    
    arg.val = 0;
    
    if (semctl(semid, 0, SETVAL, arg) < 0) {
        perror( "Failed to initialize smeaphore" );
        return 1;
    }

    {
        struct sembuf op;

        op.sem_num = (short)0;
        op.sem_op = (short)-1;
        op.sem_flg = (short)0;
        if (semop( semid, &op, 1 ) < 0) {
            perror( "failed to perform action on sempatore" );
            return 1;
        }
    }

    return 0;
}


Gabi Davar
Emblaze Semiconductor LTD.
Phone:  +972 9 7699566
Email:  gabid@emblazesemi.com
Web:    www.EmblazeSemi.com
 

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cygcheck.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20040223/11fcfdea/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: sig_test.out
URL: <http://cygwin.com/pipermail/cygwin/attachments/20040223/11fcfdea/attachment-0001.ksh>
-------------- next part --------------
--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


More information about the Cygwin mailing list