1
0
mirror of https://github.com/Interlisp/maiko.git synced 2026-01-28 20:41:30 +00:00

fcntl(..., F_SETFL, ...) return value only signals error. (#141)

The return value of `fcntl` when passed `F_SETFL` isn't guaranteed
to return the flags passed in as its return value. It will be `-1`
in the event of an error, but no other value is to be relied upon.

Fortunately, we weren't relying upon the value apart from
occasionally checking for an error.

This is as it is specified in https://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.html

Closes interlisp/medley#87.
This commit is contained in:
Bruce Mitchener
2020-12-29 08:59:27 +07:00
committed by GitHub
parent 01926fc232
commit 3e2a2d76ec
8 changed files with 21 additions and 25 deletions

View File

@@ -142,7 +142,7 @@ int main(int argc, char *argv[])
strcpy(Ename, if_data.ifc_req[0].ifr_name);
flags = fcntl(ether_fd, F_GETFL, 0);
flags = fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
#ifdef DEBUG
printf("init_ether: **** Ethernet starts ****\n");

View File

@@ -78,7 +78,6 @@ LispPTR CHAR_openfile(LispPTR *args)
#ifndef DOS
register int fd; /* return value of open system call. */
register int flags; /* open system call's argument */
register int rval;
struct stat statbuf;
char pathname[MAXPATHLEN];
@@ -104,9 +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. */
rval = fcntl(fd, F_GETFL, 0);
rval |= FNDELAY;
rval = fcntl(fd, F_SETFL, rval);
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL, 0) | FNDELAY);
return (GetSmallp(fd));
#endif /* DOS */

View File

@@ -823,7 +823,7 @@ void init_ether() {
}
flags = fcntl(ether_fd, F_GETFL, 0);
flags = fcntl(ether_fd, F_SETFL, flags | O_NDELAY);
fcntl(ether_fd, F_SETFL, flags | O_NDELAY);
} else {
I_Give_Up:

View File

@@ -130,7 +130,7 @@ int main(int argc, char *argv[]) {
}
flags = fcntl(ether_fd, F_GETFL, 0);
flags = fcntl(ether_fd, F_SETFL, flags | O_NDELAY);
fcntl(ether_fd, F_SETFL, flags | O_NDELAY);
#else
/* N O T D L P I C O D E */
@@ -211,7 +211,7 @@ int main(int argc, char *argv[]) {
strcpy(Ename, if_data.ifc_req[0].ifr_name);
flags = fcntl(ether_fd, F_GETFL, 0);
flags = fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
#endif /* USE_DLPI */
#ifdef DEBUG

View File

@@ -140,7 +140,7 @@ int main(int argc, char *argv[])
strcpy(Ename, if_data.ifc_req[0].ifr_name);
flags = fcntl(ether_fd, F_GETFL, 0);
flags = fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
fcntl(ether_fd, F_SETFL, flags | FASYNC | FNDELAY);
#ifdef DEBUG
printf("init_ether: **** Ethernet starts ****\n");

View File

@@ -149,7 +149,7 @@ gotpty:
#ifdef LOGINT
LogFileFd = cons_pty; /* was kept as an fd_set, but doesn't need to be */
flags = fcntl(cons_pty, F_GETFL, 0);
flags = fcntl(cons_pty, F_SETFL, (flags | FASYNC | FNDELAY));
fcntl(cons_pty, F_SETFL, (flags | FASYNC | FNDELAY));
if (fcntl(cons_pty, F_SETOWN, getpid()) == -1) {
#ifdef DEBUG
perror("fcntl F_SETOWN of log PTY");

View File

@@ -338,7 +338,7 @@ int FindAvailablePty(char *Master, char *Slave) {
flags = fcntl(res, F_GETFL, 0);
flags |= FNDELAY;
flags = fcntl(res, F_SETFL, flags);
fcntl(res, F_SETFL, flags);
return (res);
}
#ifndef FULLSLAVENAME
@@ -452,8 +452,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
}
res = fcntl(PipeFD, F_GETFL, 0);
res |= FNDELAY;
res = fcntl(PipeFD, F_SETFL, res);
if (res < 0) {
if (fcntl(PipeFD, F_SETFL, res) == -1) {
perror("setting up fifo to nodelay");
return (NIL);
}
@@ -615,7 +614,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
case 11: /* Fork PTY process */
{
char MasterFD[20], SlavePTY[32];
int Master, res, slot;
int Master, flags, slot;
unsigned short len;
Master = FindAvailablePty(MasterFD, SlavePTY);
@@ -651,9 +650,9 @@ LispPTR Unix_handlecomm(LispPTR *args) {
DBPRINT(("Pipe/fork result = %d.\n", d[3]));
if (d[3] == 1) {
/* Set up the IO not to block */
res = fcntl(Master, F_GETFL, 0);
res |= FNDELAY;
res = fcntl(Master, F_SETFL, res);
flags = fcntl(Master, F_GETFL, 0);
flags |= FNDELAY;
fcntl(Master, F_SETFL, flags);
UJ[slot].type = UJSHELL; /* so we can find them */
UJ[slot].PID = (d[1] << 8) | d[2];
@@ -833,7 +832,7 @@ LispPTR Unix_handlecomm(LispPTR *args) {
case 12: /* create Unix socket */
{
int res, sockFD;
int flags, sockFD;
struct sockaddr_un sock;
/* First open the socket */
@@ -862,9 +861,9 @@ 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 */
res = fcntl(sockFD, F_GETFL, 0);
res |= FNDELAY;
res = fcntl(sockFD, F_SETFL, res);
flags = fcntl(sockFD, F_GETFL, 0);
flags |= FNDELAY;
fcntl(sockFD, F_SETFL, flags);
/* things seem sane, fill out the rest of the UJ slot and return */
UJ[sockFD].status = -1;

View File

@@ -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, res, slot;
UnixPID, LispPipeIn, LispPipeOut, flags, slot;
pid_t pid;
char IOBuf[4];
@@ -292,9 +292,9 @@ int fork_Unix() {
close(LispToUnix[1]);
close(UnixToLisp[0]);
res = fcntl(LispPipeIn, F_GETFL, 0);
res &= (65535 - FNDELAY);
res = fcntl(LispPipeIn, F_SETFL, res);
flags = fcntl(LispPipeIn, F_GETFL, 0);
flags &= (65535 - FNDELAY);
fcntl(LispPipeIn, F_SETFL, flags);
while (1) {
ssize_t len;