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]

BUG: ualarm(0,0) not clearing ualarms


I have encounted a bug in Cygwin whereby ualarm(0,0) is not clearing
previously set ualarms.  This first cropped up while using Perl, but I
was able to reproduce the bug with the following 'C' program.  The gist
is that ualarm() is used several times, and then a final ualarm(0,0) is
executed to clear them.  This is followed by a usleep().  The alarm
signal handler shows that 'bogus' alarms are going off during the
usleep().  Without the signal handler, the program would terminate
prematurely due to uncaught SIGALRM.

/*
 * Reproduces bug associated with ualarm
 *
 * Make using:  gcc -o ualarm_bug.exe ualarm_bug.c
 *
 * Typical output:
 *
 *        First ualarm  - one shot
 *        Second ualarm - one shot
 *        Last ualarm   - repeats 3 times
 *        Clearing ualarm
 *        Sleeping
 *        --- BOGUS ALARM ---
 *        --- BOGUS ALARM ---
 *        Done
 *
 */

#include <unistd.h>
#include <signal.h>

/* Increments a counter when alarm goes off */
int tick;

void
inc_tick(int signal)
{
    tick++;
}

/* Prints out a warning message when an alarm goes off */
void
bogus(int signal)
{
    printf("--- BOGUS ALARM ---\n");
}


int
main(int argc, char **argv)
{
    int counter;

    /* Set incrementing alarm handler */
    signal(SIGALRM, &inc_tick);

    printf("First ualarm  - one shot\n");
    tick = 0; ualarm(10000, 0); while (tick == 0) { counter++; };

    printf("Second ualarm - one shot\n");
    tick = 0; ualarm(10000, 0); while (tick == 0) { counter++; };

    printf("Last ualarm   - repeats 3 times\n");
    tick = 0; ualarm(10000, 10000); while (tick < 3) { counter++; };

    printf("Clearing ualarm\n");
    ualarm(0, 0);

    /* Set warning alarm handler */
    signal(SIGALRM, &bogus);

    printf("Sleeping\n");
    usleep(500000);

    printf("Done\n");
    exit(0);
}

/* EOF */


--
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/


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