Changeset 3911 for branches/libc-0.6/src


Ignore:
Timestamp:
Oct 24, 2014, 12:49:58 PM (11 years ago)
Author:
bird
Message:

0.6,trunk: Introducing env var UNIXROOT_CHROOTED for faking chroot chdir (the latter for preserving whatever is the current dir + drive, unless we're inside (under) the unixroot).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/libc-0.6/src/emx/src/lib/sys/fs.c

    r3817 r3911  
    320320             */
    321321            const char *psz = getenv("UNIXROOT");
    322             if (psz)
     322            if (   psz
     323                && ((psz[0] >= 'A' && psz[0] <= 'Z') || (psz[0] >= 'a' && psz[0] <= 'z'))
     324                && psz[1] == ':'
     325                && (psz[2] == '\\' || psz[2] == '/')
     326                )
    323327            {
    324328                LIBCLOG_MSG("Unofficial unixroot=%s\n", psz);
     
    331335                memcpy(&__libc_gszUnixRoot[0], psz, cch + 1);
    332336
     337                /* Clean it up a tiny little bit. */
     338                if (__libc_gszUnixRoot[0] >= 'a')
     339                    __libc_gszUnixRoot[0] -= 'a' - 'A';
     340
     341                size_t off = cch;
     342                while (off-- > 0)
     343                    if (__libc_gszUnixRoot[off] == '\\')
     344                        __libc_gszUnixRoot[off] = '/';
     345
    333346                /* Register the rewrite rule. */
    334347                gUnixRootRewriteRule.cchTo = cch;
    335348                if (__libc_PathRewriteAdd(&gUnixRootRewriteRule, 1))
    336349                    LIBCLOG_RETURN_INT(-1);
    337             }
     350
     351                /* Should we pretend chroot($UNIXROOT) + chdir()? */
     352                psz = getenv("UNIXROOT_CHROOTED");
     353                if (psz && *psz != '\0')
     354                {
     355                    __libc_gcchUnixRoot = cch;
     356
     357                    ULONG ulDisk, ulIgnored;
     358                    rc = DosQueryCurrentDisk(&ulDisk, &ulIgnored);
     359                    if (   rc == NO_ERROR
     360                        && ulDisk + 'A' - 1 == __libc_gszUnixRoot[0])
     361                    {
     362                        if (cch == 3)
     363                            __libc_gfInUnixTree = 1;
     364                        else
     365                        {
     366                            char szCurDir[PATH_MAX];
     367                            ULONG cbCurDir = sizeof(szCurDir);
     368                            rc = DosQueryCurrentDir(0, (PSZ)&szCurDir[0], &cbCurDir);
     369                            __libc_gfInUnixTree = rc == NO_ERROR
     370                                               && cch <= cbCurDir + 3
     371                                               && memicmp(&__libc_gszUnixRoot[3], szCurDir, cch - 3) == 0
     372                                               && (   cch == cbCurDir + 3
     373                                                   || szCurDir[cch - 3] == '\\');
     374                        }
     375
     376                    }
     377                    LIBCLOG_MSG(__libc_gfInUnixTree ? "Inside unixroot chroot.\n" : "Outside unixroot chroot.\n");
     378                }
     379            }
     380            else if (psz)
     381                LIBCLOG_MSG("Invalid UNIXROOT=\"%s\" - must start with drive letter and root slash.\n", psz);
    338382        }
    339383    }
Note: See TracChangeset for help on using the changeset viewer.