about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2009-09-02 21:18:20 -0700
committerEric Wong <normalperson@yhbt.net>2009-09-02 21:18:20 -0700
commite75de4b28b19e9ac79083bba4b55bcb4c93b207d (patch)
treec44fa9f167c655a33df2e7d725ebcacb1565273d
parent7f74a16406c92c4362ac20af4ccb8bc821cf978b (diff)
downloadunicorn-e75de4b28b19e9ac79083bba4b55bcb4c93b207d.tar.gz
Followup to commit 7f74a16406c92c4362ac20af4ccb8bc821cf978b,
we want to ensure error messages do not get swallowed up into
/dev/null when daemonizing; so we defer the default redirects
to "/dev/null" to as late as possible.
-rw-r--r--test/exec/test_exec.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/test/exec/test_exec.rb b/test/exec/test_exec.rb
index cf7ef28..19177fe 100644
--- a/test/exec/test_exec.rb
+++ b/test/exec/test_exec.rb
@@ -604,6 +604,26 @@ end
     reexec_usr2_quit_test(new_pid, pid_file)
   end
 
+  def test_daemonize_redirect_fail
+    pid_file = "#{@tmpdir}/test.pid"
+    log = Tempfile.new('unicorn_test_log')
+    ucfg = Tempfile.new('unicorn_test_config')
+    ucfg.syswrite("pid #{pid_file}\"\n")
+    err = Tempfile.new('stderr')
+    out = Tempfile.new('stdout ')
+
+    File.open("config.ru", "wb") { |fp| fp.syswrite(HI) }
+    pid = xfork do
+      $stderr.reopen(err.path, "a")
+      $stdout.reopen(out.path, "a")
+      exec($unicorn_bin, "-D", "-l#{@addr}:#{@port}", "-c#{ucfg.path}")
+    end
+    pid, status = Process.waitpid2(pid)
+    assert status.success?, "original process exited successfully"
+    sleep 1 # can't waitpid on a daemonized process :<
+    assert err.stat.size > 0
+  end
+
   def test_reexec_fd_leak
     unless RUBY_PLATFORM =~ /linux/ # Solaris may work, too, but I forget...
       warn "FD leak test only works on Linux at the moment"