module Process

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

Public Class Methods

daemon() click to toggle source

Convert the current process into a daemon. Uses ideas from

(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