XENIX <-> ULTRIX interrupts & traps

Kenneth R. Ballou ballou at brahms
Wed Nov 12 05:33:26 AEST 1986


In article <43 at samira.UUCP> mike at samira.UUCP (Mike Deutsch) writes:
>I have a program written in C which I need to run under both ULTRIX 1.2
>on an 8600 and Microsoft sys V XENIX on an IBM AT.
>
>In the application, the user enters commands from the keyboard.
>I trap interrupts, and go to an interrupt handler when they hit
>interrupt.  In this handler, I ask the user if they wish to continue
>or abort.
>
>Under XENIX, when the program returns from the interrupt handler, the
>program doesn't still expect to be reading at the read where the interrupt
>trap was received.  Under ULTRIX, it does.
>
>1)  Which one is correct?  It's the same code, both C, so one must be wrong.

ABSOLUTELY NOT!  Library functions are exactly that:  library functions.
C does not specify how library functions must behave, or even what functions
must be provided in an implementation's library.

Now, if you browse through signal.h, you will note an error value called
EINTR.  At least on BSD 4.2, if a signal arrives while read is awaiting
data, read returns -1 and errno is set to EINTR:

     [EINTR]	    A read from	a slow device was interrupted
		    before any data arrived by the delivery of a
		    signal.

Again, please note that this is part of UNIX, not of C proper.

>2)  I'd prefer the program to function as it does under XENIX.  How can
>I get it to not continue with the read when there was an interrupt during
>the read?

Since read has returned -1, it seems you could examine the value of errno
and repeat the read call if errno is equal to EINTR, viz.:

	while (read (....) == -1 && errno == EINTR)
		;

Probably you will want to save the value returned by read for later use.

--------
Kenneth R. Ballou		...!ucbvax!brahms!ballou
Dept. of Mathematics		ballou at brahms.berkeley.EDU
University of California
Berkeley, California



More information about the Comp.unix.questions mailing list