From e45c634e48823219f3d449ee0c69fdcb4623186c Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Thu, 26 Mar 2020 12:03:10 +0900 Subject: [PATCH] need wait for windows and arm arch env? Signed-off-by: Yuta Iwama --- Rakefile | 3 ++- lib/fluent/daemonizer.rb | 11 ++++++++++- test/test_daemonizer.rb | 16 +++++++++++++--- 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Rakefile b/Rakefile index 82a1a53541..6456d4b935 100755 --- a/Rakefile +++ b/Rakefile @@ -34,7 +34,8 @@ Rake::TestTask.new(:base_test) do |t| t.test_files = if ENV["WIN_RAPID"] ["test/test_event.rb", "test/test_supervisor.rb", "test/plugin_helper/test_event_loop.rb"] else - tests = Dir["test/**/test_*.rb"].sort + # tests = Dir["test/**/test_*.rb"].sort + tests = Dir["test/test_daemonizer.rb"].sort if Process.uid.zero? puts "test_file_util.rb for non-root user env. Disable this test on root environment" tests.delete("test/plugin/test_file_util.rb") diff --git a/lib/fluent/daemonizer.rb b/lib/fluent/daemonizer.rb index 3549d13fbf..effe77c67c 100644 --- a/lib/fluent/daemonizer.rb +++ b/lib/fluent/daemonizer.rb @@ -14,7 +14,12 @@ # limitations under the License. # -require 'fluent/config/error' +require 'fluent/plugin/file_util' +# if Fluent.windows? +# require_relative 'file_wrapper' +# else +# Fluent::FileWrapper = File +# end module Fluent class Daemonizer @@ -52,6 +57,10 @@ def daemonize_with_spawn(pid_fullpath, args) def check_pidfile(pid_path) if File.exist?(pid_path) + puts nil, '<============================================================ OUTPUT START HERE' + p Process.uid.nonzero? + p readable: File.readable?(pid_path), writable: File.writable?(pid_path) + puts '<============================================================ OUTPUT CLOSE HERE', nil if !File.readable?(pid_path) || !File.writable?(pid_path) raise Fluent::ConfigError, "Cannot access pid file: #{pid_path}" end diff --git a/test/test_daemonizer.rb b/test/test_daemonizer.rb index 91a06f599e..3402bf9037 100644 --- a/test/test_daemonizer.rb +++ b/test/test_daemonizer.rb @@ -36,10 +36,14 @@ class DaemonizerTest < ::Test::Unit::TestCase sub_test_case 'when pid file already exists' do test 'raise an error when process is running' do + omit "root user" if Process.uid.zero? pid_path = File.join(TMP_DIR, 'file.pid') File.write(pid_path, '1') + waiting(10) { sleep 0.1 until File.exist?(pid_path) } + mock(Process).daemon(anything, anything).never + mock(Process).spawn(anything).never mock(Process).kill(0, 1).once assert_raise(Fluent::ConfigError.new('pid(1) is running')) do @@ -48,10 +52,12 @@ class DaemonizerTest < ::Test::Unit::TestCase end test 'raise an error when file is not redable' do + omit "root user" if Process.uid.zero? not_readable_path = File.join(TMP_DIR, 'not_readable.pid') File.write(not_readable_path, '1') - FileUtils.chmod(0333, not_readable_path) + FileUtils.chmod('-r', not_readable_path) + waiting(10) { sleep 0.1 until (File.exist?(not_readable_path) && !File.readable?(not_readable_path)) } mock(Process).daemon(anything, anything).never assert_raise(Fluent::ConfigError.new("Cannot access pid file: #{File.absolute_path(not_readable_path)}")) do @@ -60,10 +66,12 @@ class DaemonizerTest < ::Test::Unit::TestCase end test 'raise an error when file is not writable' do + omit "root user" if Process.uid.zero? not_writable_path = File.join(TMP_DIR, 'not_writable.pid') File.write(not_writable_path, '1') - FileUtils.chmod(0555, not_writable_path) + FileUtils.chmod('-w', not_writable_path) + waiting(10) { sleep 0.1 until (File.exist?(not_writable_path) && !File.writable?(not_writable_path)) } mock(Process).daemon(anything, anything).never assert_raise(Fluent::ConfigError.new("Cannot access pid file: #{File.absolute_path(not_writable_path)}")) do @@ -72,11 +80,13 @@ class DaemonizerTest < ::Test::Unit::TestCase end test 'raise an error when directory is not writable' do + omit "root user" if Process.uid.zero? not_writable_dir = File.join(TMP_DIR, 'not_writable') pid_path = File.join(not_writable_dir, 'file.pid') FileUtils.mkdir_p(not_writable_dir) - FileUtils.chmod(0555, not_writable_dir) + FileUtils.chmod('-w', not_writable_dir) + waiting(10) { sleep 0.1 until !File.writable?(not_writable_dir) } mock(Process).daemon(anything, anything).never assert_raise(Fluent::ConfigError.new("Cannot access directory for pid file: #{File.absolute_path(not_writable_dir)}")) do