コード例 #1
0
ファイル: main.cpp プロジェクト: bjornvar/omr
DDR_RC
readFileList(OMRPortLibrary *portLibrary, const char *debugFileList, vector<string> *debugFiles)
{
	OMRPORT_ACCESS_FROM_OMRPORT(portLibrary);
	DDR_RC rc = DDR_RC_OK;

	/* Read list of debug files to scan from the input file. */
	intptr_t fd = omrfile_open(debugFileList,  EsOpenRead, 0660);
	if (0 > fd) {
		ERRMSG("Failure attempting to open %s\nExiting...\n", debugFileList);
		rc = DDR_RC_ERROR;
	} else {
		char *buff = NULL;
		int64_t offset = omrfile_seek(fd, 0, SEEK_END);
		if (-1 != offset) {
			buff = (char *)malloc(offset + 1);
			memset(buff, 0, offset + 1);
			omrfile_seek(fd, 0, SEEK_SET);

			if (0 < omrfile_read(fd, buff, offset)) {
				char *fileName = strtok(buff, "\n");
				while (NULL != fileName) {
					debugFiles->push_back(string(fileName));
					fileName = strtok(NULL, "\n");
				}
			}
			free(buff);
		}
	}
	return rc;
}
コード例 #2
0
ファイル: GCConfigTest.cpp プロジェクト: DanHeidinga/omr
void
printFile(const char *name)
{
	OMRPORT_ACCESS_FROM_OMRPORT(gcTestEnv->portLib);
	intptr_t fileDescriptor = omrfile_open(name, EsOpenRead, 0444);
	char readBuf[2048];
	while (readBuf == omrfile_read_text(fileDescriptor, readBuf, 2048)) {
		omrtty_printf("%s", readBuf);
	}
	omrfile_close(fileDescriptor);
	omrtty_printf("\n");
}
コード例 #3
0
/**
 * Opens the file to log output to and prints the header.
 * @return true on sucess, false otherwise
 */
bool
MM_VerboseWriterFileLoggingSynchronous::openFile(MM_EnvironmentBase *env)
{
	OMRPORT_ACCESS_FROM_OMRPORT(env->getPortLibrary());
	MM_GCExtensionsBase* extensions = env->getExtensions();
	const char* version = omrgc_get_version(env->getOmrVM());
	
	char *filenameToOpen = expandFilename(env, _currentFile);
	if (NULL == filenameToOpen) {
		return false;
	}
	
	_logFileDescriptor = omrfile_open(filenameToOpen, EsOpenRead | EsOpenWrite | EsOpenCreate | EsOpenTruncate, 0666);
	if(-1 == _logFileDescriptor) {
		char *cursor = filenameToOpen;
		/**
		 * This may have failed due to directories in the path not being available.
		 * Try to create these directories and attempt to open again before failing.
		 */
		while ( (cursor = strchr(++cursor, DIR_SEPARATOR)) != NULL ) {
			*cursor = '\0';
			omrfile_mkdir(filenameToOpen);
			*cursor = DIR_SEPARATOR;
		}

		/* Try again */
		_logFileDescriptor = omrfile_open(filenameToOpen, EsOpenRead | EsOpenWrite | EsOpenCreate | EsOpenTruncate, 0666);
		if (-1 == _logFileDescriptor) {
			_manager->handleFileOpenError(env, filenameToOpen);
			extensions->getForge()->free(filenameToOpen);
			return false;
		}
	}

	extensions->getForge()->free(filenameToOpen);
	
	omrfile_printf(_logFileDescriptor, getHeader(env), version);
	
	return true;
}
コード例 #4
0
ファイル: agentNegativeTest.cpp プロジェクト: ChengJin01/omr
/*
 * Test scenario for CorruptedAgent:
 * 	- create an empty agent file
 *  - call omr_agent_create() and OMR_Agent::createAgent by providing the empty agent file
 *  - expect openLibrary() to fail
 */
TEST_F(RASAgentNegativeTest, CorruptedAgent)
{
	intptr_t fileDescriptor;
	char fileName[256];
	char agentName[256];
	char hostname[128];
	OMRPORT_ACCESS_FROM_OMRVM(&testVM.omrVM);
	ASSERT_EQ(0, gethostname(hostname, sizeof(hostname)));

	/* generate machine specific file name to prevent conflict between multiple tests running on shared drive */
	omrstr_printf(agentName, sizeof(agentName), "corruptedAgent_%s", hostname);

	/* create fileName with platform-dependent shared library prefix & suffix.
	 *  for Windows, fileName = corruptedAgent_<hostname>.dll
	 *  for Unix, fileName = libcorruptedAgent_<hostname>.so
	 *  for OSX, fileName = libcorruptedAgent_<hostname>.dylib
	 */
#if defined(WIN32) || defined(WIN64)
	omrstr_printf(fileName, sizeof(fileName), "%s.dll", agentName);
#elif defined(OSX)
	omrstr_printf(fileName, sizeof(fileName), "lib%s.dylib", agentName);
#else /* defined(OSX) */
	omrstr_printf(fileName, sizeof(fileName), "lib%s.so", agentName);
#endif /* defined(WIN32) || defined(WIN64) */

	/* create the empty agent file with permission 751*/
	fileDescriptor = omrfile_open(fileName, EsOpenCreate | EsOpenWrite, 0751);
	ASSERT_NE(-1, fileDescriptor) << "omrfile_open \"" << fileName << "\" failed";
	omrfile_close(fileDescriptor);

	/* call omr_agent_create() by providing the empty agent file */
	struct OMR_Agent *agentC = omr_agent_create(&testVM.omrVM, agentName);
	ASSERT_FALSE(NULL == agentC) << "testAgent: createAgent() " << agentName << " failed";
	OMRTEST_ASSERT_ERROR(OMR_ERROR_ILLEGAL_ARGUMENT, omr_agent_openLibrary(agentC));

	/* call OMR_Agent::createAgent() by providing the empty agent file */
	OMR_Agent *agentCPP = OMR_Agent::createAgent(&testVM.omrVM, agentName);
	ASSERT_FALSE(NULL == agentCPP) << "testAgent: createAgent() failed";
	OMRTEST_ASSERT_ERROR(OMR_ERROR_ILLEGAL_ARGUMENT, agentCPP->openLibrary());

	omrfile_unlink(fileName);
}
コード例 #5
0
ファイル: omrtracecomponent.cpp プロジェクト: ChengJin01/omr
/*******************************************************************************
 * name        - openFileFromDirectorySearchList
 * description - Look for a file in a semicolon separated list of directories
 * parameters  - searchPath - a semicolon separated list of directories, null
 *                            terminated and non NULL.
 *               fileName - the name of the file to look for null terminated
 *               flags - flags to be passed into the file open call
 *               mode - flags to be passed into the file open call
 * returns     - intptr_t >= 0 on success, < 0 on failure
 *                        success returns a valid file handle to be used in
 *                        subsequent file operations.
 ******************************************************************************/
static intptr_t
openFileFromDirectorySearchList(char *searchPath, char *fileName, int32_t flags, int32_t mode)
{
	intptr_t fileHandle = -1;
	char tempFileNamePath[MAX_IMAGE_PATH_LENGTH];
	char *nextPathEntry = searchPath;
	size_t searchPathLen;
	size_t offset = 0;
	if (searchPath == NULL || fileName == NULL) {
		/* error */
		return fileHandle;
	}

	searchPathLen = strlen(searchPath);
	while (offset < searchPathLen) {
		OMRPORT_ACCESS_FROM_OMRPORT(OMR_TRACEGLOBAL(portLibrary));
		size_t currentPathEntryEndsAt = strcspn(nextPathEntry, ";\0");
		strncpy(tempFileNamePath, nextPathEntry, currentPathEntryEndsAt);
		tempFileNamePath[currentPathEntryEndsAt] = '\0';
		strcat(tempFileNamePath, DIR_SEPARATOR_STR);
		strcat(tempFileNamePath, fileName);

		UT_DBGOUT(2, ("<UT> dat file loader looking for %s at %s\n", fileName, tempFileNamePath));

		fileHandle = omrfile_open(tempFileNamePath, flags, mode);
		if (fileHandle != -1) {
			UT_DBGOUT(2, ("<UT> dat file loader found for %s at %s\n", fileName, tempFileNamePath));
			return fileHandle;
		}

		offset += currentPathEntryEndsAt + 1;
		nextPathEntry += currentPathEntryEndsAt + 1;;
	}

	return fileHandle;
}