logger.rb: fix extra log ratation

* lib/logger.rb (lock_shift_log): no need to rotate the log file
  if it has been rotated by another process.  based on the patch
  by no6v (Nobuhiro IMAI) in [ruby-core:58620].  [Bug #9133]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44203 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-12-14 05:43:01 +00:00
Родитель 742659cb6c
Коммит 95ed081663
3 изменённых файлов: 46 добавлений и 2 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Sat Dec 14 14:42:53 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/logger.rb (lock_shift_log): no need to rotate the log file
if it has been rotated by another process. based on the patch
by no6v (Nobuhiro IMAI) in [ruby-core:58620]. [Bug #9133]
Sat Dec 14 13:01:45 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* proc.c (mnew_from_me): method by respond_to_missing? should be

Просмотреть файл

@ -644,8 +644,7 @@ private
begin
File.open(@filename, File::WRONLY | File::APPEND) do |lock|
lock.flock(File::LOCK_EX) # inter-process locking. will be unlocked at closing file
ino = lock.stat.ino
if ino == File.stat(@filename).ino
if File.identical?(@filename, lock) and File.identical?(lock, @dev)
yield # log shifting
else
# log shifted by another process (i-node before locking and i-node after locking are different)

Просмотреть файл

@ -2,6 +2,7 @@
require 'test/unit'
require 'logger'
require 'tempfile'
require 'tmpdir'
require_relative '../ruby/envutil'
@ -542,6 +543,44 @@ class TestLogDevice < Test::Unit::TestCase
end
end
def test_shifting_size_not_rotate_too_much
d(@filename).__send__(:add_log_header, @tempfile)
header_size = @tempfile.size
message = "*" * 99 + "\n"
shift_size = header_size + message.size * 3 - 1
opt = {shift_age: 1, shift_size: shift_size}
Dir.mktmpdir do |tmpdir|
begin
log = File.join(tmpdir, "log")
logdev1 = d(log, opt)
logdev2 = d(log, opt)
assert_file.identical?(log, logdev1.dev)
assert_file.identical?(log, logdev2.dev)
3.times{logdev1.write(message)}
assert_file.identical?(log, logdev1.dev)
assert_file.identical?(log, logdev2.dev)
logdev1.write(message)
assert_file.identical?(log, logdev1.dev)
assert_file.identical?(log + ".0", logdev2.dev)
logdev2.write(message)
assert_file.identical?(log, logdev1.dev)
assert_file.identical?(log, logdev2.dev)
logdev1.write(message)
assert_file.identical?(log, logdev1.dev)
assert_file.identical?(log, logdev2.dev)
ensure
logdev1.close if logdev1
logdev2.close if logdev2
end
end
end
private
def run_children(n, args, src)