Skip to content

Commit 6adb798

Browse files
Update fcntl F_SETFL usage. (#144)
This changes from `FASYNC` to `O_ASYNC`, `FNDELAY` to `O_NONBLOCK`, and `O_NDELAY` to `O_NONBLOCK`. These are the modern names. `O_NONBLOCK` is part of the POSIX standard. However, `O_ASYNC` is specific to Linux and BSD. It is not available on Solaris, where we still need to use `FASYNC`. Also, the behavior of having I/O trigger a `SIGIO` signal is not in POSIX, since the `SIGIO` signal is not in POSIX. Instead, it is only the behavior of having `SIGURG` being signalled for out of band data that is specified. We also takes this opportunity to collapse some multi-line calls to get the flags, store it into a temp, and then set them, to just doing it in one line, skipping the stored temporary value. We also change one instance of `65535 - FNDELAY` to `~O_NONBLOCK`. Closes Interlisp/medley#85.
1 parent 3b1bdd2 commit 6adb798

File tree

16 files changed

+42
-58
lines changed

16 files changed

+42
-58
lines changed

src/Cldeetr.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ int main(int argc, char *argv[])
5050
{
5151
char Earg[30], Ename[30], **newargv;
5252
int i;
53-
int flags;
5453
/* Kickstart program for the Lisp Development Environment (LDE).
5554
Run this as setuid root to open the LDE ether socket.
5655
Passes all arguments through to LDE plus -E <ether-info>
@@ -141,8 +140,7 @@ int main(int argc, char *argv[])
141140
bcopy(if_data.ifc_req[0].ifr_addr.sa_data, ether_host, 6);
142141
strcpy(Ename, if_data.ifc_req[0].ifr_name);
143142

144-
flags = fcntl(ether_fd, F_GETFL, 0);
145-
fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
143+
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
146144

147145
#ifdef DEBUG
148146
printf("init_ether: **** Ethernet starts ****\n");

src/chardev.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ LispPTR CHAR_openfile(LispPTR *args)
8484
Lisp_errno = (int *)(Addr68k_from_LADDR(args[2]));
8585

8686
LispStringToCString(args[0], pathname, MAXPATHLEN);
87-
flags = O_NDELAY;
87+
flags = O_NONBLOCK;
8888
ERRSETJMP(NIL);
8989
/* TIMEOUT( rval=stat(pathname, &statbuf) );
9090
if(rval == 0){ } */
@@ -103,7 +103,7 @@ LispPTR CHAR_openfile(LispPTR *args)
103103
}
104104
/* Prevent I/O requests from blocking -- make them error */
105105
/* if no char is available, or there's no room in pipe. */
106-
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | FNDELAY);
106+
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
107107

108108
return (GetSmallp(fd));
109109
#endif /* DOS */

src/ether.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,6 @@ void init_ether() {
779779
differences are in commented-out code below
780780
(not ifdefed because they're untested...)
781781
*/
782-
int flags;
783782
struct strioctl si;
784783
unsigned long snaplen = 0;
785784

@@ -822,8 +821,7 @@ void init_ether() {
822821
return;
823822
}
824823

825-
flags = fcntl(ether_fd, F_GETFL, 0);
826-
fcntl(ether_fd, F_SETFL, flags | O_NDELAY);
824+
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_NONBLOCK);
827825

828826
} else {
829827
I_Give_Up:
@@ -858,7 +856,7 @@ void init_ether() {
858856
#else /* OS4 */
859857

860858
if (getuid() != geteuid()) {
861-
if ((ether_fd = open("/dev/nit", O_RDWR | FASYNC)) >= 0) {
859+
if ((ether_fd = open("/dev/nit", O_RDWR | O_ASYNC)) >= 0) {
862860
/* it's open, now query it and find out its name and address */
863861
/* JRB - must document that LDE uses the first net board as
864862
found by SIOCGIFCONF (see if(4)). Maybe we need an option
@@ -1020,7 +1018,7 @@ void init_ether() {
10201018
#endif /* USE_DLPI */
10211019
#endif /* PKTFILTER -- jds 23 sep 96 unmatched if fix */
10221020
#ifndef PKTFILTER
1023-
if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | FASYNC | FNDELAY) < 0)
1021+
if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK) < 0)
10241022
perror("Ether setup SETFLAGS fcntl");
10251023
if (fcntl(ether_fd, F_SETOWN, getpid()) < 0) perror("Ether setup SETOWN");
10261024
#else /* PKTFILTER */

src/inet.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@
2828
#include <unistd.h>
2929
#endif /* DOS */
3030

31+
#ifdef OS5
32+
/* Solaris doesn't define O_ASYNC, yet still defines FASYNC. */
33+
#define O_ASYNC FASYNC
34+
#endif
35+
3136
#include "lispemul.h"
3237
#include "lispmap.h"
3338
#include "lsptypes.h"
@@ -106,7 +111,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
106111
addr_class = LispNumToCInt(nameConn);
107112
protocol = LispNumToCInt(proto);
108113
result = socket(addr_class, protocol, 0);
109-
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY | FASYNC);
114+
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
110115
fcntl(result, F_SETOWN, getpid());
111116

112117
return (GetSmallp(result));
@@ -130,7 +135,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
130135
perror("TCP connect");
131136
return (NIL);
132137
}
133-
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY);
138+
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK);
134139
fcntl(result, F_SETOWN, getpid());
135140

136141
return (GetSmallp(result));
@@ -203,7 +208,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
203208
int oldmask = sigblock(sigmask(SIGIO));
204209
#endif /* SYSVSIGNALS */
205210

206-
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY | FASYNC);
211+
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
207212
fcntl(result, F_SETOWN, getpid());
208213

209214
if (listen(result, 5) == -1) {
@@ -236,7 +241,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
236241
if (errno != EWOULDBLOCK) perror("TCP Accept");
237242
return (NIL);
238243
}
239-
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY);
244+
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK);
240245
fcntl(result, F_SETOWN, getpid());
241246

242247
return (GetSmallp(result));
@@ -274,7 +279,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
274279
close(result);
275280
return (NIL);
276281
}
277-
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY | FASYNC);
282+
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
278283
fcntl(result, F_SETOWN, getpid());
279284

280285
FD_SET(result, &LispIOFds); /* so we get interrupts */

src/initdsp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ void init_display2(DLword *display_addr, int display_max)
335335
/* int_io_open(LispWindowFd); JDS 4/27/94 move to initkbd, to try preventing the
336336
* move-mouse-never-get-kbd bug */
337337
#endif
338-
fcntl(LispWindowFd, F_SETFL, fcntl(LispWindowFd, F_GETFL, 0) | FNDELAY);
338+
fcntl(LispWindowFd, F_SETFL, fcntl(LispWindowFd, F_GETFL, 0) | O_NONBLOCK);
339339
}
340340
#endif /* SUNDISPLAY */
341341

src/ldeether.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ char filetorun[30] = "lde";
7676
int main(int argc, char *argv[]) {
7777
char Earg[30], Ename[30], **newargv;
7878
int i;
79-
int flags;
8079
#ifdef USE_DLPI
8180
static struct packetfilt pf = {0, 1, {ENF_PUSHZERO}};
8281
struct strioctl si;
@@ -129,8 +128,7 @@ int main(int argc, char *argv[]) {
129128
return (-1);
130129
}
131130

132-
flags = fcntl(ether_fd, F_GETFL, 0);
133-
fcntl(ether_fd, F_SETFL, flags | O_NDELAY);
131+
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_NONBLOCK);
134132

135133
#else
136134
/* N O T D L P I C O D E */
@@ -210,8 +208,7 @@ int main(int argc, char *argv[]) {
210208
bcopy(if_data.ifc_req[0].ifr_addr.sa_data, ether_host, 6);
211209
strcpy(Ename, if_data.ifc_req[0].ifr_name);
212210

213-
flags = fcntl(ether_fd, F_GETFL, 0);
214-
fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
211+
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
215212

216213
#endif /* USE_DLPI */
217214
#ifdef DEBUG

src/ocr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ int doblock;
408408
if (flags < 0) return 0;
409409

410410
if (doblock) {
411-
flags &= ~FNDELAY;
411+
flags &= ~O_NONBLOCK;
412412
} else {
413-
flags |= FNDELAY;
413+
flags |= O_NONBLOCK;
414414
}
415415

416416
if (fcntl(fd, F_SETFL, flags) < 0) return 0;

src/ocrproc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ static int ocr_init_sv() {
317317
perror("ocr_init_sv: fcntl");
318318
return 0;
319319
}
320-
flags &= ~FNDELAY;
320+
flags &= ~O_NONBLOCK;
321321
if (fcntl(OCR_sv, F_SETFL, flags) < 0) {
322322
perror("ocr_init_sv: fcntl 2");
323323
return 0;

src/oether.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ void init_ether() {
667667
#else /* OS4 */
668668

669669
if (getuid() != geteuid()) {
670-
if ((ether_fd = open("/dev/nit", O_RDWR | FASYNC)) >= 0) {
670+
if ((ether_fd = open("/dev/nit", O_RDWR | O_ASYNC)) >= 0) {
671671
/* it's open, now query it and find out its name and address */
672672
/* JRB - must document that LDE uses the first net board as
673673
found by SIOCGIFCONF (see if(4)). Maybe we need an option
@@ -808,7 +808,7 @@ if (ether_fd >= 0) {
808808
}
809809
#ifndef OS4
810810
EtherReadFds |= (1 << ether_fd);
811-
if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | FASYNC | FNDELAY) < 0)
811+
if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK) < 0)
812812
perror("Ether setup SETFLAGS fcntl");
813813
if (fcntl(ether_fd, F_SETOWN, getpid()) < 0) perror("Ether setup SETOWN");
814814
#else /* OS4 */

src/oldeether.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ int main(int argc, char *argv[])
4848
{
4949
char Earg[30], Ename[30], **newargv;
5050
int i;
51-
int flags;
5251
/* Kickstart program for the Lisp Development Environment (LDE).
5352
Run this as setuid root to open the LDE ether socket.
5453
Passes all arguments through to LDE plus -E <ether-info>
@@ -139,8 +138,7 @@ int main(int argc, char *argv[])
139138
bcopy(if_data.ifc_req[0].ifr_addr.sa_data, ether_host, 6);
140139
strcpy(Ename, if_data.ifc_req[0].ifr_name);
141140

142-
flags = fcntl(ether_fd, F_GETFL, 0);
143-
fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
141+
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
144142

145143
#ifdef DEBUG
146144
printf("init_ether: **** Ethernet starts ****\n");

0 commit comments

Comments
 (0)