|
Signal() sigaction() and IO interrupt
Hi,
I'm currently discovering a strange behavior with signal() and sigaction() on a RHEL 4.
During a syscall like read interrupted by an ALARM signal : in both cases the handler function is called, but with signal() : the read() continues indeed the read() call is stopped if I use sigaction.
The code :
--------------------------------------------------
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <signal.h>
void callback(int param)
{
printf("signal !! \n");
}
int main(void)
{ int fd,ret;
char t;
struct sigaction sig;
sig.sa_handler=callback;
sigaction(SIGALRM,&sig,NULL);
fd=open("/dev/ttyS0",O_RDONLY);
printf("open\n");
if(fd<0)exit(1);
alarm(5);
printf("alarm\n");
ret=read(fd,&t,1);
printf("lu=%d (ret=%d)\n",t,ret);
close(fd);
exit(0);
}
--------------------------------------------------
When running, the read() call is interrupted :
> ./sigread
open
alarm
signal !!
lu=0 (ret=-1)
>
But, if I replace sigaction() with :
signal(SIGALRM,callback);
The read() call is not interrupted :
> ./sigread
open
alarm
signal !!
^C
>
I know that :
"The sigaction() function provides a more comprehensive and reliable mechanism for controlling signals; new applications should use sigaction() rather than signal()."
but IHMO it is not sufficient ...
Does anyone have any explanation of this difference ?
Thanks
|