about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2013-02-07 22:02:41 +0000
committerEric Wong <normalperson@yhbt.net>2013-02-07 22:02:41 +0000
commit117a11e9e2b8a365df90336ae78b61f6562b7bd3 (patch)
treef32a442756da00edc05f9a2c17e19743ae519d40
parent4f45f562180489a97a4572ebd3822e9f15289bd6 (diff)
downloadcmogstored-117a11e9e2b8a365df90336ae78b61f6562b7bd3.tar.gz
Trailing ':' in PATH means using the current path, which
is now incompatible with daemonize.
-rw-r--r--cfg.c6
-rw-r--r--test/cmogstored-cfg.rb18
2 files changed, 21 insertions, 3 deletions
diff --git a/cfg.c b/cfg.c
index 2b3430f..a21aac2 100644
--- a/cfg.c
+++ b/cfg.c
@@ -128,6 +128,11 @@ static void validate_daemonize(struct mog_cfg *cli)
                 mog_cfg_validate_daemon(cli, &nerr);
 
         p = path;
+
+        /* trailing ':' in PATH is identical to trailing ":." (cwd) */
+        if (p[strlen(p) - 1] == ':')
+                goto err;
+
         while (*p) {
                 if (*p == '/') {
                         p = strchr(p, ':');
@@ -136,6 +141,7 @@ static void validate_daemonize(struct mog_cfg *cli)
                         p++;
                         continue;
                 }
+err:
                 warn("PATH environment contains relative path: %s", p);
                 nerr++;
                 break;
diff --git a/test/cmogstored-cfg.rb b/test/cmogstored-cfg.rb
index 8086ac3..77efd7c 100644
--- a/test/cmogstored-cfg.rb
+++ b/test/cmogstored-cfg.rb
@@ -407,24 +407,36 @@ class TestCmogstoredConfig < Test::Unit::TestCase
     end
   end
 
-  def test_PATH_env_has_relpath
+  def PATH_env_has_relpath(badpath)
     @cmd << "--docroot=#@tmpdir"
     @cmd << "--daemonize"
     @cmd << "--mgmtlisten=#@host:#@port"
     tmp = Tempfile.new("err")
     @pid = fork do
-      ENV["PATH"] = "#{ENV["PATH"]}:."
+      ENV["PATH"] = badpath
       $stderr.reopen(tmp)
       exec(*@cmd)
     end
     _, status = Process.waitpid2(@pid)
-    assert ! status.success?, status.inspect
+    assert ! status.success?, "#{status.inspect} badpath=#{badpath.inspect}"
     tmp.rewind
     lines = tmp.read
     assert_match(/PATH environment contains relative path/, lines)
     assert_match(/relative paths are incompatible with --daemonize/, lines)
   end
 
+  def test_PATH_env_has_relpath
+    [
+      "#{ENV["PATH"]}::#{ENV["PATH"]}",
+      "#{ENV["PATH"]}:",
+      "#{ENV["PATH"]}:.",
+      ".:#{ENV["PATH"]}",
+      ":#{ENV["PATH"]}"
+    ].each do |badpath|
+      PATH_env_has_relpath(badpath)
+    end
+  end
+
   def test_docroot_has_relpath
     @cmd << "--daemonize"
     @cmd << "--mgmtlisten=#@host:#@port"