help with signals (ultrix)
Simon Brown
simon at its63b.ed.ac.uk
Mon Mar 7 05:49:43 AEST 1988
In article <1583 at boulder.Colorado.EDU> cdash at boulder.Colorado.EDU (Charles Shub) writes:
>on at&t unix if a system call to (eg) read is in progress when a signal
>occurs, the system call fails. On sun unix and ultrix, the system call
>restarts. On the sun, one can use siginterrupt(3) to make the system call
>fail. How do I make the system call fail under ultrix???????
>we are running 1.2 on microvaxen.
A particularly disgusting way to do this is to close(2) the descriptor being
read from inside the signal-handling routine, keeping a dup(2)'d copy so
you can restore it later. The read(2) cannot restart on a closed descriptor,
so it fails (with errno==EBADF). I'm sure there must be a better way (though
it probably isn't so portable :-)):
extern int descriptor;
static int dupdescriptor;
handler()
{
dup2(descriptor, dupdescriptor);
close(descriptor);
}
readchar()
{
char ch;
switch (read(descriptor,&ch,1)) {
case -1:
if (errno == EBADF) {
descriptor = dupdescriptor;
return(INTERRUPTED);
} else return(...);
case 0:
return(EOF);
default:
return(ch);
}
}
--
--
--------------------------------------------------
| Simon Brown |
| Laboratory for Foundations of Computer Science |
| Department of Computer Science |
| University of Edinburgh, Scotland, UK. |
--------------------------------------------------
UUCP: uunet!mcvax!ukc!lfcs!simon
ARPA: simon%lfcs.ed at nss.cs.ucl.ac.uk "Life's like that, you know"
JANET: simon at uk.ac.ed.lfcs
More information about the Comp.unix.questions
mailing list