Changeset 83647 in vbox for trunk/src/VBox/Runtime
- Timestamp:
- Apr 9, 2020 12:14:33 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/log/log.cpp
r83646 r83647 305 305 uint32_t fFlag; /**< The flag value. */ 306 306 bool fInverted; /**< Inverse meaning? */ 307 uint32_t fFixedDest; /**< RTLOGDEST_FIXED_XXX flags blocking this. */308 307 } const g_aLogFlags[] = 309 308 { 310 { "disabled", sizeof("disabled" ) - 1, RTLOGFLAGS_DISABLED, false , 0},311 { "enabled", sizeof("enabled" ) - 1, RTLOGFLAGS_DISABLED, true , 0},312 { "buffered", sizeof("buffered" ) - 1, RTLOGFLAGS_BUFFERED, false , 0},313 { "unbuffered", sizeof("unbuffered" ) - 1, RTLOGFLAGS_BUFFERED, true , 0},314 { "usecrlf", sizeof("usecrlf" ) - 1, RTLOGFLAGS_USECRLF, false , 0},315 { "uself", sizeof("uself" ) - 1, RTLOGFLAGS_USECRLF, true , 0},316 { "append", sizeof("append" ) - 1, RTLOGFLAGS_APPEND, false , RTLOGDEST_FIXED_FILE},317 { "overwrite", sizeof("overwrite" ) - 1, RTLOGFLAGS_APPEND, true , RTLOGDEST_FIXED_FILE},318 { "rel", sizeof("rel" ) - 1, RTLOGFLAGS_REL_TS, false , 0},319 { "abs", sizeof("abs" ) - 1, RTLOGFLAGS_REL_TS, true , 0},320 { "dec", sizeof("dec" ) - 1, RTLOGFLAGS_DECIMAL_TS, false , 0},321 { "hex", sizeof("hex" ) - 1, RTLOGFLAGS_DECIMAL_TS, true , 0},322 { "writethru", sizeof("writethru" ) - 1, RTLOGFLAGS_WRITE_THROUGH, false , 0},323 { "writethrough", sizeof("writethrough") - 1, RTLOGFLAGS_WRITE_THROUGH, false , 0},324 { "flush", sizeof("flush" ) - 1, RTLOGFLAGS_FLUSH, false , 0},325 { "lockcnts", sizeof("lockcnts" ) - 1, RTLOGFLAGS_PREFIX_LOCK_COUNTS, false , 0},326 { "cpuid", sizeof("cpuid" ) - 1, RTLOGFLAGS_PREFIX_CPUID, false , 0},327 { "pid", sizeof("pid" ) - 1, RTLOGFLAGS_PREFIX_PID, false , 0},328 { "flagno", sizeof("flagno" ) - 1, RTLOGFLAGS_PREFIX_FLAG_NO, false , 0},329 { "flag", sizeof("flag" ) - 1, RTLOGFLAGS_PREFIX_FLAG, false , 0},330 { "groupno", sizeof("groupno" ) - 1, RTLOGFLAGS_PREFIX_GROUP_NO, false , 0},331 { "group", sizeof("group" ) - 1, RTLOGFLAGS_PREFIX_GROUP, false , 0},332 { "tid", sizeof("tid" ) - 1, RTLOGFLAGS_PREFIX_TID, false , 0},333 { "thread", sizeof("thread" ) - 1, RTLOGFLAGS_PREFIX_THREAD, false , 0},334 { "custom", sizeof("custom" ) - 1, RTLOGFLAGS_PREFIX_CUSTOM, false , 0},335 { "timeprog", sizeof("timeprog" ) - 1, RTLOGFLAGS_PREFIX_TIME_PROG, false , 0},336 { "time", sizeof("time" ) - 1, RTLOGFLAGS_PREFIX_TIME, false , 0},337 { "msprog", sizeof("msprog" ) - 1, RTLOGFLAGS_PREFIX_MS_PROG, false , 0},338 { "tsc", sizeof("tsc" ) - 1, RTLOGFLAGS_PREFIX_TSC, false , 0}, /* before ts! */339 { "ts", sizeof("ts" ) - 1, RTLOGFLAGS_PREFIX_TS, false , 0},309 { "disabled", sizeof("disabled" ) - 1, RTLOGFLAGS_DISABLED, false }, 310 { "enabled", sizeof("enabled" ) - 1, RTLOGFLAGS_DISABLED, true }, 311 { "buffered", sizeof("buffered" ) - 1, RTLOGFLAGS_BUFFERED, false }, 312 { "unbuffered", sizeof("unbuffered" ) - 1, RTLOGFLAGS_BUFFERED, true }, 313 { "usecrlf", sizeof("usecrlf" ) - 1, RTLOGFLAGS_USECRLF, false }, 314 { "uself", sizeof("uself" ) - 1, RTLOGFLAGS_USECRLF, true }, 315 { "append", sizeof("append" ) - 1, RTLOGFLAGS_APPEND, false }, 316 { "overwrite", sizeof("overwrite" ) - 1, RTLOGFLAGS_APPEND, true }, 317 { "rel", sizeof("rel" ) - 1, RTLOGFLAGS_REL_TS, false }, 318 { "abs", sizeof("abs" ) - 1, RTLOGFLAGS_REL_TS, true }, 319 { "dec", sizeof("dec" ) - 1, RTLOGFLAGS_DECIMAL_TS, false }, 320 { "hex", sizeof("hex" ) - 1, RTLOGFLAGS_DECIMAL_TS, true }, 321 { "writethru", sizeof("writethru" ) - 1, RTLOGFLAGS_WRITE_THROUGH, false }, 322 { "writethrough", sizeof("writethrough") - 1, RTLOGFLAGS_WRITE_THROUGH, false }, 323 { "flush", sizeof("flush" ) - 1, RTLOGFLAGS_FLUSH, false }, 324 { "lockcnts", sizeof("lockcnts" ) - 1, RTLOGFLAGS_PREFIX_LOCK_COUNTS, false }, 325 { "cpuid", sizeof("cpuid" ) - 1, RTLOGFLAGS_PREFIX_CPUID, false }, 326 { "pid", sizeof("pid" ) - 1, RTLOGFLAGS_PREFIX_PID, false }, 327 { "flagno", sizeof("flagno" ) - 1, RTLOGFLAGS_PREFIX_FLAG_NO, false }, 328 { "flag", sizeof("flag" ) - 1, RTLOGFLAGS_PREFIX_FLAG, false }, 329 { "groupno", sizeof("groupno" ) - 1, RTLOGFLAGS_PREFIX_GROUP_NO, false }, 330 { "group", sizeof("group" ) - 1, RTLOGFLAGS_PREFIX_GROUP, false }, 331 { "tid", sizeof("tid" ) - 1, RTLOGFLAGS_PREFIX_TID, false }, 332 { "thread", sizeof("thread" ) - 1, RTLOGFLAGS_PREFIX_THREAD, false }, 333 { "custom", sizeof("custom" ) - 1, RTLOGFLAGS_PREFIX_CUSTOM, false }, 334 { "timeprog", sizeof("timeprog" ) - 1, RTLOGFLAGS_PREFIX_TIME_PROG, false }, 335 { "time", sizeof("time" ) - 1, RTLOGFLAGS_PREFIX_TIME, false }, 336 { "msprog", sizeof("msprog" ) - 1, RTLOGFLAGS_PREFIX_MS_PROG, false }, 337 { "tsc", sizeof("tsc" ) - 1, RTLOGFLAGS_PREFIX_TSC, false }, /* before ts! */ 338 { "ts", sizeof("ts" ) - 1, RTLOGFLAGS_PREFIX_TS, false }, 340 339 /* We intentionally omit RTLOGFLAGS_RESTRICT_GROUPS. */ 341 340 }; … … 363 362 { RT_STR_TUPLE("nodeny"), RTLOGDEST_F_NO_DENY }, 364 363 { RT_STR_TUPLE("user"), RTLOGDEST_USER }, 365 /* The RTLOGDEST_FIXED_XXX flags are omitted on purpose. */366 364 }; 367 365 … … 2046 2044 if (!strncmp(pszValue, g_aLogFlags[i].pszInstr, g_aLogFlags[i].cchInstr)) 2047 2045 { 2048 if (!(g_aLogFlags[i].fFixedDest & pLogger->fDestFlags)) 2049 { 2050 if (fNo == g_aLogFlags[i].fInverted) 2051 pLogger->fFlags |= g_aLogFlags[i].fFlag; 2052 else 2053 pLogger->fFlags &= ~g_aLogFlags[i].fFlag; 2054 } 2046 if (fNo == g_aLogFlags[i].fInverted) 2047 pLogger->fFlags |= g_aLogFlags[i].fFlag; 2048 else 2049 pLogger->fFlags &= ~g_aLogFlags[i].fFlag; 2055 2050 pszValue += g_aLogFlags[i].cchInstr; 2056 2051 break; … … 2320 2315 else if (i == 0 /* file */ && !fNo) 2321 2316 { 2322 if (!(pLogger->fDestFlags & RTLOGDEST_FIXED_FILE)) 2323 { 2324 AssertReturn(cch < sizeof(pLogger->pInt->szFilename), VERR_OUT_OF_RANGE); 2325 memcpy(pLogger->pInt->szFilename, pszValue, cch); 2326 pLogger->pInt->szFilename[cch] = '\0'; 2327 /** @todo reopen log file if pLogger->pInt->fCreated is true ... */ 2328 } 2317 AssertReturn(cch < sizeof(pLogger->pInt->szFilename), VERR_OUT_OF_RANGE); 2318 memcpy(pLogger->pInt->szFilename, pszValue, cch); 2319 pLogger->pInt->szFilename[cch] = '\0'; 2320 /** @todo reopen log file if pLogger->pInt->fCreated is true ... */ 2329 2321 } 2330 2322 /* log directory */ 2331 2323 else if (i == 1 /* dir */ && !fNo) 2332 2324 { 2333 if (!(pLogger->fDestFlags & RTLOGDEST_FIXED_DIR)) 2334 { 2335 const char *pszFile = RTPathFilename(pLogger->pInt->szFilename); 2336 size_t cchFile = pszFile ? strlen(pszFile) : 0; 2337 AssertReturn(cchFile + cch + 1 < sizeof(pLogger->pInt->szFilename), VERR_OUT_OF_RANGE); 2338 memcpy(szTmp, cchFile ? pszFile : "", cchFile + 1); 2339 2340 memcpy(pLogger->pInt->szFilename, pszValue, cch); 2341 pLogger->pInt->szFilename[cch] = '\0'; 2342 RTPathStripTrailingSlash(pLogger->pInt->szFilename); 2343 2344 cch = strlen(pLogger->pInt->szFilename); 2345 pLogger->pInt->szFilename[cch++] = '/'; 2346 memcpy(&pLogger->pInt->szFilename[cch], szTmp, cchFile); 2347 pLogger->pInt->szFilename[cch + cchFile] = '\0'; 2348 /** @todo reopen log file if pLogger->pInt->fCreated is true ... */ 2349 } 2325 const char *pszFile = RTPathFilename(pLogger->pInt->szFilename); 2326 size_t cchFile = pszFile ? strlen(pszFile) : 0; 2327 AssertReturn(cchFile + cch + 1 < sizeof(pLogger->pInt->szFilename), VERR_OUT_OF_RANGE); 2328 memcpy(szTmp, cchFile ? pszFile : "", cchFile + 1); 2329 2330 memcpy(pLogger->pInt->szFilename, pszValue, cch); 2331 pLogger->pInt->szFilename[cch] = '\0'; 2332 RTPathStripTrailingSlash(pLogger->pInt->szFilename); 2333 2334 cch = strlen(pLogger->pInt->szFilename); 2335 pLogger->pInt->szFilename[cch++] = '/'; 2336 memcpy(&pLogger->pInt->szFilename[cch], szTmp, cchFile); 2337 pLogger->pInt->szFilename[cch + cchFile] = '\0'; 2338 /** @todo reopen log file if pLogger->pInt->fCreated is true ... */ 2350 2339 } 2351 2340 else if (i == 2 /* history */) … … 3202 3191 fOpen |= RTFILE_O_OPEN_CREATE | RTFILE_O_APPEND; 3203 3192 else 3204 { 3205 RTFileDelete(pLogger->pInt->szFilename); 3206 fOpen |= RTFILE_O_CREATE; 3207 } 3193 fOpen |= RTFILE_O_CREATE_REPLACE; 3208 3194 if (pLogger->fFlags & RTLOGFLAGS_WRITE_THROUGH) 3209 3195 fOpen |= RTFILE_O_WRITE_THROUGH; … … 3213 3199 unsigned cBackoff = 0; 3214 3200 int rc = RTFileOpen(&pLogger->pInt->hFile, pLogger->pInt->szFilename, fOpen); 3215 while ( ( rc == VERR_SHARING_VIOLATION 3216 || (rc == VERR_ALREADY_EXISTS && !(pLogger->fFlags & RTLOGFLAGS_APPEND))) 3201 while ( rc == VERR_SHARING_VIOLATION 3217 3202 && cBackoff < RT_ELEMENTS(g_acMsLogBackoff)) 3218 3203 { 3219 3204 RTThreadSleep(g_acMsLogBackoff[cBackoff++]); 3220 if (!(pLogger->fFlags & RTLOGFLAGS_APPEND))3221 RTFileDelete(pLogger->pInt->szFilename);3222 3205 rc = RTFileOpen(&pLogger->pInt->hFile, pLogger->pInt->szFilename, fOpen); 3223 3206 }
Note:
See TracChangeset
for help on using the changeset viewer.