BSD vs. Sys V alarm and SIGALRM PROBLEMS!

Pond Scum hue at island.COM
Thu Feb 7 19:23:16 AEST 1991


In article <121464 at uunet.UU.NET> rbj at uunet.UU.NET (Root Boy Jim) writes:
>There are two kinds of system calls. Ones that are interruptible,
>and ones that aren't. Most are not. Wait and read or write on a
>slow device (such as a tty, where input may never occur) are
>interruptible. When interrupted by a signal handler, they
>return -1 and set errno to EINTR, or EAGAIN or some such.

Writes to a file appear to be interruptable and not restartable under SunOS
4.1.1.  Suprised the sh*t out of me when someone started having problems with
it.  In 4.0.3 and previous versions writes to "fast" devices could not
be interrupted.  I'll post the test program in a followup.


>Berkeley changed these calls to automaticly restart in 4.2BSD.
>Purists screamed long and hard and a bit was put into the sigvec
>to allow a choice to be made for each type of signal.

For the original poster, in order to prevent the auto restart, use sigvec()
or sigaction() (only available in SunOS 4.1.1), and specify SV_INTERRUPT
in the sv_flags field (SA_INTERRUPT and sa_flags for sigaction()).

>I don't know which versions you have. Another complication is
>that you are using two timeouts, not one. Probably the most
>portable solution is to use setjmp with the getchar and
>longjmp from the alarm routine.

If all you want is a timeout on tty input, I'd just use VTIME and VMIN, seems
simpler to me (though perhaps less portable):

#include <sys/termios.h>
#include <stdio.h>

main()
{
    struct termios oldt, newt;
    int c;

    ioctl(fileno(stdin), TCGETS, &oldt);
    newt = oldt;
    newt.c_cc[VMIN] = 0;
    newt.c_cc[VTIME] = 50;
    newt.c_lflag &= ~ICANON;
    ioctl(fileno(stdin), TCSETS, &newt);
    if ((c = getchar()) == EOF)
	fputs("No input\n", stderr);
    ioctl(fileno(stdin), TCSETS, &oldt);
    return(0);
}

(I know this isn't internals, but this is where to followups were directed)

----
"I'll tell you what "MTV" stands for.  It stands for "Music To Vomit by"."
-Bobby "The Brain" Heenan

Jonathan Hue, Senior Coding Pig	   Island Grapics Corp.  Graphic Arts Division
4000 Civic Center Drive San Rafael, CA  {uunet,sun}!island!hue  hue at island.com



More information about the Comp.unix.internals mailing list