Changeset 3911


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).

Files:
2 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    }
  • trunk/libc/src/kNIX/os2/fs-os2.c

    r3861 r3911  
    217217{
    218218    LIBCLOG_ENTER("\n");
     219    APIRET rc;
    219220/** @todo getenv doesn't work at this point. :( */
    220221
     
    262263        if (pInherit)
    263264            __libc_spmInheritRelease();
     265
    264266        /*
    265267         * Setup unofficial unixroot.
    266268         */
    267269        const char *psz = getenv("UNIXROOT");
    268         if (psz)
     270        if (   psz
     271            && ((psz[0] >= 'A' && psz[0] <= 'Z') || (psz[0] >= 'a' && psz[0] <= 'z'))
     272            && psz[1] == ':'
     273            && (psz[2] == '\\' || psz[2] == '/')
     274            )
    269275        {
    270276            LIBCLOG_MSG("Unofficial unixroot=%s\n", psz);
     
    276282            }
    277283            memcpy(&__libc_gszUnixRoot[0], psz, cch + 1);
     284
     285            /* Clean it up a tiny little bit. */
     286            if (__libc_gszUnixRoot[0] >= 'a')
     287                __libc_gszUnixRoot[0] -= 'a' - 'A';
     288
     289            size_t off = cch;
     290            while (off-- > 0)
     291                if (__libc_gszUnixRoot[off] == '\\')
     292                    __libc_gszUnixRoot[off] = '/';
    278293
    279294            /* Register the rewrite rule. */
     
    281296            if (__libc_PathRewriteAdd(&gUnixRootRewriteRule, 1))
    282297                LIBCLOG_RETURN_INT(-1);
    283         }
     298
     299            /* Should we pretend chroot($UNIXROOT) + chdir()? */
     300            psz = getenv("UNIXROOT_CHROOTED");
     301            if (psz && *psz != '\0')
     302            {
     303                __libc_gcchUnixRoot = cch;
     304
     305                ULONG ulDisk, ulIgnored;
     306                rc = DosQueryCurrentDisk(&ulDisk, &ulIgnored);
     307                if (   rc == NO_ERROR
     308                    && ulDisk + 'A' - 1 == __libc_gszUnixRoot[0])
     309                {
     310                    if (cch == 3)
     311                        __libc_gfInUnixTree = 1;
     312                    else
     313                    {
     314                        char szCurDir[PATH_MAX];
     315                        ULONG cbCurDir = sizeof(szCurDir);
     316                        rc = DosQueryCurrentDir(0, (PSZ)&szCurDir[0], &cbCurDir);
     317                        __libc_gfInUnixTree = rc == NO_ERROR
     318                                           && cch <= cbCurDir + 3
     319                                           && memicmp(&__libc_gszUnixRoot[3], szCurDir, cch - 3) == 0
     320                                           && (   cch == cbCurDir + 3
     321                                               || szCurDir[cch - 3] == '\\');
     322                    }
     323
     324                }
     325                LIBCLOG_MSG(__libc_gfInUnixTree ? "Inside unixroot chroot.\n" : "Outside unixroot chroot.\n");
     326            }
     327        }
     328        else if (psz)
     329            LIBCLOG_MSG("Invalid UNIXROOT=\"%s\" - must start with drive letter and root slash.\n", psz);
    284330    }
    285331
     
    291337    PPIB pPib;
    292338    DosGetInfoBlocks(&pTib, &pPib);
    293     APIRET rc = DosQueryModuleName(pPib->pib_hmte, sizeof(__libc_gszExecPath), &__libc_gszExecPath[0]);
     339    rc = DosQueryModuleName(pPib->pib_hmte, sizeof(__libc_gszExecPath), &__libc_gszExecPath[0]);
    294340    if (!rc)
    295341    {
Note: See TracChangeset for help on using the changeset viewer.