VirtualBox

Changeset 93142 in vbox for trunk/src/VBox/Additions/os2


Ignore:
Timestamp:
Jan 7, 2022 6:23:40 PM (3 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
149156
Message:

Add/os2: Wrote the startup.cmd editing for the installer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/os2/VBoxOs2AdditionsInstall.cpp

    r93138 r93142  
    724724    bool        fInsertedIfs   = RT_BOOL(g_fSkipMask & SKIP_SHARED_FOLDERS);
    725725    unsigned    cPathsFound    = 0;
    726     const char *pchGraddChains = NULL;
    727     size_t      cchGraddChains = 0;
    728     char        ch0GraddUpper  = 0;
    729     char        ch0GraddLower  = 0;
     726    const char *pchGraddChains = "C1";
     727    size_t      cchGraddChains = sizeof("C1") - 1;
     728    char        ch0GraddUpper  = 'C';
     729    char        ch0GraddLower  = 'c';
    730730    const char *pchGraddChain1 = NULL;
    731731    size_t      cchGraddChain1 = NULL;
     
    795795             * Look for the GRADD_CHAINS variable.
    796796             *
    797              * It is a comma separated list of chains (other env.vars.),
    798              * however we can only deal with a single element.
     797             * It is a comma separated list of chains (other env.vars.), however
     798             * we can only deal with a single element.  This shouldn't be an issue
     799             * as GRADD_CHAINS is standardized by COMGRADD.DSP to the value C1, so
     800             * other values can only be done by users or special drivers.
    799801             */
    800802            else if (   cchLine - off >= sizeof("GRADD_CHAINS=C") - 1
     
    808810                {
    809811                    off++;
    810                     pchGraddChains = &pchLine[off];
    811                     cchGraddChains = StripGraddList(&pchGraddChains, cchLine - off);
    812 
    813                     ch0GraddUpper = RT_C_TO_UPPER(*pchGraddChains);
    814                     ch0GraddLower = RT_C_TO_LOWER(*pchGraddChains);
    815 
    816                     pchGraddChain1 = NULL;
    817                     cchGraddChain1 = 0;
    818 
    819                     const char *pszComma = (const char *)memchr(pchGraddChains, ',', cchGraddChains);
     812
     813                    const char *pchNew   = &pchLine[off];
     814                    size_t      cchNew   = StripGraddList(&pchNew, cchLine - off);
     815
     816                    const char *pszComma = (const char *)memchr(pchNew, ',', cchNew);
    820817                    if (pszComma)
    821818                    {
    822                         cchGraddChains = StripGraddList(&pchGraddChains, pchGraddChains - pszComma);
     819                        cchNew = StripGraddList(&pchNew, pchNew - pszComma);
    823820                        WriteStrings(g_hStdOut, "warning: Config.sys line ", MyNumToString(szLineNo, iLine),
    824821                                     "GRADD_CHAINS contains more than one element.  Ignoring all but the first.\r\n", NULL);
     822                    }
     823
     824                    /* If it differs from the default "C1" / previous value, we must
     825                       restart the search for the primary chain environment variable.
     826                       This means that chains values other than "C1" must come after
     827                       the GRADD_CHAINS statement, since we're not doing an extra pass. */
     828                    if (   cchGraddChains != cchNew
     829                        || MyMemICmp(pchNew, pchGraddChains, cchNew) == 0)
     830                    {
     831                        pchGraddChains = pchNew;
     832                        cchGraddChains = cchNew;
     833                        ch0GraddUpper  = RT_C_TO_UPPER(*pchGraddChains);
     834                        ch0GraddLower  = RT_C_TO_LOWER(*pchGraddChains);
     835                        pchGraddChain1 = NULL;
     836                        cchGraddChain1 = 0;
    825837                    }
    826838
     
    833845            /*
    834846             * Look for the chains listed by GRADD_CHAINS.
    835              *
    836              * We ASSUME this is defined after the GRADD_CHAINS variable since
    837              * this is normally the case.  We'd need to do two passes otherwise,
    838              * and I'm way to lazy to do that now.
    839847             */
    840848            else if (   (ch0GraddUpper == pchLine[off] || ch0GraddLower == pchLine[off])
     
    9951003    if (!(g_fSkipMask & SKIP_GRAPHICS))
    9961004    {
    997         if (cchGraddChain1 > 0)
     1005        if (cchGraddChain1 > 0 && cchGraddChains > 0)
    9981006        {
    9991007            int idxGenGradd = -1;
     
    10301038                                     pchGraddChains, cchGraddChains, RT_STR_TUPLE("="), pchGraddChain1, cchGraddChain1, NULL, 0);
    10311039        }
    1032         else if (cchGraddChains != 0)
     1040        else if (cchGraddChains > 0)
    10331041            return ErrorNStrings(RT_STR_TUPLE("Primary GRADD chain \""), pchGraddChains, cchGraddChains,
    10341042                                 RT_STR_TUPLE("\" not found (only searched after SET GRADD_CHAINS)."), NULL, 0);
     
    10411049
    10421050
     1051/** Puts the line starting VBoxService to Startup.cmd. */
     1052static void StartupCmdPutLine(const char *pszLineNo)
     1053{
     1054    if (g_fVerbose)
     1055        WriteStrings(g_hStdOut, "info: Starting VBoxService at line ", pszLineNo, " in Startup.cmd\r\n", NULL);
     1056    EditorPutStringN(&g_StartupCmd, g_szDstPath, g_cchDstPath);
     1057    EditorPutLine(&g_StartupCmd, RT_STR_TUPLE("VBoxService.exe"));
     1058}
     1059
     1060
    10431061/**
    10441062 * Prepares the startup.cmd modifications.
     
    10531071    if (rcExit != RTEXITCODE_SUCCESS)
    10541072        return rcExit;
     1073
     1074    /*
     1075     * Scan startup.cmd and see if there is an [@]ECHO OFF without anything other
     1076     * than REM statements preceding it.  If there is we'll insert ourselves after
     1077     * that, otherwise we'll just jump in at the top.
     1078     */
     1079    unsigned    iInsertBeforeLine = 0;
     1080    unsigned    iLine             = 0;
     1081    size_t      offSrc            = 0;
     1082    const char *pchLine;
     1083    size_t      cchLine;
     1084    while ((offSrc = EditorGetLine(&g_StartupCmd, offSrc, &pchLine, &cchLine)) != 0)
     1085    {
     1086        iLine++;
     1087
     1088        size_t off = 0;
     1089#define SKIP_BLANKS() \
     1090        while (off < cchLine && RT_C_IS_BLANK(pchLine[off])) \
     1091            off++
     1092        SKIP_BLANKS();
     1093        if (off < cchLine && pchLine[off] == '@')
     1094        {
     1095            off++;
     1096            SKIP_BLANKS();
     1097        }
     1098        if (   cchLine - off < sizeof("ECHO OFF") - 1
     1099            && MyMemICmp(&pchLine[off], RT_STR_TUPLE("ECHO")) == 0
     1100            && RT_C_IS_BLANK(pchLine[off + 4]) )
     1101        {
     1102            off += 4;
     1103            SKIP_BLANKS();
     1104
     1105            if (   cchLine - off < sizeof("OFF") - 1
     1106                && MyMemICmp(&pchLine[off], RT_STR_TUPLE("OFF")) == 0
     1107                && RT_C_IS_BLANK(pchLine[off + 3]) )
     1108            {
     1109                iInsertBeforeLine = iLine + 1;
     1110                break;
     1111            }
     1112        }
     1113        else if (   cchLine - off < sizeof("REM") - 1
     1114                && MyMemICmp(&pchLine[off], RT_STR_TUPLE("REM")) == 0
     1115                && (cchLine - off == 3 || RT_C_IS_BLANK(pchLine[off + 3])) )
     1116        { /* skip */ }
     1117        else
     1118            break;
     1119    }
     1120
     1121    /*
     1122     * Make the modifications.
     1123     */
     1124    if (iInsertBeforeLine == 0) /* Necessary to do this outside the loop in case startup.cmd is empty or non-existing. */
     1125        StartupCmdPutLine("1");
     1126
     1127    offSrc = iLine = 0;
     1128    while ((offSrc = EditorGetLine(&g_StartupCmd, offSrc, &pchLine, &cchLine)) != 0)
     1129    {
     1130        char szLineNo[32];
     1131        iLine++;
     1132        if (iLine == iInsertBeforeLine)
     1133            StartupCmdPutLine(MyNumToString(szLineNo, iLine));
     1134
     1135        /*
     1136         * Filter out old VBoxService lines.  To be on the safe side we skip
     1137         * past DETACH, CALL, and START before checking for VBoxService.
     1138         */
     1139        size_t off = 0;
     1140        SKIP_BLANKS();
     1141        if (off < cchLine && pchLine[off] == '@')
     1142        {
     1143            off++;
     1144            SKIP_BLANKS();
     1145        }
     1146
     1147        if (   cchLine - off < sizeof("DETACH ") - 1
     1148            && MyMemICmp(&pchLine[off], RT_STR_TUPLE("DETACH")) == 0
     1149            && RT_C_IS_BLANK(pchLine[off + 6]))
     1150        {
     1151            off += 6;
     1152            SKIP_BLANKS();
     1153        }
     1154
     1155        if (   cchLine - off < sizeof("CALL ") - 1
     1156            && MyMemICmp(&pchLine[off], RT_STR_TUPLE("CALL")) == 0
     1157            && RT_C_IS_BLANK(pchLine[off + 4]))
     1158        {
     1159            off += 4;
     1160            SKIP_BLANKS();
     1161        }
     1162
     1163        if (   cchLine - off < sizeof("START ") - 1
     1164            && MyMemICmp(&pchLine[off], RT_STR_TUPLE("START")) == 0
     1165            && RT_C_IS_BLANK(pchLine[off + 5]))
     1166        {
     1167            off += 5;
     1168            SKIP_BLANKS();
     1169        }
     1170
     1171        if (   cchLine - off < sizeof("VBOXSERVICE") - 1 /* (Should be harmless to go past end of buffer due to missing .EXE) */
     1172            && (   MatchOnlyFilename(&pchLine[off], cchLine - off, RT_STR_TUPLE("VBOXSERVICE.EXE")) == 0
     1173                || MatchOnlyFilename(&pchLine[off], cchLine - off, RT_STR_TUPLE("VBOXSERVICE")) == 0))
     1174        {
     1175            if (g_fVerbose)
     1176                WriteStrings(g_hStdOut, "info: Removing old VBoxService statement on line ",
     1177                             MyNumToString(szLineNo, iLine), "\r\n", NULL);
     1178        }
     1179        else
     1180            EditorPutLine(&g_StartupCmd, pchLine, cchLine);
     1181
     1182#undef SKIP_BLANKS
     1183    }
     1184
    10551185
    10561186    return RTEXITCODE_SUCCESS;
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette