# HG changeset patch # User Rob Landley # Date 1424659525 21600 # Node ID 8d82dc711a93186a4ec2e19a6ee81cca9db10de6 # Parent 4c3164f0d2c22891cdb649902932abbd7cb0f830 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. diff -r 4c3164f0d2c2 -r 8d82dc711a93 sources/toys/ccwrap.c --- 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 this isn't a symlink, we stop here. + if (1 > (len = readlink(topdir, buf, 4096))) break; + buf[len] = 0; - if (len<1) break; + // 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; - // Absolute symlink replaces, relative symlink appends - buf[len] = 0; + // 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) { diff -r 4c3164f0d2c2 -r 8d82dc711a93 sources/toys/hdainit.sh --- 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 ]