FileHandle_t VirtualFunctionHooks::IBaseFileSystem__Open(const char *pFileName, const char *pOptions, const char *pathID) { IBaseFileSystem *ths = (IBaseFileSystem *)this; std::string relative_path, full_path; if (pathID && strcmp("SKIN", pathID)) if (FunctionHooks->mainthread == ThreadGetCurrentId()) { try { ToFull(pFileName, pathID, full_path); RelativeFrom(full_path, "BASE_PATH", relative_path); } catch (std::exception e) { return 0; } OpenResult opener(relative_path, full_path); if (!opener.GetResult()) return 0; } else { FSLog(std::string("Path ID ") + (pathID ? pathID : "NULL") + " accessed from non-main thread for file " + pFileName + " (" + (pOptions ? pOptions : "no options") + ")"); } return FunctionHooks->BaseFileSystemReplacer->Call<FileHandle_t, const char *, const char *, const char *>(FunctionHooks->IBaseFileSystem__Open__index, pFileName, pOptions, pathID); }
void LogError(long code, char *fmt, ... ) { va_list ap; int len; char buffer[1024]; va_start(ap, fmt); len = vsnprintf(buffer, sizeof(buffer), fmt, ap); va_end(ap); if (len >= 1024) { len = 1023; buffer[1023] = '\0'; } /* Be consistent with (unintentional?) historic behavior. */ if (code) { FSLog("%s: %s\n", afs_error_table_name(code), afs_error_message(code)); WriteLogBuffer(buffer, len); } else { FSLog("%s", buffer); } }
int OpenLog(const char *fileName) { /* * This function should allow various libraries that inconsistently * use stdout/stderr to all go to the same place */ int tempfd, isfifo = 0; char oldName[MAXPATHLEN]; struct timeval Start; struct tm *TimeFields; char FileName[MAXPATHLEN]; #ifndef AFS_NT40_ENV struct stat statbuf; if (serverLogSyslog) { openlog(serverLogSyslogTag, LOG_PID, serverLogSyslogFacility); return (0); } /* Support named pipes as logs by not rotating them */ if ((lstat(fileName, &statbuf) == 0) && (S_ISFIFO(statbuf.st_mode))) { isfifo = 1; } #endif if (mrafsStyleLogs) { time_t t; struct stat buf; FT_GetTimeOfDay(&Start, 0); t = Start.tv_sec; TimeFields = localtime(&t); if (fileName) { if (strncmp(fileName, (char *)&ourName, strlen(fileName))) strcpy((char *)&ourName, (char *)fileName); } makefilename: afs_snprintf(FileName, MAXPATHLEN, "%s.%d%02d%02d%02d%02d%02d", ourName, TimeFields->tm_year + 1900, TimeFields->tm_mon + 1, TimeFields->tm_mday, TimeFields->tm_hour, TimeFields->tm_min, TimeFields->tm_sec); if(lstat(FileName, &buf) == 0) { /* avoid clobbering a log */ TimeFields->tm_sec++; goto makefilename; } if (!isfifo) renamefile(fileName, FileName); /* don't check error code */ tempfd = open(fileName, O_WRONLY | O_TRUNC | O_CREAT | O_APPEND | (isfifo?O_NONBLOCK:0), 0666); } else { strcpy(oldName, fileName); strcat(oldName, ".old"); /* don't check error */ if (!isfifo) renamefile(fileName, oldName); tempfd = open(fileName, O_WRONLY | O_TRUNC | O_CREAT | (isfifo?O_NONBLOCK:0), 0666); } if (tempfd < 0) { printf("Unable to open log file %s\n", fileName); return -1; } /* redirect stdout and stderr so random printf's don't write to data */ (void)freopen(fileName, "a", stdout); (void)freopen(fileName, "a", stderr); #ifdef HAVE_SETVBUF setvbuf(stderr, NULL, _IONBF, 0); #else setbuf(stderr, NULL); #endif #if defined(AFS_PTHREAD_ENV) MUTEX_INIT(&serverLogMutex, "serverlog", MUTEX_DEFAULT, 0); #endif /* AFS_PTHREAD_ENV */ serverLogFD = tempfd; if (mrafsStyleLogs) { FSLog("Running version %s\n", cml_version_number +4); } return 0; } /*OpenLog */