Skip to content
This repository has been archived by the owner before Nov 9, 2022. It is now read-only.
Permalink
Browse files
8256008: UL does not report anything if disk writing fails
Reviewed-by: stuefe
  • Loading branch information
YaSuenag committed Dec 2, 2020
1 parent fb139cf commit 3e3745c2dabf3e9d5f326362a6688a701b7dcf21
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 19 deletions.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -292,10 +292,12 @@ int LogFileOutput::write(const LogDecorations& decorations, const char* msg) {

_rotation_semaphore.wait();
int written = LogFileStreamOutput::write(decorations, msg);
_current_size += written;
if (written > 0) {
_current_size += written;

if (should_rotate()) {
rotate();
if (should_rotate()) {
rotate();
}
}
_rotation_semaphore.signal();

@@ -310,10 +312,12 @@ int LogFileOutput::write(LogMessageBuffer::Iterator msg_iterator) {

_rotation_semaphore.wait();
int written = LogFileStreamOutput::write(msg_iterator);
_current_size += written;
if (written > 0) {
_current_size += written;

if (should_rotate()) {
rotate();
if (should_rotate()) {
rotate();
}
}
_rotation_semaphore.signal();

@@ -28,6 +28,7 @@
#include "logging/logFileStreamOutput.hpp"
#include "logging/logMessageBuffer.hpp"
#include "memory/allocation.inline.hpp"
#include "utilities/defaultStream.hpp"

static bool initialized;
static union {
@@ -86,19 +87,47 @@ class FileLocker : public StackObj {
}
};

bool LogFileStreamOutput::flush() {
bool result = true;
if (fflush(_stream) != 0) {
if (!_write_error_is_shown) {
jio_fprintf(defaultStream::error_stream(),
"Could not flush log: %s (%s (%d))\n", name(), os::strerror(errno), errno);
jio_fprintf(_stream, "\nERROR: Could not flush log (%d)\n", errno);
_write_error_is_shown = true;
}
result = false;
}
return result;
}

#define WRITE_LOG_WITH_RESULT_CHECK(op, total) \
{ \
int result = op; \
if (result < 0) { \
if (!_write_error_is_shown) { \
jio_fprintf(defaultStream::error_stream(), \
"Could not write log: %s\n", name()); \
jio_fprintf(_stream, "\nERROR: Could not write log\n"); \
_write_error_is_shown = true; \
return -1; \
} \
} \
total += result; \
}

int LogFileStreamOutput::write(const LogDecorations& decorations, const char* msg) {
const bool use_decorations = !_decorators.is_empty();

int written = 0;
FileLocker flocker(_stream);
if (use_decorations) {
written += write_decorations(decorations);
written += jio_fprintf(_stream, " ");
WRITE_LOG_WITH_RESULT_CHECK(write_decorations(decorations), written);
WRITE_LOG_WITH_RESULT_CHECK(jio_fprintf(_stream, " "), written);
}
written += jio_fprintf(_stream, "%s\n", msg);
fflush(_stream);
WRITE_LOG_WITH_RESULT_CHECK(jio_fprintf(_stream, "%s\n", msg), written);

return written;
return flush() ? written : -1;
}

int LogFileStreamOutput::write(LogMessageBuffer::Iterator msg_iterator) {
@@ -108,12 +137,11 @@ int LogFileStreamOutput::write(LogMessageBuffer::Iterator msg_iterator) {
FileLocker flocker(_stream);
for (; !msg_iterator.is_at_end(); msg_iterator++) {
if (use_decorations) {
written += write_decorations(msg_iterator.decorations());
written += jio_fprintf(_stream, " ");
WRITE_LOG_WITH_RESULT_CHECK(write_decorations(msg_iterator.decorations()), written);
WRITE_LOG_WITH_RESULT_CHECK(jio_fprintf(_stream, " "), written);
}
written += jio_fprintf(_stream, "%s\n", msg_iterator.message());
WRITE_LOG_WITH_RESULT_CHECK(jio_fprintf(_stream, "%s\n", msg_iterator.message()), written);
}
fflush(_stream);

return written;
return flush() ? written : -1;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2020, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -40,17 +40,20 @@ static LogFileStreamInitializer log_stream_initializer;

// Base class for all FileStream-based log outputs.
class LogFileStreamOutput : public LogOutput {
private:
bool _write_error_is_shown;
protected:
FILE* _stream;
size_t _decorator_padding[LogDecorators::Count];

LogFileStreamOutput(FILE *stream) : _stream(stream) {
LogFileStreamOutput(FILE *stream) : _write_error_is_shown(false), _stream(stream) {
for (size_t i = 0; i < LogDecorators::Count; i++) {
_decorator_padding[i] = 0;
}
}

int write_decorations(const LogDecorations& decorations);
bool flush();

public:
virtual int write(const LogDecorations& decorations, const char* msg);

0 comments on commit 3e3745c

Please sign in to comment.