Help! My fd's are incrementing by themselves!!
Roger Gonzalez
rg at uunet!unhd
Fri May 4 22:59:45 AEST 1990
I recently wrote a file system for a standalone WORM drive that will live
in an autonomous vehicle. Some files are placed on the WORMdisk in the
lab from Unix (over the VMEbus to the slave SCSI controller board for the
WORM.)
I basically have a simple shell that sits on top of csh, handles WORM
commands, and passes anything else to an execvp.
Two of the commands are
write worm-path unix-path (copy file from unix to worm)
and read worm-path [unix-path] (copy file from worm to unix)
Here is a snippet of code from write:
..
if ((fd = open(unix_path, O_RDONLY)) < 0) {
perror("unix-open");
return(ERROR);
}
if ((gfd = w_open("unix", worm_path, WRITEMODE) < 0) {
fprintf(stderr, "worm-open: global file descriptor alloc error!\n");
return(ERROR);
}
while ((num = read(fd, buffer, BUFFSIZE)) == BUFFSIZE) {
w_write(gfd, buffer, BUFFSIZE);
if (num < 0)
perror("unix-read");
else
w_write(gfd, buffer, num);
w_close(gfd);
close(fd);
..
I think the syntax of my routines is unixish enough to figure my intent
without much discussion. Also, I know its ugly and incomplete, and I'm
not concerned about that. What I'm concerned about is the fact that after
the second or third time this routine is done, it dumps out in the open
(open, *not* w_open) with a "too many fd's" error. Printing the fd on
each open revealed that it was incrementing by 3 each time, starting at
about 9. Since I assumed that it would be starting at 3, and incrementing
by 1 (0, 1, 2 being the std[in|out|err]), I was a little surprised.
One thing I noticed was that when I decreased BUFFSIZE, I gained a few
extra fd's before it died. Does this mean that I have some memory allocation
problems? I *am* eating a big chunk of memory with a phys:
phys(0, 0xfc0000, 0x100000, 0xfffc0000)
but I need these numbers to get at the SCSI board (which is annoying, since
the register bank of the board is only 512 bytes long, and starts way up in
the middle of the phys-ed routine. I haven't diddled the numbers, because
I haven't been able to find the page resolution of my machine documented
anywhere, and these numbers work.)
So, if you've followed me thus far, I need some opinions:
- Memory allocation problem?
- Stray pointer blasting something?
- Stupid programmer?
- ?
I'd appreciate any advice.
I'm running System V Unix on an Ironix P32.
Thanks,
Roger
--
UUCP: ..!uunet!unhd!rg | USPS: Marine Systems Engineering Laboratory
BITNET: r_gonzalez at unhh | University of New Hampshire
PHONE: (603) 862-4600 | Marine Programs Building
FAX: (603) 862-4399 | Durham, NH 03824-3525
More information about the Comp.unix.wizards
mailing list