Skip to content

Commit

Permalink
Merge pull request #1963 from jl2005/master
Browse files Browse the repository at this point in the history
change read_pos and read_ino. relate #1953 #1804
  • Loading branch information
repeatedly authored Jun 11, 2018
2 parents aa848de + bee4639 commit 31fb6a4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
22 changes: 10 additions & 12 deletions lib/fluent/plugin/in_tail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ def [](path)
@file.write "0000000000000000\t0000000000000000\n"
@last_pos = @file.pos

@map[path] = FilePositionEntry.new(@file, seek)
@map[path] = FilePositionEntry.new(@file, seek, 0, 0)
end

def self.parse(file)
Expand All @@ -874,8 +874,10 @@ def self.parse(file)
m = /^([^\t]+)\t([0-9a-fA-F]+)\t([0-9a-fA-F]+)/.match(line)
next unless m
path = m[1]
pos = m[2].to_i(16)
ino = m[3].to_i(16)
seek = file.pos - line.bytesize + path.bytesize + 1
map[path] = FilePositionEntry.new(file, seek)
map[path] = FilePositionEntry.new(file, seek, pos, ino)
}
new(file, map, file.pos)
end
Expand Down Expand Up @@ -908,16 +910,18 @@ class FilePositionEntry
LN_OFFSET = 33
SIZE = 34

def initialize(file, seek)
def initialize(file, seek, pos, inode)
@file = file
@seek = seek
@pos = nil
@pos = pos
@inode = inode
end

def update(ino, pos)
@file.pos = @seek
@file.write "%016x\t%016x" % [pos, ino]
@pos = pos
@inode = ino
end

def update_pos(pos)
Expand All @@ -927,17 +931,11 @@ def update_pos(pos)
end

def read_inode
@file.pos = @seek + INO_OFFSET
raw = @file.read(16)
raw ? raw.to_i(16) : 0
@inode
end

def read_pos
@pos ||= begin
@file.pos = @seek
raw = @file.read(16)
raw ? raw.to_i(16) : 0
end
@pos
end
end

Expand Down
8 changes: 4 additions & 4 deletions test/plugin_helper/test_child_process.rb
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ def configure(conf)
unless Fluent.windows?
test 'can specify subprocess name' do
io = IO.popen([["cat", "caaaaaaaaaaat"], '-'])
process_naming_enabled = (open("|ps"){|_io| _io.readlines }.select{|line| line.include?("caaaaaaaaaaat") }.size > 0)
process_naming_enabled = (open("|ps opid,cmd"){|_io| _io.readlines }.select{|line| line.include?("caaaaaaaaaaat") }.size > 0)
Process.kill(:TERM, io.pid) rescue nil
io.close rescue nil

Expand All @@ -527,15 +527,15 @@ def configure(conf)
m.lock
ran = true
pids << @d.child_process_id
proc_lines += open("|ps"){|_io| _io.readlines }
proc_lines += open("|ps opid,cmd"){|_io| _io.readlines }
m.unlock
readio.read
end
sleep TEST_WAIT_INTERVAL_FOR_BLOCK_RUNNING until m.locked? || ran
m.lock
pid = pids.first
# 51358 ttys001 0:00.00 sleeper -e sleep 10
assert{ proc_lines.select{|line| line =~ /^\s*#{pid}\s/ }.first.strip.split(/\s+/)[3] == "sleeeeeeeeeper" }
# 16357 sleeeeeeeeeper -e sleep 10; puts "hello"
assert{ proc_lines.select{|line| line =~ /^\s*#{pid}\s/ }.first.strip.split(/\s+/)[1] == "sleeeeeeeeeper" }
@d.stop; @d.shutdown; @d.close; @d.terminate
end
end
Expand Down

0 comments on commit 31fb6a4

Please sign in to comment.