[comp.unix.wizards] help with signals

cdash@boulder.Colorado.EDU (Charles Shub) (03/05/88)

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

cdash   aka cdash@boulder.colorado.edu    aka ...hao!boulder!cdash
	aka ...nbires!boulder!cdash       aka  (303) 593-3492

wolfgang@mgm.mit.edu (Wolfgang Rupprecht) (03/06/88)

In article <1583@boulder.Colorado.EDU> cdash@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???????

Another (hack) way to do this involves a setjump/longjump pair. Put a
setjump around the system call, set a signal handler for the signal in
question, and finally put a longjump in the signal handler to the
setjump saved point. (Don't forget to take down the signal handler
after use, or else you will find yourself longjumping back to the same
section of code everytime a signal of that type comes in.)

--
Wolfgang Rupprecht	ARPA:  wolfgang@mgm.mit.edu (IP 18.82.0.114)
326 Commonwealth Ave.	UUCP:  mit-eddie!mgm.mit.edu!wolfgang
Boston, Ma. 02115	TEL:   (617) 267-4365

simon@its63b.ed.ac.uk (Simon Brown) (03/07/88)

In article <1583@boulder.Colorado.EDU> cdash@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@nss.cs.ucl.ac.uk      "Life's like that, you know"
 JANET: simon@uk.ac.ed.lfcs