msc@qubix.UUCP (Mark Callow) (01/15/84)
Since nobody had done it yet and since my ski-trip this weekend was postponed I decided to roll up my sleeves and fix vnews so that it handles signals properly under 4.2. It turned out to be fairly straightforward. Don't be put off by the length of this article. That's just diff -c for you. There's really only about 15 additional lines of code. Below are the diff's from Bill Sebok's version of vnews to my 4.2 version. There is one change that isn't shown. I changed all sigsys() (I think; I haven't got my 4.1 manuals handy) calls to signal(). I had to do this to get vnews to link under 4.2 and I didn't keep the old version. I also changed visual.c so that it uses the already declared and initialised extern LIB to find the news library for use in the reply and follow commands instead of having the full path name compiled in. Note that there is no need for the setjmp/longjmp uglyness. A simple select call is all it takes. As usual take the line numbers with a grain of salt. =================================================== *** visual.c.old Sat Jan 14 23:19:25 1984 --- visual.c Sat Jan 14 23:26:00 1984 *************** *** 29,34 * 6) Applied many of the bug fixes given on the net. This includes the bug fix * I posted to make ^Z not hang vnews when given from the editor invoked by * the "r" or "f" commands. */ #define STATTOP --- 29,39 ----- * 6) Applied many of the bug fixes given on the net. This includes the bug fix * I posted to make ^Z not hang vnews when given from the editor invoked by * the "r" or "f" commands. + * + * 7) Fixed it for 4.2 signal package. All sigset()'s changed to signal. + * Added statement to clear sigmask in SIGTSTP handler. Changed + * vgetc to use select since that is interrupted by a signal whereas + * read isn't. Mark Callow -- qubix!msc */ #define STATTOP *************** *** 88,94 #define OVWRITE 02 /* overwrite the file if it already exists */ /* shell procedures to reply and post followups */ #ifndef REPLYPROG ! #define REPLYPROG "/usr/new/lib/news/reply" #endif #ifndef FOLLOWPROG #define FOLLOWPROG "/usr/new/lib/news/follow" --- 93,99 ----- #define OVWRITE 02 /* overwrite the file if it already exists */ /* shell procedures to reply and post followups */ #ifndef REPLYPROG ! #define REPLYPROG "reply" #endif #ifndef FOLLOWPROG #define FOLLOWPROG "follow" *************** *** 91,97 #define REPLYPROG "/usr/new/lib/news/reply" #endif #ifndef FOLLOWPROG ! #define FOLLOWPROG "/usr/new/lib/news/follow" #endif /* other files */ #ifndef VHELP --- 96,102 ----- #define REPLYPROG "reply" #endif #ifndef FOLLOWPROG ! #define FOLLOWPROG "follow" #endif /* other files */ #ifndef VHELP *************** *** 868,873 char *arg[8]; FILE *tfp; char subj[132]; char *p; char *replyname(); --- 873,879 ----- char *arg[8]; FILE *tfp; char subj[132]; + char frprog[64]; char *p; char *replyname(); *************** *** 903,909 fprintf(tfp, "Subject: %s\n", subj); if (followup != 2) fprintf(tfp, "In-reply-to: your article %s\n", h.ident); ! arg[1] = REPLYPROG; arg[4] = p; } else { p = h.nbuf; --- 909,916 ----- fprintf(tfp, "Subject: %s\n", subj); if (followup != 2) fprintf(tfp, "In-reply-to: your article %s\n", h.ident); ! sprintf(frprog, "%s/%s", LIB, REPLYPROG); ! arg[1] = frprog; arg[4] = p; } else { p = h.nbuf; *************** *** 917,923 fprintf(tfp, "Keywords: %s\n", h.keywords); if (h.distribution[0]) fprintf(tfp, "Distribution: %s\n", h.distribution); ! arg[1] = FOLLOWPROG; arg[4] = linebuf; } if (followup != 0) { --- 924,931 ----- fprintf(tfp, "Keywords: %s\n", h.keywords); if (h.distribution[0]) fprintf(tfp, "Distribution: %s\n", h.distribution); ! sprintf(frprog, "%s/%s", LIB, FOLLOWPROG); ! arg[1] = frprog; arg[4] = linebuf; } if (followup != 0) { *************** *** 1797,1802 vgetc() { register c; recurse: if (--innleft >= 0) { c = *innext++; --- 1805,1813 ----- vgetc() { register c; + #ifdef BSD4_2 + int readfds, exceptfds; + #endif recurse: if (--innleft >= 0) { c = *innext++; *************** *** 1814,1819 fcntl(0, F_SETFL, oflags); } #endif if ((innleft = read(0, inbuf, INBUFSIZ)) > 0) { #ifdef BSD if (intflag) { --- 1825,1837 ----- fcntl(0, F_SETFL, oflags); } #endif + #ifdef BSD4_2 + /* Use a select because it can be interrupted. */ + readfds = 1; exceptfds = 1; + select(1, &readfds, 0, &exceptfds, 0);; + if (readfds & 1) { /* Got a key. Go and get it. */ + read(0, inbuf, INBUFSIZ); + #else if ((innleft = read(0, inbuf, INBUFSIZ)) > 0) { #endif #ifdef BSD *************** *** 1815,1820 } #endif if ((innleft = read(0, inbuf, INBUFSIZ)) > 0) { #ifdef BSD if (intflag) { intflag--; --- 1833,1839 ----- read(0, inbuf, INBUFSIZ); #else if ((innleft = read(0, inbuf, INBUFSIZ)) > 0) { + #endif #ifdef BSD if (intflag) { intflag--; *************** *** 2143,2148 ttycooked(); signal(signo, SIG_DFL); /* clear SIGTSTP mask bit */ kill(getpid(), signo); /* stop here until continued */ fprintf(stderr,"Vnews restarted."); signal(signo, onstop); --- 2162,2170 ----- ttycooked(); signal(signo, SIG_DFL); /* clear SIGTSTP mask bit */ + #ifdef BSD4_2 + sigsetmask(sigblock(0) & ~(1 << (SIGTSTP-1))); + #endif kill(getpid(), signo); /* stop here until continued */ fprintf(stderr,"Vnews restarted."); signal(signo, onstop); -- From the Tardis of Mark Callow msc@qubix.UUCP, decwrl!qubix!msc@Berkeley.ARPA ...{decvax,ucbvax,ihnp4}!decwrl!qubix!msc, ...{ittvax,amd70}!qubix!msc