# HG changeset patch # User hseigel # Date 1547732891 18000 # Node ID 55cee96fefece7a1c7af9893e365dd8bc6d3e916 # Parent 91f56aee3928fa1b85d6cc6d12524fd958acd9d8 8215699: -Xlog::file cannot be used with named pipe Summary: If the log file is a named pipe then change the default file_count to zero so no log file rotation is attempted. Reviewed-by: lfoltan, coleenp diff -r 91f56aee3928 -r 55cee96fefec src/hotspot/os/windows/os_windows.cpp --- a/src/hotspot/os/windows/os_windows.cpp Thu Jan 10 17:08:44 2019 +0800 +++ b/src/hotspot/os/windows/os_windows.cpp Thu Jan 17 08:48:11 2019 -0500 @@ -4707,9 +4707,6 @@ static int nonSeekAvailable(int, long *); static int stdinAvailable(int, long *); -#define S_ISCHR(mode) (((mode) & _S_IFCHR) == _S_IFCHR) -#define S_ISFIFO(mode) (((mode) & _S_IFIFO) == _S_IFIFO) - // This code is a copy of JDK's sysAvailable // from src/windows/hpi/src/sys_api_md.c diff -r 91f56aee3928 -r 55cee96fefec src/hotspot/os/windows/os_windows.hpp --- a/src/hotspot/os/windows/os_windows.hpp Thu Jan 10 17:08:44 2019 +0800 +++ b/src/hotspot/os/windows/os_windows.hpp Thu Jan 17 08:48:11 2019 -0500 @@ -29,6 +29,9 @@ // strtok_s is the Windows thread-safe equivalent of POSIX strtok_r #define strtok_r strtok_s +#define S_ISCHR(mode) (((mode) & _S_IFCHR) == _S_IFCHR) +#define S_ISFIFO(mode) (((mode) & _S_IFIFO) == _S_IFIFO) + // Information about the protection of the page at address '0' on this os. static bool zero_page_read_protected() { return true; } diff -r 91f56aee3928 -r 55cee96fefec src/hotspot/share/logging/logFileOutput.cpp --- a/src/hotspot/share/logging/logFileOutput.cpp Thu Jan 10 17:08:44 2019 +0800 +++ b/src/hotspot/share/logging/logFileOutput.cpp Thu Jan 17 08:48:11 2019 -0500 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2015, 2019, 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 @@ -45,7 +45,7 @@ LogFileOutput::LogFileOutput(const char* name) : LogFileStreamOutput(NULL), _name(os::strdup_check_oom(name, mtLogging)), _file_name(NULL), _archive_name(NULL), _current_file(0), - _file_count(DefaultFileCount), _archive_name_len(0), + _file_count(DefaultFileCount), _is_default_file_count(true), _archive_name_len(0), _rotate_size(DefaultFileSize), _current_size(0), _rotation_semaphore(1) { assert(strstr(name, Prefix) == name, "invalid output name '%s': missing prefix: %s", name, Prefix); _file_name = make_file_name(name + strlen(Prefix), _pid_str, _vm_start_time_str); @@ -101,6 +101,15 @@ return (st.st_mode & S_IFMT) == S_IFREG; } +static bool is_fifo_file(const char* filename) { + struct stat st; + int ret = os::stat(filename, &st); + if (ret != 0) { + return false; + } + return S_ISFIFO(st.st_mode); +} + // Try to find the next number that should be used for file rotation. // Return UINT_MAX on error. static uint next_file_number(const char* filename, @@ -187,6 +196,7 @@ break; } _file_count = static_cast(value); + _is_default_file_count = false; } else if (strcmp(FileSizeOptionKey, key) == 0) { julong value; success = Arguments::atojulong(value_str, &value); @@ -214,6 +224,11 @@ return false; } + bool file_exist = file_exists(_file_name); + if (file_exist && _is_default_file_count && is_fifo_file(_file_name)) { + _file_count = 0; // Prevent file rotation for fifo's such as named pipes. + } + if (_file_count > 0) { // compute digits with filecount - 1 since numbers will start from 0 _file_count_max_digits = number_of_digits(_file_count - 1); @@ -225,7 +240,7 @@ ", filesize: " SIZE_FORMAT " KiB).", _file_name, _file_count, _rotate_size / K); - if (_file_count > 0 && file_exists(_file_name)) { + if (_file_count > 0 && file_exist) { if (!is_regular_file(_file_name)) { errstream->print_cr("Unable to log to file %s with log file rotation: " "%s is not a regular file", diff -r 91f56aee3928 -r 55cee96fefec src/hotspot/share/logging/logFileOutput.hpp --- a/src/hotspot/share/logging/logFileOutput.hpp Thu Jan 10 17:08:44 2019 +0800 +++ b/src/hotspot/share/logging/logFileOutput.hpp Thu Jan 17 08:48:11 2019 -0500 @@ -54,6 +54,7 @@ uint _current_file; uint _file_count; uint _file_count_max_digits; + bool _is_default_file_count; size_t _archive_name_len; size_t _rotate_size;