Subject: Re: /dev/null symlink and suse_base
To: Quentin Garnier <cube@cubidou.net>
From: Dan McMahill <mcmahill@alum.mit.edu>
List: tech-pkg
Date: 07/04/2005 08:46:13
On Mon, Jul 04, 2005 at 02:27:08PM +0200, Quentin Garnier wrote:
> On Mon, Jul 04, 2005 at 02:07:06PM +0200, Quentin Garnier wrote:
> > On Mon, Jul 04, 2005 at 07:19:23AM -0400, Dan McMahill wrote:
> > > I've run into a compat_linux problem which stems from ${EMULDIR}/dev/null
> > > being a symlink to /dev/null.
> > > 
> > > In the install target in emulators/suse_base/Makefile, this is done with:
> > > 
> > > ${LN} -fs /dev/null ${EMULDIR}/dev/null
> > > 
> > > I've seen some linux programs which use realpath() and readlink() on
> > > /dev/null.  The problem is when looking for /dev/null, compat_linux
> > > will look for ${EMULDIR}/dev/null first and the program loops a whole
> > > bunch of times until you get an error about too many symlinks.
> > > 
> > > I'm wondering if we should instead do something like
> > > 
> > > ${CP} -p /dev/MAKEDEV ${EMULDIR}/dev
> > > cd ${EMULDIR}/dev && ${SH} ./MAKEDEV std
> > > 
> > > or some such thing.  I tried just running
> > > 
> > > cd /emul/linux/dev && mknod -m 666 -g wheel -u root null c 2 2
> > > 
> > > to create a /dev/null in the emulation root which was not a symlink.
> > > It seemed to have gotten past the problem I'd been having.
> > > 
> > > Does anyone see a problem with changing the suse_base and suse91_base
> > > packages to do this?  Maybe there is a better fix?  Someone had suggested
> > > 
> > > cd /emul/linux/dev && ln -s ../../../dev/null
> > > 
> > > but that also failed.
> > 
> > It should be "ln -s /../dev/null".  The leading "/../" is magic.
> 
> Ignore that.  I didn't switch the brains on.
> 
> But now that I think of it, that's something I should add to my special
> namei() function.

it was your namei() post on tech-kern which reminded me that I hadn't resolved
this issue :)

> Now back to your issue.  It is weird.  I guess realpath() would
> typically the function that fails, reading each component individually.
> readlink() is a simple syscall, so there is no risk of it doing
> anything wrong, but indeed realpath() is a problem.
> 
> I guess your solution is acceptable in the /dev/null case, but the
> issue can arise with any symlink of that kind.

any symlink from somewhere inside the emulation root to the real root.

so I gues the complete list of what needs to be added instead of the 
symlinks in ${EMULDIR}/dev is:

${CP} -p /dev/MAKEDEV ${EMULDIR}/dev
cd ${EMULDIR}/dev && ${SH} ./MAKEDEV std
cd ${EMULDIR}/dev && ${SH} ./MAKEDEV sound
cd ${EMULDIR}/dev && ${LN} -s sound dsp


-Dan

--