summaryrefslogtreecommitdiff
path: root/lib/rbot
diff options
context:
space:
mode:
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>2021-06-04 16:46:59 +0200
committerMatthias Hecker <36882671+mattzque@users.noreply.github.com>2021-06-05 18:06:45 +0200
commite01699c5284bdb45f88ee6335dc90f25f4932b66 (patch)
tree4b4488d22c2f4b497e5cf5255fbf304cda466337 /lib/rbot
parent8a458c02a29b1d7c41b9420eabc90ba40bbe960a (diff)
bot: reorder fork sequence
We do the actual fork as the last step, after redirecting the standard I/O streams. This also ensures that no log messages are shown on console _after_ forking.
Diffstat (limited to 'lib/rbot')
-rw-r--r--lib/rbot/ircbot.rb38
1 files changed, 17 insertions, 21 deletions
diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb
index 564403f5..058e7bbe 100644
--- a/lib/rbot/ircbot.rb
+++ b/lib/rbot/ircbot.rb
@@ -403,26 +403,6 @@ class Bot
debug "Using `#{@logfile}' as debug log"
end
- LoggerManager.instance.flush
-
- # See http://blog.humlab.umu.se/samuel/archives/000107.html
- # for the backgrounding code
- if $daemonize
- begin
- exit if fork
- Process.setsid
- exit if fork
- rescue NotImplementedError
- warning "Could not background, fork not supported"
- rescue SystemExit
- exit 0
- rescue Exception => e
- warning "Could not background. #{e.pretty_inspect}"
- end
- Dir.chdir botclass
- # File.umask 0000 # Ensure sensible umask. Adjust as needed.
- end
-
# setup logger based on bot configuration, if not set from the command line
loglevel_set = $opts.has_key?('debug') or $opts.has_key?('loglevel')
LoggerManager.instance.set_level(@config['log.level']) unless loglevel_set
@@ -459,9 +439,25 @@ class Bot
return str.bytesize
end
- LoggerManager.instance.log_session_start
+ # See http://blog.humlab.umu.se/samuel/archives/000107.html
+ # for the backgrounding code
+ begin
+ exit if fork
+ Process.setsid
+ exit if fork
+ rescue NotImplementedError
+ warning "Could not background, fork not supported"
+ rescue SystemExit
+ exit 0
+ rescue Exception => e
+ warning "Could not background. #{e.pretty_inspect}"
+ end
+ Dir.chdir botclass
+ # File.umask 0000 # Ensure sensible umask. Adjust as needed.
end
+ LoggerManager.instance.log_session_start
+
File.open($opts['pidfile'] || File.join(@botclass, 'rbot.pid'), 'w') do |pf|
pf << "#{$$}\n"
end