mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
88e51fb08e
Reduces runtime allocation by freezing string literals by default. We could also remove a ton of manual `.freeze` calls, however the ruby supported version is 2.2 and the magic comment only targets 2.3+.
33 lines
725 B
Ruby
33 lines
725 B
Ruby
# frozen_string_literal: true
|
|
|
|
module Process
|
|
|
|
# This overrides the default version because it is broken if it
|
|
# exists.
|
|
|
|
if respond_to? :daemon
|
|
class << self
|
|
remove_method :daemon
|
|
end
|
|
end
|
|
|
|
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
|