Add a class method to Ruby 1.8's Process module to convert the running process into a daemon. This is used during the --poll mode after the IMAP credentials have been confirmed. Ruby 1.9 already defines ::daemon
Convert the current process into a daemon. Uses ideas from
Webrick (/usr/lib/ruby/1.8/webrick/server.rb)
Ruby Cookbook (p.746) Carlson/Richardson
(NOTE: Ruby 1.9 actually has ::daemon method.)
# File buryspam.rb, line 105 def self.daemon exit!(0) if fork # Parent exits, child continues. Process.setsid # Become session leader. exit!(0) if fork # Zap session leader. Dir.chdir "/" # Release old working directory. File.umask 0000 # Ensure sensible umask. Adjust as needed. STDIN.reopen "/dev/null" # Free file descriptors and STDOUT.reopen "/dev/null", "a" # point them somewhere sensible. STDERR.reopen STDOUT # STDOUT/ERR should better go to a logfile. end