Re: chdir/rmdir



On Sat, Apr 19, 2008 at 11:02:27AM -0700, Randall Hyde wrote:
Hi,
I recently made a couple of calls like the following

// currently in /x/y/z

chdir( "/x/y" );
rmdir( "/x/y/z" );

Presumably you checked the return codes and both these succeeded.

When I did at "gwd" call, it returned "/x/y/z" along with ENOTDIR.
Is this a known issue?

What do you mean by "gwd"? There's getcwd(3) which uses __getcwd(2) -
but the syscall may fail, in which case getcwd(3) falls back to stat(2)ing
.. until it reaches root and then using directory(3) to translate the
inode numbers to a pathname. And, even if __getcwd(3) succeeds, the
result may need massaging before being returned to the caller.

Note that system calls very rarely both fail and return a value -
normally, any output buffer will be returned untouched if there's an
error.

P.S. I noticed that the man pages said something about using open on
"." and fchdir to more robustly switch back to some previous
directory;

This is for security and reliability reasons: The process can still
get back to the original directory even if components of its pathname
have been renamed.

--
Peter Jeremy
Please excuse any delays as the result of my ISP's inability to implement
an MTA that is either RFC2821-compliant or matches their claimed behaviour.

Attachment: pgpsiZ9vQnI0y.pgp
Description: PGP signature



Relevant Pages

  • [PATCH] Fix scripts/mkuboot.sh to return status
    ... If `mkimage` is either not found in search path or returns non-zero status, ... `make uImage` succeeds when it should fail. ... to return status so build succeeds or fails as appropriate. ... build failure when uImage target is not created. ...
    (Linux-Kernel)
  • Re: -e fails sometimes
    ... would it sometimes fail and sometimes succeed? ... that it fails have a different $file than the sometimes that it succeeds? ... do you know that the file did in fact exist on disk at the exact instance ...
    (comp.lang.perl.misc)
  • Re: [PATCH] Fix scripts/mkuboot.sh to return status
    ... > `make uImage` succeeds when it should fail. ... > to return status so build succeeds or fails as appropriate. ... send the line "unsubscribe linux-kernel" in ...
    (Linux-Kernel)
  • Flaw in ide_unregister()
    ... it can fail *silently* under the following condition: ... Fix ide_unregister so it always succeeds. ... Only a limited number of drivers use ide_unregister: ... To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/ ...
    (Linux-Kernel)