about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2014-02-21 22:47:15 +0000
committerEric Wong <normalperson@yhbt.net>2014-02-22 00:09:03 +0000
commitaf3e5766523110f50cfb5bcdaba82f700d7d7807 (patch)
tree500f5f244893096d911dce69cd238e6bd9655881
parent35782a1facdc61ae007086657689cf289c96dd92 (diff)
downloadcmogstored-af3e5766523110f50cfb5bcdaba82f700d7d7807.tar.gz
This is expected by Perl mogstored, and our previous support
of "daemonize" (standalone) was in error (but still supported
for now).
-rw-r--r--cfg_parser.rl19
-rw-r--r--test/cmogstored-cfg.rb48
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