Changeset 79416 in vbox for trunk/src/VBox/ValidationKit/utils
- Timestamp:
- Jun 28, 2019 3:51:27 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/utils/TestExecServ/TestExecService.cpp
r76553 r79416 177 177 /** The default CD/DVD-ROM path. */ 178 178 static char g_szDefCdRomPath[RTPATH_MAX]; 179 /** The directory containing the TXS executable. */ 180 static char g_szTxsDir[RTPATH_MAX]; 181 /** The current working directory for TXS (doesn't change). */ 182 static char g_szCwd[RTPATH_MAX]; 179 183 /** The operating system short name. */ 180 184 static char g_szOsShortName[16]; … … 549 553 while ((pszDollar = strchr(pszDollar, '$')) != NULL) 550 554 { 555 /** @todo employ $$ as escape sequence here. */ 551 556 if (pszDollar[1] == '{') 552 557 { 553 c onst char *pszEnd = strchr(&pszDollar[2], '}');558 char *pszEnd = strchr(&pszDollar[2], '}'); 554 559 if (pszEnd) 555 560 { … … 574 579 else IF_VARIABLE_DO(pszDollar, "${EXESUFF}", g_szExeSuff) 575 580 else IF_VARIABLE_DO(pszDollar, "${SCRIPTSUFF}", g_szScriptSuff) 581 else IF_VARIABLE_DO(pszDollar, "${TXSDIR}", g_szTxsDir) 582 else IF_VARIABLE_DO(pszDollar, "${CWD}", g_szCwd) 583 else if ( cchVar >= sizeof("${env.") + 1 584 && memcmp(pszDollar, RT_STR_TUPLE("${env.")) == 0) 585 { 586 const char *pszEnvVar = pszDollar + 6; 587 size_t cchValue = 0; 588 char szValue[RTPATH_MAX]; 589 *pszEnd = '\0'; 590 rc = RTEnvGetEx(RTENV_DEFAULT, pszEnvVar, szValue, sizeof(szValue), &cchValue); 591 if (RT_SUCCESS(rc)) 592 { 593 *pszEnd = '}'; 594 rc = txsReplaceStringVariable(&pszNew, &cchNew, offDollar, cchVar, szValue, cchValue); 595 offDollar += cchValue; 596 } 597 else 598 { 599 if (rc == VERR_ENV_VAR_NOT_FOUND) 600 *prcSend = txsReplyFailure(pPktHdr, "UNKN VAR", "Environment variable '%s' encountered in '%s'", 601 pszEnvVar, pszSrc); 602 else 603 *prcSend = txsReplyFailure(pPktHdr, "FAILDENV", 604 "RTEnvGetEx(,'%s',,,) failed with %Rrc (opcode '%.8s')", 605 pszEnvVar, rc, pPktHdr->achOpcode); 606 RTStrFree(pszNew); 607 *ppszNew = NULL; 608 return false; 609 } 610 } 576 611 else 577 612 { … … 743 778 return rc; 744 779 } 780 781 ///** 782 // * Expands the variables in the string and sends it back to the host. 783 // * 784 // * @returns IPRT status code from send. 785 // * @param pPktHdr The expand string packet. 786 // */ 787 //static int txsDoExpandString(PCTXSPKTHDR pPktHdr) 788 //{ 789 // int rc; 790 // char *pszIn; 791 // if (!txsIsStringPktValid(pPktHdr, "string", &pszIn, &rc)) 792 // return rc; 793 // 794 // txsReplyRc 795 // 796 //} 745 797 746 798 /** … … 874 926 * @returns IPRT status code from send. 875 927 * @param pPktHdr The put file packet. 876 */ 877 static int txsDoPutFile(PCTXSPKTHDR pPktHdr) 928 * @param fHasMode Set if the packet starts with a mode field. 929 */ 930 static int txsDoPutFile(PCTXSPKTHDR pPktHdr, bool fHasMode) 878 931 { 879 932 int rc; 880 char *pszPath; 881 if (!txsIsStringPktValid(pPktHdr, "file", &pszPath, &rc)) 882 return rc; 933 RTFMODE fMode = 0; 934 char *pszPath; 935 if (!fHasMode) 936 { 937 if (!txsIsStringPktValid(pPktHdr, "file", &pszPath, &rc)) 938 return rc; 939 } 940 else 941 { 942 /* After the packet header follows a mode mask and the remainder of 943 the packet is the zero terminated file name. */ 944 size_t const cbMin = sizeof(TXSPKTHDR) + sizeof(RTFMODE) + 2; 945 if (pPktHdr->cb < cbMin) 946 return txsReplyBadMinSize(pPktHdr, cbMin); 947 if (!txsIsStringValid(pPktHdr, "file", (const char *)(pPktHdr + 1) + sizeof(RTFMODE), &pszPath, NULL, &rc)) 948 return rc; 949 fMode = *(RTFMODE const *)(pPktHdr + 1); 950 fMode <<= RTFILE_O_CREATE_MODE_SHIFT; 951 fMode &= RTFILE_O_CREATE_MODE_MASK; 952 } 883 953 884 954 RTFILE hFile; 885 rc = RTFileOpen(&hFile, pszPath, RTFILE_O_WRITE | RTFILE_O_DENY_WRITE | RTFILE_O_CREATE_REPLACE );955 rc = RTFileOpen(&hFile, pszPath, RTFILE_O_WRITE | RTFILE_O_DENY_WRITE | RTFILE_O_CREATE_REPLACE | fMode); 886 956 if (RT_SUCCESS(rc)) 887 957 { … … 890 960 if (RT_SUCCESS(rc)) 891 961 { 962 if (fMode) 963 RTFileSetMode(hFile, fMode); 964 892 965 /* 893 966 * Read client command packets and process them. … … 1148 1221 static int txsDoChMod(PCTXSPKTHDR pPktHdr) 1149 1222 { 1150 return txsReplyNotImplemented(pPktHdr); 1223 /* After the packet header follows a mode mask and the remainder of 1224 the packet is the zero terminated file name. */ 1225 size_t const cbMin = sizeof(TXSPKTHDR) + sizeof(RTFMODE) + 2; 1226 if (pPktHdr->cb < cbMin) 1227 return txsReplyBadMinSize(pPktHdr, cbMin); 1228 1229 int rc; 1230 char *pszPath; 1231 if (!txsIsStringValid(pPktHdr, "path", (const char *)(pPktHdr + 1) + sizeof(RTFMODE), &pszPath, NULL, &rc)) 1232 return rc; 1233 1234 RTFMODE fMode = *(RTFMODE const *)(pPktHdr + 1); 1235 1236 rc = RTPathSetMode(pszPath, fMode); 1237 1238 rc = txsReplyRC(pPktHdr, rc, "RTPathSetMode(\"%s\", %o)", pszPath, fMode); 1239 RTStrFree(pszPath); 1240 return rc; 1151 1241 } 1152 1242 … … 1184 1274 return rc; 1185 1275 1186 rc = VERR_NOT_IMPLEMENTED; /// @todo RTSymlinkDelete(pszPath);1276 rc = RTSymlinkDelete(pszPath, 0); 1187 1277 1188 1278 rc = txsReplyRC(pPktHdr, rc, "RTSymlinkDelete(\"%s\")", pszPath); … … 2835 2925 rc = txsDoList(pPktHdr); 2836 2926 else if (txsIsSameOpcode(pPktHdr, "PUT FILE")) 2837 rc = txsDoPutFile(pPktHdr); 2927 rc = txsDoPutFile(pPktHdr, false /*fHasMode*/); 2928 else if (txsIsSameOpcode(pPktHdr, "PUT2FILE")) 2929 rc = txsDoPutFile(pPktHdr, true /*fHasMode*/); 2838 2930 else if (txsIsSameOpcode(pPktHdr, "GET FILE")) 2839 2931 rc = txsDoGetFile(pPktHdr); … … 2841 2933 rc = txsDoUnpackFile(pPktHdr); 2842 2934 /* Misc: */ 2935 //else if (txsIsSameOpcode(pPktHdr, "EXP STR ")) 2936 // rc = txsDoExpandString(pPktHdr); 2843 2937 else 2844 2938 rc = txsReplyUnknown(pPktHdr); … … 3179 3273 #endif 3180 3274 3275 int rc = RTPathGetCurrent(g_szCwd, sizeof(g_szCwd)); 3276 if (RT_FAILURE(rc)) 3277 RTMsgError("RTPathGetCurrent failed: %Rrc\n", rc); 3278 g_szCwd[sizeof(g_szCwd) - 1] = '\0'; 3279 3280 if (!RTProcGetExecutablePath(g_szTxsDir, sizeof(g_szTxsDir))) 3281 RTMsgError("RTProcGetExecutablePath failed!\n"); 3282 g_szTxsDir[sizeof(g_szTxsDir) - 1] = '\0'; 3283 RTPathStripFilename(g_szTxsDir); 3284 RTPathStripTrailingSlash(g_szTxsDir); 3285 3181 3286 /* 3182 3287 * The CD/DVD-ROM location. … … 3198 3303 * Temporary directory. 3199 3304 */ 3200 intrc = RTPathTemp(g_szDefScratchPath, sizeof(g_szDefScratchPath));3305 rc = RTPathTemp(g_szDefScratchPath, sizeof(g_szDefScratchPath)); 3201 3306 if (RT_SUCCESS(rc)) 3202 3307 #if defined(RT_OS_OS2) || defined(RT_OS_WINDOWS) || defined(RT_OS_DOS)
Note:
See TracChangeset
for help on using the changeset viewer.