[Xapian-discuss] Atomic DB rebuilds

Olly Betts olly at survex.com
Tue Oct 5 17:16:14 BST 2004


On Tue, Oct 05, 2004 at 02:07:08PM +0100, Olly Betts wrote:
> Looks like we need to canonicalise the path to the database directory
> by eliminating symlinks and making it absolute.

Done a little more digging and this is a really nasty problem.  The
answer ought to be to use realpath (man 3 realpath) but unfortunately
the design is broken because you pass a pointer for the result which
has to be a buffer of size PATH_MAX which on some platforms may be huge
and unsuitable for mallocing, or worse still it might be -1 (meaning
unbounded).  So it's impossible to use portably without risking a buffer
overflow.

You can't roll your own portably, since you can't portably use the value
returned by readlink as a path you can actually use.  And while you
can use `open(".") / chdir(path) / getcwd() / fchdir()', that's not
ideal because any signal handler called will get the wrong current
directory:

http://sources.redhat.com/ml/libc-alpha/2001-09/msg00228.html

Actually, I think the `open(".") / chdir(path) / getcwd() / fchdir()'
approach is probably the least bad, most portable solution for us.  We
can even look at blocking signal delivery for the critical part.

And we can probably just use realpath where the buffer size is sane (I
found some LGPL code for that).

Cheers,
    Olly



More information about the Xapian-discuss mailing list