On Fri, Oct 03, 2008 at 09:43:19PM -0400, Joe Malicki wrote:
> This faked-link2.diff (patch to fakeroot 1.5.10) passes tests and holds up 
> through
> reasonable testing.
> 
> It should fix all cases noted in this bug, which were probably all caused by 
> ldconfig.

Forward-ported to 1.10 so I can get back to it later.
Also I want to add trap handlers to the tests to rm -rf tmp on premature
abort.
diff --git a/faked.c b/faked.c
index a98b0b5..1e38853 100644
--- a/faked.c
+++ b/faked.c
@@ -662,12 +662,17 @@ void process_chmod(struct fake_msg *buf){
        cache stale file information.
 
        mknod() creates a regular file, everything else should have the same
-       file type on disk and in our database.  Therefore, we check to see if
-       it's a regular file before blindly applying the new file type.
+       file type on disk and in our database.  Therefore, we check the file's
+       type first.  If we have something in our database as a device node and
+       we get a request to change it to regular file, it might be a chmod of
+       a device node that was created from within fakeroot, which is a device
+       file on disk - there's no way to distinguish.   For anything else, we
+       trust the new type and assume the inode got unlinked from something that
+       wasn't using the LD_PRELOAD library.
     */
 
-    if ((buf->st.mode&S_IFMT) != S_IFREG &&
-        (buf->st.mode&S_IFMT) != (st->mode&S_IFMT)) {
+    if ((buf->st.mode&S_IFMT) != (st->mode&S_IFMT) &&
+        ((buf->st.mode&S_IFMT) != S_IFREG || (!st->mode&(S_IFBLK|S_IFCHR)))) {
       fprintf(stderr,"FAKEROOT: chmod mode=%lo incompatible with "
               "existing mode=%lo\n", buf->st.mode, st->mode);
       st->mode = buf->st.mode;
diff --git a/test/Makefile.am b/test/Makefile.am
index 9a03d6f..e22b978 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1,7 +1,7 @@
 AUTOMAKE_OPTIONS=foreign
 
 TESTS = t.echoarg t.mknod t.tar t.truereturn t.falsereturn t.option \
-	t.touchinstall t.no_ld_preload
+	t.touchinstall t.no_ld_preload t.no_ld_preload_link t.chmod_dev
 
 suffix =
 TESTS_ENVIRONMENT = libfakeroot=libfakeroot-0.so suffix=$(suffix) posixshell=$(SHELL)
diff --git a/test/t.chmod_dev b/test/t.chmod_dev
new file mode 100755
index 0000000..34d8c63
--- /dev/null
+++ b/test/t.chmod_dev
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+mkdir tmp
+../scripts/fakeroot${tcp} -f ../faked${tcp} -l ../.libs/${libfakeroot} -- \
+ ${posixshell} -c 'mknod tmp/hda3 b 3 0 && chmod 644 tmp/hda3 && ls -ld tmp/hda3' | grep "^b"
+TEMP=$?
+rm -rf tmp
+exit $TEMP
diff --git a/test/t.no_ld_preload b/test/t.no_ld_preload
index b5cd729..64a20f2 100755
--- a/test/t.no_ld_preload
+++ b/test/t.no_ld_preload
@@ -1,4 +1,8 @@
 #!/bin/sh
 
+mkdir tmp
 ../scripts/fakeroot${tcp} -f ../faked${tcp} -l ../.libs/${libfakeroot} -- \
- ${posixshell} -c 'touch justafile; LD_PRELOAD= rm justafile; mkdir justafile; ls -ld justafile' | grep "^d"
+ ${posixshell} -c 'touch tmp/justafile && LD_PRELOAD= rm tmp/justafile && mkdir tmp/justafile && ls -ld tmp/justafile' | grep "^d"
+TEMP=$?
+rm -rf tmp
+exit $TEMP
diff --git a/test/t.no_ld_preload_link b/test/t.no_ld_preload_link
new file mode 100755
index 0000000..be32114
--- /dev/null
+++ b/test/t.no_ld_preload_link
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+mkdir tmp
+../scripts/fakeroot${tcp} -f ../faked${tcp} -l ../.libs/${libfakeroot} -- \
+ ${posixshell} -c 'touch tmp/justafile && ln -s justafile tmp/alink && LD_PRELOAD= rm tmp/alink && touch tmp/alink && ls -ld tmp/alink' | grep "^-"
+TEMP=$?
+rm -rf tmp
+exit $TEMP

Reply via email to