Beispiel #1
0
/**
 * Synchronize a file's state with the state on disk.
 *
 * @param[in] portLibrary The port library
 * @param[in] fd The file descriptor.
 *
 * @return 0 on success, -1 on failure.
 * @internal @todo return negative portable return code on failure.
 */
int32_t
omrfile_sync(struct OMRPortLibrary *portLibrary, intptr_t inFD)
{
	int fd = (int)inFD;
	int32_t result = 0;

	Trc_PRT_file_sync_Entry(inFD);

#ifdef J9ZOS390
	if (fd == OMRPORT_TTY_OUT) {
		result =  fflush(stdout);
		Trc_PRT_file_sync_Exit(result);
		return result;
	} else if (fd == OMRPORT_TTY_ERR) {
		result =  fflush(stderr);
		Trc_PRT_file_sync_Exit(result);
		return result;
	} else if (fd < FD_BIAS) {
		Trc_PRT_file_sync_Exit(-1);
		/* Cannot fsync STDIN, and no other FD's should exist <FD_BIAS */
		return -1;
	}
#elif (FD_BIAS != 0)
#error FD_BIAS must be 0
#endif

	result = fsync(fd - FD_BIAS);
	Trc_PRT_file_sync_Exit(result);
	return result;
}
Beispiel #2
0
int32_t
omrfile_sync(struct OMRPortLibrary *portLibrary, intptr_t fd)
{
	HANDLE handle = toHandle(portLibrary, fd);

	Trc_PRT_file_sync_Entry(fd);

	/*
	 * According to MSDN:
	 * 1) If hFile is a handle to the server end of a named pipe, the function does not return until the client has read all buffered data from the pipe.
	 * 2) The function fails if hFile is a handle to the console output. That is because the console output is not buffered. The function returns FALSE, and GetLastError returns ERROR_INVALID_HANDLE.
	 *
	 * This behaviour caused JAZZ 44899 defect: Test_SimpleTenantLimitXmt would freeze while waiting for process to terminate while child
	 * was waiting for parent to read from STDIN and STDOUT streams of a child.
	 *
	 * Manual testing showed that even if we called System.out.print('X') and System.err.print('Y') a parent process would still get receive 'X' and 'Y'
	 * (with and without flushing) after child process in terminated.
	 *
	 * This check does not modify original behaviour of the port library because we never actually flushed STDIN and STDOUT handles but
	 * some arbitrary handles 1 & 2.
	 */
	if (((HANDLE)OMRPORT_TTY_OUT == (HANDLE)fd) || ((HANDLE)OMRPORT_TTY_ERR == (HANDLE)fd)) {
		Trc_PRT_file_sync_Exit(0);
		return 0;
	}

	if (FlushFileBuffers(handle)) {
		Trc_PRT_file_sync_Exit(0);
		return 0;
	} else {
		int32_t error = GetLastError();
		error = portLibrary->error_set_last_error(portLibrary, error, findError(error));
		Trc_PRT_file_sync_Exit(error);
		return -1;
	}
}