Skip to content

Commit 2008795

Browse files
committed
chumask: fix issue where it only works with standalone worker
Fix fluent#3671 (88a7260) After fluent#3671, the value of `chumask` passed to ServerEngine was always `nil`. The `chumask` value was being used only when standalone. It appears to be unintentional. This fixes it. * By default, `0` as `chumask` is passed to ServerEngine. * If specifying `--umask` option, that value is passed. * This `chumask` value is applied when using `daemonize`. * When not using `daemonize`, the value is not used. * This is the specification of ServerEngine. Specification change: (Just undo the specification that fluent#3671 unintentionally changed.) * This changes the default `umask` when using `daemonize`. * fluent-package (RPM/DEB), for example. * Before: system default (`nil` for ServerEngine) * After: `0` Signed-off-by: Daijiro Fukuda <fukuda@clear-code.com>
1 parent 644c921 commit 2008795

File tree

3 files changed

+86
-44
lines changed

3 files changed

+86
-44
lines changed

lib/fluent/supervisor.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def self.serverengine_config(params = {})
587587
log_level: params['log_level'],
588588
chuser: params['chuser'],
589589
chgroup: params['chgroup'],
590-
chumask: params['chumask'],
590+
chumask: params['chumask'].is_a?(Integer) ? params['chumask'] : params['chumask']&.to_i(8),
591591
daemonize: daemonize,
592592
rpc_endpoint: params['rpc_endpoint'],
593593
counter_server: params['counter_server'],
@@ -924,6 +924,7 @@ def supervise
924924
'inline_config' => @inline_config,
925925
'chuser' => @chuser,
926926
'chgroup' => @chgroup,
927+
'chumask' => @chumask,
927928
'fluentd_conf_path' => @config_path,
928929
'fluentd_conf' => @conf.to_s,
929930
'use_v1_config' => @use_v1_config,

test/command/test_fluentd.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1336,6 +1336,14 @@ def multi_workers_ready?; true; end
13361336
end
13371337
end
13381338

1339+
test "--umask should be recognized as command line" do
1340+
conf_path = create_conf_file("empty.conf", "")
1341+
assert File.exist?(conf_path)
1342+
assert_log_matches(create_cmdline(conf_path, "--umask", "222"),
1343+
"spawn command to main:", '"--umask", "222"',
1344+
patterns_not_match: ["[error]"])
1345+
end
1346+
13391347
sub_test_case "--with-source-only" do
13401348
setup do
13411349
omit "Not supported on Windows" if Fluent.windows?

test/test_supervisor.rb

Lines changed: 76 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -610,51 +610,84 @@ def server.config
610610
assert_equal('{"ok":true}', response)
611611
end
612612

613-
def test_serverengine_config
614-
params = {}
615-
params['workers'] = 1
616-
params['fluentd_conf_path'] = "fluentd.conf"
617-
params['use_v1_config'] = true
618-
params['conf_encoding'] = 'utf-8'
619-
params['log_level'] = Fluent::Log::LEVEL_INFO
620-
load_config_proc = Proc.new { Fluent::Supervisor.serverengine_config(params) }
621-
622-
se_config = load_config_proc.call
623-
assert_equal Fluent::Log::LEVEL_INFO, se_config[:log_level]
624-
assert_equal 'spawn', se_config[:worker_type]
625-
assert_equal 1, se_config[:workers]
626-
assert_equal false, se_config[:log_stdin]
627-
assert_equal false, se_config[:log_stdout]
628-
assert_equal false, se_config[:log_stderr]
629-
assert_equal true, se_config[:enable_heartbeat]
630-
assert_equal false, se_config[:auto_heartbeat]
631-
assert_equal "fluentd.conf", se_config[:config_path]
632-
assert_equal false, se_config[:daemonize]
633-
assert_nil se_config[:pid_path]
613+
sub_test_case "serverengine_config" do
614+
def test_normal
615+
params = {}
616+
params['workers'] = 1
617+
params['fluentd_conf_path'] = "fluentd.conf"
618+
params['use_v1_config'] = true
619+
params['conf_encoding'] = 'utf-8'
620+
params['log_level'] = Fluent::Log::LEVEL_INFO
621+
load_config_proc = Proc.new { Fluent::Supervisor.serverengine_config(params) }
622+
623+
se_config = load_config_proc.call
624+
assert_equal Fluent::Log::LEVEL_INFO, se_config[:log_level]
625+
assert_equal 'spawn', se_config[:worker_type]
626+
assert_equal 1, se_config[:workers]
627+
assert_equal false, se_config[:log_stdin]
628+
assert_equal false, se_config[:log_stdout]
629+
assert_equal false, se_config[:log_stderr]
630+
assert_equal true, se_config[:enable_heartbeat]
631+
assert_equal false, se_config[:auto_heartbeat]
632+
assert_equal "fluentd.conf", se_config[:config_path]
633+
assert_equal false, se_config[:daemonize]
634+
assert_nil se_config[:pid_path]
635+
end
636+
637+
def test_daemonize
638+
params = {}
639+
params['workers'] = 1
640+
params['fluentd_conf_path'] = "fluentd.conf"
641+
params['use_v1_config'] = true
642+
params['conf_encoding'] = 'utf-8'
643+
params['log_level'] = Fluent::Log::LEVEL_INFO
644+
params['daemonize'] = './fluentd.pid'
645+
load_config_proc = Proc.new { Fluent::Supervisor.serverengine_config(params) }
646+
647+
se_config = load_config_proc.call
648+
assert_equal Fluent::Log::LEVEL_INFO, se_config[:log_level]
649+
assert_equal 'spawn', se_config[:worker_type]
650+
assert_equal 1, se_config[:workers]
651+
assert_equal false, se_config[:log_stdin]
652+
assert_equal false, se_config[:log_stdout]
653+
assert_equal false, se_config[:log_stderr]
654+
assert_equal true, se_config[:enable_heartbeat]
655+
assert_equal false, se_config[:auto_heartbeat]
656+
assert_equal "fluentd.conf", se_config[:config_path]
657+
assert_equal true, se_config[:daemonize]
658+
assert_equal './fluentd.pid', se_config[:pid_path]
659+
end
660+
661+
data("nil", [nil, nil])
662+
data("default", ["0", 0])
663+
data("000", ["000", 0])
664+
data("0000", ["0000", 0])
665+
data("2", ["2", 2])
666+
data("222", ["222", 146])
667+
data("0222", ["0222", 146])
668+
data("0 as integer", [0, 0])
669+
def test_chumask((chumask, expected))
670+
params = { "chumask" => chumask }
671+
load_config_proc = Proc.new { Fluent::Supervisor.serverengine_config(params) }
672+
673+
se_config = load_config_proc.call
674+
675+
assert_equal expected, se_config[:chumask]
676+
end
634677
end
635678

636-
def test_serverengine_config_for_daemonize
637-
params = {}
638-
params['workers'] = 1
639-
params['fluentd_conf_path'] = "fluentd.conf"
640-
params['use_v1_config'] = true
641-
params['conf_encoding'] = 'utf-8'
642-
params['log_level'] = Fluent::Log::LEVEL_INFO
643-
params['daemonize'] = './fluentd.pid'
644-
load_config_proc = Proc.new { Fluent::Supervisor.serverengine_config(params) }
645-
646-
se_config = load_config_proc.call
647-
assert_equal Fluent::Log::LEVEL_INFO, se_config[:log_level]
648-
assert_equal 'spawn', se_config[:worker_type]
649-
assert_equal 1, se_config[:workers]
650-
assert_equal false, se_config[:log_stdin]
651-
assert_equal false, se_config[:log_stdout]
652-
assert_equal false, se_config[:log_stderr]
653-
assert_equal true, se_config[:enable_heartbeat]
654-
assert_equal false, se_config[:auto_heartbeat]
655-
assert_equal "fluentd.conf", se_config[:config_path]
656-
assert_equal true, se_config[:daemonize]
657-
assert_equal './fluentd.pid', se_config[:pid_path]
679+
data("default", [{}, "0"])
680+
data("222", [{chumask: "222"}, "222"])
681+
def test_chumask_should_be_passed_to_ServerEngine((cl_opt, expected_chumask_value))
682+
proxy.mock(Fluent::Supervisor).serverengine_config(hash_including("chumask" => expected_chumask_value))
683+
any_instance_of(ServerEngine::Daemon) { |daemon| mock(daemon).run.once }
684+
685+
supervisor = Fluent::Supervisor.new(cl_opt)
686+
stub(Fluent::Config).build { config_element('ROOT') }
687+
stub(supervisor).build_spawn_command { "dummy command line" }
688+
supervisor.configure(supervisor: true)
689+
690+
supervisor.run_supervisor
658691
end
659692

660693
sub_test_case "init logger" do

0 commit comments

Comments
 (0)