vhangup
Chris Torek
chris at mimsy.UUCP
Mon Dec 5 12:14:25 AEST 1988
In article <9124 at rpp386.Dallas.TX.US> jfh at rpp386.Dallas.TX.US (The Beach Bum)
asks:
>Why can't the file just be closed? Why wasn't this done?
Here is how vhangup() is currently implemented:
for (f in file_table)
if (f->f_type is an inode)
if (f as an inode is a device && is u.u_ttyd)
f->f_flag &= ~(FREAD|FWRITE);
Simple, if unelegant.
Suppose we were to try to close it:
if (f device is u.u_ttyd)
xxx
xxx cannot simply be `closef(f)'; the other process's u. area still
refers to f. If the same file table slot is later used for (say)
/etc/passwd, all sorts of things might go wrong. Besides, this file
table entry might be referenced from any number of u.u_ofile[] entries.
(In fact, it will have f->f_count such references.)
What we can do is swap:
oldip = NULL;
newip = inode_for("/dev/null");
for (f in file_table)
if (f->f_type is an inode)
if (f as an inode is a device && is u.u_ttyd) {
oldip = (struct inode *)f->f_data;
f->f_data = (caddr_t)newip;
}
/* oldip==NULL => caller did not have control terminal open */
if (oldip)
error = closei(oldip dev, mode, flag);
except that this is not quite all that needs doing.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain: chris at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.unix.wizards
mailing list