Xref: utzoo comp.unix.questions:5974 comp.unix.wizards:6890 Path: utzoo!mnetor!uunet!mcvax!ukc!its63b!simon From: simon@its63b.ed.ac.uk (Simon Brown) Newsgroups: comp.unix.questions,comp.unix.wizards Subject: Re: help with signals (ultrix) Message-ID: <1042@its63b.ed.ac.uk> Date: 6 Mar 88 19:49:43 GMT References: <1583@boulder.Colorado.EDU> Reply-To: simon@its63b.ed.ac.uk (Simon Brown) Organization: LFCS, University of Edinburgh Lines: 49 Keywords: signal, system call restart/failure 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