changeset 1745:8d82dc711a93

Fix the darn ccwrap symlink resolution path logic that was finding the wrong /usr/include. It wasn't distcc's fault. Test _before_ following symlinks, otherwise the original location found doesn't get checked to see if it's valid.
author Rob Landley <rob@landley.net>
date Sun, 22 Feb 2015 20:45:25 -0600
parents 4c3164f0d2c2
children 5f84cad1fdc9
files sources/toys/ccwrap.c sources/toys/hdainit.sh
diffstat 2 files changed, 17 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/sources/toys/ccwrap.c	Sun Feb 22 17:22:00 2015 -0600
+++ b/sources/toys/ccwrap.c	Sun Feb 22 20:45:25 2015 -0600
@@ -161,6 +161,8 @@
   int i, keepc, srcfiles, flags, outc;
   struct dlist *libs = 0;
 
+  if (getenv("CCWRAP_DEBUG")) fprintf(stderr, "%s@%s\n", argv[0], getcwd(0, 0));
+
   keepv = xmalloc(argc*sizeof(char *));
   flags = MASK_BIT(Clink)|MASK_BIT(Cstart)|MASK_BIT(Cstdinc)|MASK_BIT(Cstdlib)
           |MASK_BIT(CPctordtor);
@@ -191,7 +193,7 @@
     i -= 3;
     CLEAR_FLAG(Clink);
   } else return 1; // TODO: wrap ld
-  if (!(ccprefix = strndup(ccprefix, i))) exit(1);
+  if (!(ccprefix = strndup(ccprefix, (size_t)i))) exit(1); // todo: fix uclibc
 
   // Find the cannonical path to the directory containing our executable
   topdir = find_in_path(getenv("PATH"), *argv, 1);
@@ -203,12 +205,22 @@
   i = 99;
   while (topdir && i--) {
     char buf[4200], *new, *libc;
-    int len = readlink(topdir, buf, 4096);
+    int len;
 
-    if (len<1) break;
+    // If this isn't a symlink, we stop here.
+    if (1 > (len = readlink(topdir, buf, 4096))) break;
+    buf[len] = 0;
 
-    // Absolute symlink replaces, relative symlink appends
-    buf[len] = 0;
+    // if we can find libc.so from here, stop looking.
+    if (!(temp = strrchr(topdir, '/'))) break; // should never happen
+    *temp = 0;
+    libc = xmprintf("%s/../lib/libc.so", topdir);
+    *temp = '/';
+    len = access(libc, R_OK);
+    free(libc);
+    if (!len) break;
+
+    // Follow symlink. Absolute symlink replaces, relative symlink appends
     if (buf[0] == '/') new = strdup(buf);
     else {
       temp = strrchr(topdir, '/');
@@ -217,15 +229,6 @@
     }
     free(topdir);
     topdir = new;
-
-    // if we can find libc.so from here, stop looking.
-    temp = strrchr(new, '/');
-    *temp = 0;
-    libc = xmprintf("%s/../lib/libc.so", new);
-    *temp = '/';
-    len = access(libc, R_OK);
-    free(libc);
-    if (!len) break;
   }
 
   if (!topdir || !(temp = strrchr(topdir, '/')) || strlen(*argv)<2) {
--- a/sources/toys/hdainit.sh	Sun Feb 22 17:22:00 2015 -0600
+++ b/sources/toys/hdainit.sh	Sun Feb 22 20:45:25 2015 -0600
@@ -9,13 +9,6 @@
 else
   echo "Distcc acceleration enabled."
   PATH="/usr/distcc:$PATH"
-
-  # distcc does realpath() which is a problem because ccwrap won't use
-  # things added to the relocated include directory if you call the one
-  # at the original location.
-  rm /usr/bin/cc &&
-  echo -e "#!/bin/ash\nexec /usr/overlay/usr/bin/cc" > /usr/bin/cc &&
-  chmod +x /usr/bin/cc || exit 1
 fi
 
 if [ -e /mnt/init ]