Article View: net.4bsd-bugs
Article #16missing file descriptors
From: uncsmb
Date: Thu, 20 Aug 1981 22:04
Date: Thu, 20 Aug 1981 22:04
56 lines
1404 bytes
1404 bytes
If a process is interrupted while trying to open a file, the
file descriptor tentatively assigned is lost -- unless you
know what it should be and close it! The following program
demonstrates this. (This was run under 4bsd, but I believe
the same problem is present in V6 and V7.) Note that this
implies that a device driver close routine can be called
for a file that was never successfully opened -- which might
cause problems for weird devices/drivers.
#include <signal.h>
#include <errno.h>
#define CLOSEDTTY "/dev/ttyia" /* should wait forever */
#define FLIM 25 /* maximum open files */
extern errno;
main()
{
int i, j;
int f;
int tick();
char lbuf[100];
signal(SIGALRM, tick);
for (j = 0; j<2; j++) {
for (i = 3; i < FLIM; i++)
close(i);
for (i=0; i<FLIM; i++) {
alarm(2);
f = open(CLOSEDTTY, 1);
if (f >= 0) {
printf("Huh -- f=%d\n", f);
}
else if (errno != EINTR) {
alarm(0);
sprintf(lbuf, "i=%d j=%d", i, j);
perror(lbuf);
break;
}
if (j) {
if (close(3) < 0) perror("close");
}
}
printf("end inner loop, i=%d\n", i);
}
}
tick()
{
signal(SIGALRM, tick);
return;
}
Technical Details
Message-ID:
<anews.Aunc.1057>Path:
arc1-ca.pugleaf.net!utzoo!decvax!duke!unc!smbShow Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!decvax!duke!unc!smb From: unc!smb Newsgroups: net.4bsd-bugs,net.v7-bugs Subject: missing file descriptors Date: Thu, 20 Aug 1981 22:04:12 +0000 Message-ID: <anews.Aunc.1057>