fbp@cybvax0.UUCP (Rick Peralta) (08/08/85)
What is the proper behavior of an alarm call. Below is an extract of a public domain program. To get it to work on a VAX (4.2) I made some changes. What is the proper way to handle the timeout condition ? Is the original way "legal" (I know it works on most machines) ? Also what liabilities are incured by calling setjmp so frequently ? Any suggestions, comments or discussion welcome. #ifdef BSD #include <setjmp.h> jmp_buf alrmbuf ; #endif /* receive a byte from sender */ recvbyte(seconds,bitmask) unsigned seconds; int bitmask; { char c; int alarmfunc(); /* forward declaration */ #ifdef BSD if ( setjmp (alrmbuf) ) return (TO) ; #endif signal(SIGALRM,alarmfunc); /* catch alarms */ alarm(seconds); /* set clock */ if (read (0, &c, 1) < 0) /* get char or timeout */ return (TO); alarm(0); /* clear clock */ return (c&bitmask); } /* dummy alarm function */ alarmfunc() { #ifdef BSD longjmp ( alrmbuf, 1 ); #endif return; } Rick ...!cybvax0[!dmc0]!fbp "A likely story. I don't believe a word of it."
rlk@wlcrjs.UUCP (Richard L. Klappal) (08/11/85)
Concerning setjmp/longjmp/signal in BSD4.2 vs V7/BSD4.1/?? Several months ago, UNIXWORLD mag had an article documenting and illustrating the fix needed. I don't recall all of the details, but I think --Lauren-- may have authored the article.
peter@baylor.UUCP (Peter da Silva) (08/12/85)
> What is the proper behavior of an alarm call. > > Below is an extract of a public domain program. > To get it to work on a VAX (4.2) I made some changes. > What is the proper way to handle the timeout condition ? > Is the original way "legal" (I know it works on most machines) ? The original way worked on everything except a 4.2 system. UCB wanted a cleaner way to deal with signals that didn't trash system calls, so they changed the way they worked. The fact that they didn't leave the old method in is my only major gripe with 4.2. They should have at least implemented a "killsys()" call when you wanted to abort the system call you happened to be in when the alarm occurred. -- Peter da Silva (the mad Australian) UUCP: ...!shell!neuro1!{hyd-ptd,baylor,datafac}!peter MCI: PDASILVA; CIS: 70216,1076