From af3e5766523110f50cfb5bcdaba82f700d7d7807 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Fri, 21 Feb 2014 22:47:15 +0000 Subject: support "daemonize = 0|1" in the config file This is expected by Perl mogstored, and our previous support of "daemonize" (standalone) was in error (but still supported for now). --- cfg_parser.rl | 19 +++++++++++++++++-- test/cmogstored-cfg.rb | 48 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/cfg_parser.rl b/cfg_parser.rl index 9394ea7..af6419f 100644 --- a/cfg_parser.rl +++ b/cfg_parser.rl @@ -63,7 +63,22 @@ static char *mystrdup(const char *key, char *mark_beg, const char *p) cfg->pidfile = mystrdup("pidfile", mark_beg, fpc); if (!cfg->pidfile) return -1; }; - daemonize = lws* "daemonize" comment* eor > { cfg->daemonize = true; }; + daemonize_compat = lws* "daemonize" comment* eor > { + syslog(LOG_ERR, +"\"daemonize\" in was supported in error in the past and now deprecated"); + syslog(LOG_ERR, +"use \"daemonize = 1\" in your config file instead"); + cfg->daemonize = true; + }; + daemonize = lws* "daemonize" sep + ((any - space)+) > { mark_beg = fpc; } + (comment* eor) > { + mark_len = fpc - mark_beg; + mark_beg[mark_len] = 0; + + /* special case for compatibility with mogstored */ + cfg->daemonize = strcmp("0", mark_beg); + }; maxconns = lws* "maxconns" sep (digit+) > { mark_beg = fpc; } (comment* eor) > { @@ -93,7 +108,7 @@ static char *mystrdup(const char *key, char *mark_beg, const char *p) free(tmp); }; main := (mgmtlisten | httplisten | httpgetlisten | - pidfile | docroot | daemonize | maxconns | + pidfile | docroot | daemonize | daemonize_compat | maxconns | server | serverbin ) + $! { fhold; diff --git a/test/cmogstored-cfg.rb b/test/cmogstored-cfg.rb index 77efd7c..07dfc6a 100644 --- a/test/cmogstored-cfg.rb +++ b/test/cmogstored-cfg.rb @@ -487,7 +487,7 @@ class TestCmogstoredConfig < Test::Unit::TestCase cfg.puts "mgmtlisten = #@host:#@port" cfg.puts "docroot = #@tmpdir" cfg.puts "pidfile = #{basename}" - cfg.puts "daemonize" + cfg.puts "daemonize = 1" cfg.flush @cmd << "--config=#{cfg.path}" tmp = Tempfile.new("err") @@ -504,4 +504,50 @@ class TestCmogstoredConfig < Test::Unit::TestCase assert_match(/pidfile=#{basename} must use an absolute/, lines) assert_match(/relative paths are incompatible with --daemonize/, lines) end + + def test_daemonized_config_has_pidfile + pid = Tempfile.new("pid") + cfg = Tempfile.new("cfg") + cfg.puts "mgmtlisten = #@host:#@port" + cfg.puts "docroot = #@tmpdir" + cfg.puts "pidfile = #{pid.path}" + cfg.puts "daemonize = 1" + cfg.flush + @cmd << "--config=#{cfg.path}" + tmp = Tempfile.new("err") + @pid = fork do + expand_suppressions!(@cmd) + $stderr.reopen(tmp) + exec(*@cmd) + end + _, status = Process.waitpid2(@pid) + assert status.success?, status.inspect + pre_kill + read_pid = File.read(pid.path) + assert_match(%r{\A\d+\n\z}, read_pid) + read_pid = read_pid.to_i + assert_equal 1, Process.kill(0, read_pid) + assert_equal 1, Process.kill(:QUIT, read_pid) + end + + def test_daemonized_0 + pid = Tempfile.new("pid") + cfg = Tempfile.new("cfg") + cfg.puts "mgmtlisten = #@host:#@port" + cfg.puts "docroot = #@tmpdir" + cfg.puts "pidfile = #{pid.path}" + cfg.puts "daemonize = 0" + cfg.flush + @cmd << "--config=#{cfg.path}" + tmp = Tempfile.new("err") + @pid = fork do + expand_suppressions!(@cmd) + $stderr.reopen(tmp) + exec(*@cmd) + end + pre_kill + read_pid = File.read(pid.path) + assert_equal @pid, read_pid.to_i + assert_equal 1, Process.kill(:QUIT, @pid) + end end -- cgit v1.2.3-24-ge0c7