Changeset 3911 for trunk


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