[Q-e-developers] symlink problem (and possible solution) in clib/c_mkdir.c:check_writable_dir()

Giovanni Pizzi giovanni.pizzi at epfl.ch
Fri May 9 12:48:23 CEST 2014


Dear all,

we found a small issue in the function that creates/checks directories, 
that makes QE stop with an error if the scratch directory is a symlink.

In particular, in clib/c_mkdir.c, in the check_writable_dir function, it 
is written:

#if defined(_WIN32)
     /* windows has no symlinks so we use stat(2) */
     if (stat(filename, &sb) == -1) {
       return -3; /* does not exist */
       /* note: this happens also if looking for "dir/" when there is a 
file cal\
led "dir" */
     }
#else
*    /* lstat follows symlinks */**
**    if (lstat(filename, &sb) == -1) {**
*      return -3; /* does not exist */
       /* note: this happens also if looking for "dir/" when there is a 
file cal\
led "dir" */
     }
#endif

However, 'man lstat' states the opposite, that is, 'stat' follows 
symlinks and 'lstat' does not:

lstat() is identical to stat(), except that if path is a symbolic link, 
then the link itself is stat-ed, not the  file that it refers to.

Indeed, in the current version of QE, if the PREFIX.save folder is a 
symlink, at the end the calculation crashes with a "unable to create 
directory" error because the check_writable_dir routine is checking the 
symlink and not the linked folder.

Changing lstat with stat, everything seems to work properly, instead 
(moreover, probably the #if defined(_WIN32) could also be removed, 
because the two sections would become identical).

Does anyone have expertise with these functions and give us feedback on 
whether our modification makes sense and does not create different 
problems, and if we can proceed to commit the change?

Thanks,

Andrea Cepellotti and Giovanni Pizzi, THEOS-EPFL, Switzerland


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.quantum-espresso.org/pipermail/developers/attachments/20140509/d4190dbf/attachment.html>


More information about the developers mailing list