Mail Archives: djgpp-workers/2003/01/23/14:51:21
Richard Dawe wrote:
> Hello.
>
> Laurynas Biveinis wrote:
>
>>> HERE=`pwd`
>>> ln -s /dev/env/FOO link
>>> export FOO=../../somefile
>>> echo Hello > $FOO
>>> cat link
>>> cd ..
>>> cat link
>
>
> Oops, obviously the last line should be:
>
> cat <directory>/link
Indeed. Now I was able to reproduce and fix the bug. Patch below
commited. Can you check if shell commands you've described are working
now? Also, here is the addition to the testsuite for the record. It is
not commited yet because of many unrelated changes to the testsuite I've
made.
setenv("SYMTEST", "../../Makefile", 1);
chdir("dir1/dir2");
symlink("/dev/env/SYMTEST", "linkSYMTEST");
test_success("linkSYMTEST", "../../Makefile");
chdir("..");
test_success("dir2/linkSYMTEST", "../Makefile");
chdir("..");
unsetenv("SYMTEST");
And the patch:
Index: djgpp/src/libc/compat/unistd/xsymlink.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/compat/unistd/xsymlink.c,v
retrieving revision 1.7
diff -u -p -r1.7 xsymlink.c
--- djgpp/src/libc/compat/unistd/xsymlink.c 17 Jan 2003 19:48:12 -0000 1.7
+++ djgpp/src/libc/compat/unistd/xsymlink.c 23 Jan 2003 19:44:07 -0000
@@ -7,8 +7,10 @@
/* resolves only last filename component and one symlink level.) */
#include <libc/stubs.h>
+#include <libc/dosio.h>
#include <libc/symlink.h>
#include <errno.h>
+#include <go32.h>
#include <limits.h>
#include <stdio.h>
#include <unistd.h>
@@ -79,7 +81,24 @@ int __solve_symlinks(const char * __syml
done_something = 1;
link_level++;
fn_buf[bytes_copied] = '\0';
- strcpy(resolved, fn_buf);
+ /* We can get /dev/env/SOMEVARIABLE as a symlink target. Do not
+ restart processing in this case, but substitute
/dev/env/SOMEVARIABLE
+ with expanded SOMEVARIABLE. Note that SOMEVARIABLE may
expand to
+ either relative or absolute path. */
+ if (strncmp(fn_buf, "/dev/env/", strlen("/dev/env/")))
+ strcpy(resolved, fn_buf);
+ else
+ {
+ /* Fill `resolved' with expanded env variable. Do this by
+ calling _put_path(). TODO: It could be nice to factor
+ out some code from _put_path2() to separate function to
expand
+ /dev/env/FOO once, i.e. do not recurse as _put_path2()
does.
+ However, it is not completely trivial, so current
implementation
+ takes a performance hit there. */
+ _put_path(fn_buf);
+ dosmemget(__tb, FILENAME_MAX, resolved);
+ }
+
/* FIXME: does absolute path check below work with
chroot()? */
if (((bytes_copied > 2) && (resolved[1] == ':')) ||
((bytes_copied > 0) && ((resolved[0] == '/') ||
- Raw text -