mirror of
https://github.com/Interlisp/maiko.git
synced 2026-01-14 15:36:34 +00:00
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.
This commit is contained in:
parent
3b1bdd225f
commit
6adb79840d
@ -50,7 +50,6 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
char Earg[30], Ename[30], **newargv;
|
||||
int i;
|
||||
int flags;
|
||||
/* Kickstart program for the Lisp Development Environment (LDE).
|
||||
Run this as setuid root to open the LDE ether socket.
|
||||
Passes all arguments through to LDE plus -E <ether-info>
|
||||
@ -141,8 +140,7 @@ int main(int argc, char *argv[])
|
||||
bcopy(if_data.ifc_req[0].ifr_addr.sa_data, ether_host, 6);
|
||||
strcpy(Ename, if_data.ifc_req[0].ifr_name);
|
||||
|
||||
flags = fcntl(ether_fd, F_GETFL, 0);
|
||||
fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
|
||||
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("init_ether: **** Ethernet starts ****\n");
|
||||
|
||||
@ -84,7 +84,7 @@ LispPTR CHAR_openfile(LispPTR *args)
|
||||
Lisp_errno = (int *)(Addr68k_from_LADDR(args[2]));
|
||||
|
||||
LispStringToCString(args[0], pathname, MAXPATHLEN);
|
||||
flags = O_NDELAY;
|
||||
flags = O_NONBLOCK;
|
||||
ERRSETJMP(NIL);
|
||||
/* TIMEOUT( rval=stat(pathname, &statbuf) );
|
||||
if(rval == 0){ } */
|
||||
@ -103,7 +103,7 @@ LispPTR CHAR_openfile(LispPTR *args)
|
||||
}
|
||||
/* Prevent I/O requests from blocking -- make them error */
|
||||
/* if no char is available, or there's no room in pipe. */
|
||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | FNDELAY);
|
||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
|
||||
return (GetSmallp(fd));
|
||||
#endif /* DOS */
|
||||
|
||||
@ -779,7 +779,6 @@ void init_ether() {
|
||||
differences are in commented-out code below
|
||||
(not ifdefed because they're untested...)
|
||||
*/
|
||||
int flags;
|
||||
struct strioctl si;
|
||||
unsigned long snaplen = 0;
|
||||
|
||||
@ -822,8 +821,7 @@ void init_ether() {
|
||||
return;
|
||||
}
|
||||
|
||||
flags = fcntl(ether_fd, F_GETFL, 0);
|
||||
fcntl(ether_fd, F_SETFL, flags | O_NDELAY);
|
||||
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
|
||||
} else {
|
||||
I_Give_Up:
|
||||
@ -858,7 +856,7 @@ void init_ether() {
|
||||
#else /* OS4 */
|
||||
|
||||
if (getuid() != geteuid()) {
|
||||
if ((ether_fd = open("/dev/nit", O_RDWR | FASYNC)) >= 0) {
|
||||
if ((ether_fd = open("/dev/nit", O_RDWR | O_ASYNC)) >= 0) {
|
||||
/* it's open, now query it and find out its name and address */
|
||||
/* JRB - must document that LDE uses the first net board as
|
||||
found by SIOCGIFCONF (see if(4)). Maybe we need an option
|
||||
@ -1020,7 +1018,7 @@ void init_ether() {
|
||||
#endif /* USE_DLPI */
|
||||
#endif /* PKTFILTER -- jds 23 sep 96 unmatched if fix */
|
||||
#ifndef PKTFILTER
|
||||
if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | FASYNC | FNDELAY) < 0)
|
||||
if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK) < 0)
|
||||
perror("Ether setup SETFLAGS fcntl");
|
||||
if (fcntl(ether_fd, F_SETOWN, getpid()) < 0) perror("Ether setup SETOWN");
|
||||
#else /* PKTFILTER */
|
||||
|
||||
15
src/inet.c
15
src/inet.c
@ -28,6 +28,11 @@
|
||||
#include <unistd.h>
|
||||
#endif /* DOS */
|
||||
|
||||
#ifdef OS5
|
||||
/* Solaris doesn't define O_ASYNC, yet still defines FASYNC. */
|
||||
#define O_ASYNC FASYNC
|
||||
#endif
|
||||
|
||||
#include "lispemul.h"
|
||||
#include "lispmap.h"
|
||||
#include "lsptypes.h"
|
||||
@ -106,7 +111,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
|
||||
addr_class = LispNumToCInt(nameConn);
|
||||
protocol = LispNumToCInt(proto);
|
||||
result = socket(addr_class, protocol, 0);
|
||||
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY | FASYNC);
|
||||
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
|
||||
fcntl(result, F_SETOWN, getpid());
|
||||
|
||||
return (GetSmallp(result));
|
||||
@ -130,7 +135,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
|
||||
perror("TCP connect");
|
||||
return (NIL);
|
||||
}
|
||||
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY);
|
||||
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK);
|
||||
fcntl(result, F_SETOWN, getpid());
|
||||
|
||||
return (GetSmallp(result));
|
||||
@ -203,7 +208,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
|
||||
int oldmask = sigblock(sigmask(SIGIO));
|
||||
#endif /* SYSVSIGNALS */
|
||||
|
||||
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY | FASYNC);
|
||||
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
|
||||
fcntl(result, F_SETOWN, getpid());
|
||||
|
||||
if (listen(result, 5) == -1) {
|
||||
@ -236,7 +241,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
|
||||
if (errno != EWOULDBLOCK) perror("TCP Accept");
|
||||
return (NIL);
|
||||
}
|
||||
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY);
|
||||
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_NONBLOCK);
|
||||
fcntl(result, F_SETOWN, getpid());
|
||||
|
||||
return (GetSmallp(result));
|
||||
@ -274,7 +279,7 @@ LispPTR subr_TCP_ops(int op, LispPTR nameConn, LispPTR proto, LispPTR length, Li
|
||||
close(result);
|
||||
return (NIL);
|
||||
}
|
||||
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | FNDELAY | FASYNC);
|
||||
fcntl(result, F_SETFL, fcntl(result, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
|
||||
fcntl(result, F_SETOWN, getpid());
|
||||
|
||||
FD_SET(result, &LispIOFds); /* so we get interrupts */
|
||||
|
||||
@ -335,7 +335,7 @@ void init_display2(DLword *display_addr, int display_max)
|
||||
/* int_io_open(LispWindowFd); JDS 4/27/94 move to initkbd, to try preventing the
|
||||
* move-mouse-never-get-kbd bug */
|
||||
#endif
|
||||
fcntl(LispWindowFd, F_SETFL, fcntl(LispWindowFd, F_GETFL, 0) | FNDELAY);
|
||||
fcntl(LispWindowFd, F_SETFL, fcntl(LispWindowFd, F_GETFL, 0) | O_NONBLOCK);
|
||||
}
|
||||
#endif /* SUNDISPLAY */
|
||||
|
||||
|
||||
@ -76,7 +76,6 @@ char filetorun[30] = "lde";
|
||||
int main(int argc, char *argv[]) {
|
||||
char Earg[30], Ename[30], **newargv;
|
||||
int i;
|
||||
int flags;
|
||||
#ifdef USE_DLPI
|
||||
static struct packetfilt pf = {0, 1, {ENF_PUSHZERO}};
|
||||
struct strioctl si;
|
||||
@ -129,8 +128,7 @@ int main(int argc, char *argv[]) {
|
||||
return (-1);
|
||||
}
|
||||
|
||||
flags = fcntl(ether_fd, F_GETFL, 0);
|
||||
fcntl(ether_fd, F_SETFL, flags | O_NDELAY);
|
||||
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_NONBLOCK);
|
||||
|
||||
#else
|
||||
/* N O T D L P I C O D E */
|
||||
@ -210,8 +208,7 @@ int main(int argc, char *argv[]) {
|
||||
bcopy(if_data.ifc_req[0].ifr_addr.sa_data, ether_host, 6);
|
||||
strcpy(Ename, if_data.ifc_req[0].ifr_name);
|
||||
|
||||
flags = fcntl(ether_fd, F_GETFL, 0);
|
||||
fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
|
||||
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
|
||||
|
||||
#endif /* USE_DLPI */
|
||||
#ifdef DEBUG
|
||||
|
||||
@ -408,9 +408,9 @@ int doblock;
|
||||
if (flags < 0) return 0;
|
||||
|
||||
if (doblock) {
|
||||
flags &= ~FNDELAY;
|
||||
flags &= ~O_NONBLOCK;
|
||||
} else {
|
||||
flags |= FNDELAY;
|
||||
flags |= O_NONBLOCK;
|
||||
}
|
||||
|
||||
if (fcntl(fd, F_SETFL, flags) < 0) return 0;
|
||||
|
||||
@ -317,7 +317,7 @@ static int ocr_init_sv() {
|
||||
perror("ocr_init_sv: fcntl");
|
||||
return 0;
|
||||
}
|
||||
flags &= ~FNDELAY;
|
||||
flags &= ~O_NONBLOCK;
|
||||
if (fcntl(OCR_sv, F_SETFL, flags) < 0) {
|
||||
perror("ocr_init_sv: fcntl 2");
|
||||
return 0;
|
||||
|
||||
@ -667,7 +667,7 @@ void init_ether() {
|
||||
#else /* OS4 */
|
||||
|
||||
if (getuid() != geteuid()) {
|
||||
if ((ether_fd = open("/dev/nit", O_RDWR | FASYNC)) >= 0) {
|
||||
if ((ether_fd = open("/dev/nit", O_RDWR | O_ASYNC)) >= 0) {
|
||||
/* it's open, now query it and find out its name and address */
|
||||
/* JRB - must document that LDE uses the first net board as
|
||||
found by SIOCGIFCONF (see if(4)). Maybe we need an option
|
||||
@ -808,7 +808,7 @@ if (ether_fd >= 0) {
|
||||
}
|
||||
#ifndef OS4
|
||||
EtherReadFds |= (1 << ether_fd);
|
||||
if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | FASYNC | FNDELAY) < 0)
|
||||
if (fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK) < 0)
|
||||
perror("Ether setup SETFLAGS fcntl");
|
||||
if (fcntl(ether_fd, F_SETOWN, getpid()) < 0) perror("Ether setup SETOWN");
|
||||
#else /* OS4 */
|
||||
|
||||
@ -48,7 +48,6 @@ int main(int argc, char *argv[])
|
||||
{
|
||||
char Earg[30], Ename[30], **newargv;
|
||||
int i;
|
||||
int flags;
|
||||
/* Kickstart program for the Lisp Development Environment (LDE).
|
||||
Run this as setuid root to open the LDE ether socket.
|
||||
Passes all arguments through to LDE plus -E <ether-info>
|
||||
@ -139,8 +138,7 @@ int main(int argc, char *argv[])
|
||||
bcopy(if_data.ifc_req[0].ifr_addr.sa_data, ether_host, 6);
|
||||
strcpy(Ename, if_data.ifc_req[0].ifr_name);
|
||||
|
||||
flags = fcntl(ether_fd, F_GETFL, 0);
|
||||
fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
|
||||
fcntl(ether_fd, F_SETFL, fcntl(ether_fd, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
|
||||
|
||||
#ifdef DEBUG
|
||||
printf("init_ether: **** Ethernet starts ****\n");
|
||||
|
||||
@ -85,7 +85,7 @@ void mess_init() {
|
||||
int ttyfd;
|
||||
int ptyfd, ptynum;
|
||||
char *ptyname, *ttyname;
|
||||
int temp, flags;
|
||||
int temp;
|
||||
int on = 1;
|
||||
|
||||
ptyname = "/dev/ptypx";
|
||||
@ -148,8 +148,7 @@ gotpty:
|
||||
if ((log_id = open(logfile, (O_RDWR | O_CREAT), 0666)) < 0) return;
|
||||
#ifdef LOGINT
|
||||
LogFileFd = cons_pty; /* was kept as an fd_set, but doesn't need to be */
|
||||
flags = fcntl(cons_pty, F_GETFL, 0);
|
||||
fcntl(cons_pty, F_SETFL, (flags | FASYNC | FNDELAY));
|
||||
fcntl(cons_pty, F_SETFL, fcntl(cons_pty, F_GETFL, 0) | O_ASYNC | O_NONBLOCK);
|
||||
if (fcntl(cons_pty, F_SETOWN, getpid()) == -1) {
|
||||
#ifdef DEBUG
|
||||
perror("fcntl F_SETOWN of log PTY");
|
||||
|
||||
@ -89,7 +89,7 @@ void init_display2(int display_addr, int display_max)
|
||||
#ifdef KBINT
|
||||
int_io_open(LispWindowFd);
|
||||
#endif
|
||||
fcntl(LispWindowFd, F_SETFL, fcntl(LispWindowFd, F_GETFL, 0) | FNDELAY);
|
||||
fcntl(LispWindowFd, F_SETFL, fcntl(LispWindowFd, F_GETFL, 0) | O_NONBLOCK);
|
||||
}
|
||||
|
||||
DisplayRegion68k = (short *)display_addr;
|
||||
|
||||
@ -546,7 +546,7 @@ void int_io_open(int fd)
|
||||
perror("fcntl F_SETOWN ERROR");
|
||||
#endif
|
||||
};
|
||||
if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | FASYNC) == -1) perror("fcntl F_SETFL error");
|
||||
if (fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | O_ASYNC) == -1) perror("fcntl F_SETFL error");
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -555,7 +555,7 @@ void int_io_close(int fd)
|
||||
#ifdef DOS
|
||||
/* Turn off signaller here */
|
||||
#elif KBINT
|
||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~FASYNC);
|
||||
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) & ~O_ASYNC);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -309,7 +309,7 @@ int FindUnixPipes(void) {
|
||||
/* Find the first PTY pair that is not in use */
|
||||
|
||||
int FindAvailablePty(char *Master, char *Slave) {
|
||||
int res, flags;
|
||||
int res;
|
||||
char *let, *num;
|
||||
|
||||
#ifdef OS5
|
||||
@ -335,10 +335,7 @@ int FindAvailablePty(char *Master, char *Slave) {
|
||||
#endif
|
||||
|
||||
if (res != -1) {
|
||||
flags = fcntl(res, F_GETFL, 0);
|
||||
flags |= FNDELAY;
|
||||
|
||||
fcntl(res, F_SETFL, flags);
|
||||
fcntl(res, F_SETFL, fcntl(res, F_GETFL, 0) | O_NONBLOCK);
|
||||
return (res);
|
||||
}
|
||||
#ifndef FULLSLAVENAME
|
||||
@ -403,7 +400,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
|
||||
case 0: /* Fork pipe process */
|
||||
{
|
||||
char *UpPipeName, *DownPipeName, *PipeName;
|
||||
int res, slot, PipeFD, sockFD;
|
||||
int slot, PipeFD, sockFD;
|
||||
|
||||
/* First create the socket */
|
||||
struct sockaddr_un sock;
|
||||
@ -450,9 +447,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
|
||||
if (unlink(PipeName) < 0) perror("Unlink");
|
||||
return (NIL);
|
||||
}
|
||||
res = fcntl(PipeFD, F_GETFL, 0);
|
||||
res |= FNDELAY;
|
||||
if (fcntl(PipeFD, F_SETFL, res) == -1) {
|
||||
if (fcntl(PipeFD, F_SETFL, fcntl(PipeFD, F_GETFL, 0) | O_NONBLOCK) == -1) {
|
||||
perror("setting up fifo to nodelay");
|
||||
return (NIL);
|
||||
}
|
||||
@ -614,7 +609,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
|
||||
case 11: /* Fork PTY process */
|
||||
{
|
||||
char MasterFD[20], SlavePTY[32];
|
||||
int Master, flags, slot;
|
||||
int Master, slot;
|
||||
unsigned short len;
|
||||
|
||||
Master = FindAvailablePty(MasterFD, SlavePTY);
|
||||
@ -650,9 +645,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
|
||||
DBPRINT(("Pipe/fork result = %d.\n", d[3]));
|
||||
if (d[3] == 1) {
|
||||
/* Set up the IO not to block */
|
||||
flags = fcntl(Master, F_GETFL, 0);
|
||||
flags |= FNDELAY;
|
||||
fcntl(Master, F_SETFL, flags);
|
||||
fcntl(Master, F_SETFL, fcntl(Master, F_GETFL, 0) | O_NONBLOCK);
|
||||
|
||||
UJ[slot].type = UJSHELL; /* so we can find them */
|
||||
UJ[slot].PID = (d[1] << 8) | d[2];
|
||||
@ -832,7 +825,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
|
||||
case 12: /* create Unix socket */
|
||||
|
||||
{
|
||||
int flags, sockFD;
|
||||
int sockFD;
|
||||
struct sockaddr_un sock;
|
||||
|
||||
/* First open the socket */
|
||||
@ -861,9 +854,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
|
||||
DBPRINT(("Socket %d bound to name %s.\n", sockFD, shcom));
|
||||
if (listen(sockFD, 1) < 0) perror("Listen");
|
||||
/* Set up the IO not to block */
|
||||
flags = fcntl(sockFD, F_GETFL, 0);
|
||||
flags |= FNDELAY;
|
||||
fcntl(sockFD, F_SETFL, flags);
|
||||
fcntl(sockFD, F_SETFL, fcntl(sockFD, F_GETFL, 0) | O_NONBLOCK);
|
||||
|
||||
/* things seem sane, fill out the rest of the UJ slot and return */
|
||||
UJ[sockFD].status = -1;
|
||||
|
||||
@ -225,7 +225,7 @@ of the packet received except:
|
||||
int fork_Unix() {
|
||||
int LispToUnix[2], /* Incoming pipe from LISP */
|
||||
UnixToLisp[2], /* Outgoing pipe to LISP */
|
||||
UnixPID, LispPipeIn, LispPipeOut, flags, slot;
|
||||
UnixPID, LispPipeIn, LispPipeOut, slot;
|
||||
pid_t pid;
|
||||
|
||||
char IOBuf[4];
|
||||
@ -292,9 +292,7 @@ int fork_Unix() {
|
||||
close(LispToUnix[1]);
|
||||
close(UnixToLisp[0]);
|
||||
|
||||
flags = fcntl(LispPipeIn, F_GETFL, 0);
|
||||
flags &= (65535 - FNDELAY);
|
||||
fcntl(LispPipeIn, F_SETFL, flags);
|
||||
fcntl(LispPipeIn, F_SETFL, fcntl(LispPipeIn, F_GETFL, 0) & ~O_NONBLOCK);
|
||||
|
||||
while (1) {
|
||||
ssize_t len;
|
||||
|
||||
@ -1185,7 +1185,7 @@ static int re_init_display(int lisp_display_addr, int display_max)
|
||||
} else {
|
||||
#ifdef KBINT
|
||||
int_io_open(LispWindowFd);
|
||||
fcntl(LispWindowFd, F_SETFL, fcntl(LispWindowFd, F_GETFL, 0) | FNDELAY);
|
||||
fcntl(LispWindowFd, F_SETFL, fcntl(LispWindowFd, F_GETFL, 0) | O_NONBLOCK);
|
||||
|
||||
#ifdef FX_AR_124
|
||||
/* For AR 124. Type4 driver bug?? by m.matsuda */
|
||||
@ -1297,7 +1297,7 @@ static int re_init_display(int lisp_display_addr, int display_max)
|
||||
} else {
|
||||
#ifdef KBINT
|
||||
int_io_open(LispWindowFd);
|
||||
fcntl(LispWindowFd, F_SETFL, fcntl(LispWindowFd, F_GETFL, 0) | FNDELAY);
|
||||
fcntl(LispWindowFd, F_SETFL, fcntl(LispWindowFd, F_GETFL, 0) | O_NONBLOCK);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user