1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/lib/puma/daemon_ext.rb
Evan Phoenix 399c166516 Keep STDOUT/STDERR the right mode. Fixes #422
If you reopen STDOUT with an IO object that is "w+", then later reopen
it again as just "w", you get an exception:

`reopen': /dev/null can't change access mode from "w+" to "w" (ArgumentError)
2013-12-05 09:51:39 -08:00

25 lines
608 B
Ruby

module Process
# This overrides the default version because it is broken if it
# exists.
def self.daemon(nochdir=false, noclose=false)
exit if fork # Parent exits, child continues.
Process.setsid # Become session leader.
exit if fork # Zap session leader. See [1].
Dir.chdir "/" unless nochdir # Release old working directory.
if !noclose
STDIN.reopen File.open("/dev/null", "r")
null_out = File.open "/dev/null", "w"
STDOUT.reopen null_out
STDERR.reopen null_out
end
0
end
end