[Libguestfs] [PATCH 1/3] New API: case-sensitive-path to return case sensitive path on NTFS 3g fs

Richard W.M. Jones rjones at redhat.com
Mon Oct 26 10:52:15 UTC 2009


On Mon, Oct 26, 2009 at 11:41:22AM +0100, Jim Meyering wrote:
> Richard W.M. Jones wrote:
> > +char *
> > +do_case_sensitive_path (const char *path)
> > +{
> > +  char ret[PATH_MAX+1] = "/";
> > +  size_t next = 1;
> > +
> > +  /* MUST chdir ("/") before leaving this function. */
> > +  if (chdir (sysroot) == -1) {
> 
> If this function might ever be used from a multi-threaded
> application, then you'll want to change it not to use chdir,
> since chdir changes the process-wide current directory.
> That can cause rare but particularly hard to debug problems.

This code would be much harder to write if we don't use chdir.  Any
suggestions on that?  If there was a "readdirat" variant then that
might be promising.

Note that the daemon isn't likely to be multithreaded any time soon
(more likely to be pre-forking multiprocess if anything).

> Another (albeit small) advantage of not performing the chdir/readdir is
> that the function will be able to handle those rare names
> with a directory component that grants "x" but not "r" access.

This shouldn't be an issue because the daemon always runs as root.

> > +    while ((d = readdir (dir)) != NULL) {
> 
> If you want to distinguish readdir "EOF" from failure (e.g., EIO),
> you'll have to set errno=0 before each call and test whether it's
> still 0 upon NULL return.

OK, I'll fix that.

> > +    /* This is OK provided we've reached the end of the path. */
> > +    if (errno == ENOTDIR) {
> > +      if (*path) {
> > +        reply_with_error ("non-directory element in path");
> > +        goto error;
> > +      }
> > +      break;
> > +    }
> 
> What about other errno values?

.. and I'll fix that.

Thanks for looking at this.

Rich.

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://et.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list