From 50b5fbed54cb8bbd75f13e2332cb67d9294d8c01 Mon Sep 17 00:00:00 2001 From: Koichi TANAKA Date: Wed, 3 Dec 2014 16:47:02 +0900 Subject: [PATCH] Fix bug: pid become zero when pid file is empty --- app/models/fluentd/agent/local_common.rb | 1 + spec/models/fluentd/agent/local_common_spec.rb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/models/fluentd/agent/local_common.rb b/app/models/fluentd/agent/local_common.rb index 06f2f75..a9b7e1e 100644 --- a/app/models/fluentd/agent/local_common.rb +++ b/app/models/fluentd/agent/local_common.rb @@ -55,6 +55,7 @@ class Fluentd def pid return unless File.exists?(pid_file) + return if File.zero?(pid_file) File.read(pid_file).to_i rescue nil end diff --git a/spec/models/fluentd/agent/local_common_spec.rb b/spec/models/fluentd/agent/local_common_spec.rb index a928ce9..582804d 100644 --- a/spec/models/fluentd/agent/local_common_spec.rb +++ b/spec/models/fluentd/agent/local_common_spec.rb @@ -20,10 +20,10 @@ describe 'Fluentd::Agent::LocalCommon' do end context 'valid pid file given' do - before { File.write pid_file_path, '99999' } + before { File.write pid_file_path, '9999' } after { FileUtils.rm pid_file_path } - its(:pid) { should eq(99999) } + its(:pid) { should eq(9999) } end end end