[Pkg-sysvinit-devel] Strange redirection in mountnfs.sh

Miquel van Smoorenburg miquels at cistron.nl
Thu Jan 5 23:45:29 UTC 2006


On Thu, 2006-01-05 at 12:20 +0100, Thomas Hood wrote:
> In mountnfs.sh, after reading through fstab, the script does the following:
> 
>     exec 0>&1
> 
> That is, file descriptor 0 (stdin) is made a copy of file descriptor 1 (stdout)!
> 
> I don't understand this.  Is it a mistake?

Nope. It undoes the redirection from /etc/fstab. In normal
circumstances, filedescriptors 0, 1 and 2 are equivalent.

Also 0>&1 and 0<&1 are on all Unixes I know of equivalent - they
translate to the the dup2() system call, which doesn't have a
provisioning for read or write modes.

It is nessecary to undo the redirection because you don't want to start
portmap and mount with /etc/fstab on stdin.

> Background: I am studying mountnfs.sh because I am hoping to speed it up by replacing:
> 
> 	(
> 	...
> 	) < /etc/fstab
> 
> with:
> 
> 	exec 9<&0 < /etc/fstab
> 	...
> 	exec 0<&9 9<&-
> 
> which is what checkroot.sh does.  This would eliminate an unnecessary subprocess.

The shells I know of do not create an extra process when you use ( ).
It's just an internal abstraction. So I doubt you'll see any performance
increase. But if you think it looks better ....

Mike.




More information about the Pkg-sysvinit-devel mailing list