NetBSD-Users archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: [Signal handler] Bug or feature ?
* BERTRAND Jol (joel.bertrand%systella.fr@localhost) wrote:
> volatile int flag;
>
> flag = 0;
>
> do
> {
> code_retour = nanosleep(&temporisation, &temporisation);
> erreur = errno;
>
> if (flag == 1)
> {
> exit(0);
> }
> } while((code_retour == -1) && (erreur == EINTR));
>
> SIGINT signal handler is :
>
> void
> interruption1(int signal)
> {
> flag = 1;
> return;
> }
I'm not sure what you are expecting to test.
But the code should look like the attached main.c.
Testing flag is redundant anyway.
--
Pongthep Kulkrisada
"UNIX is basically a simple operating system,
but you have to be a genius to understand the simplicity."
-- Dennis M. Ritchie
#include <signal.h>
#include <setjmp.h>
#include <errno.h>
#include <time.h>
#include <stdlib.h>
#include "wrappers.h"
volatile int flag = 0;
sigjmp_buf env;
void interruption1(int);
int main()
{
int code_retour, erreur;
struct timespec temporisation;
temporisation.tv_sec = 1;
temporisation.tv_nsec = 0;
if (signal(SIGINT, interruption1) == SIG_ERR)
err_sys("signal");
do {
code_retour = nanosleep(&temporisation, NULL);
erreur = errno;
if (sigsetjmp(env, 1) == 127)
if (flag == 1)
exit(0);
} while ((code_retour == 0) || (erreur == EINTR));
/* Infinite if timeout or get interrupted. *
* The only escape is through the signal handler. */
return 0;
}
void interruption1(int sig)
{
if (sig == SIGINT) {
flag = 1;
siglongjmp(env, 127);
}
}
Home |
Main Index |
Thread Index |
Old Index