From: Tom Gilbert Date: Wed, 7 Sep 2005 19:16:34 +0000 (+0000) Subject: win32 thing for signal handling X-Git-Url: https://git.netwichtig.de/gitweb/?a=commitdiff_plain;h=42fd60e6a81e592553cdc6bb3b6011386692dde2;p=user%2Fhenk%2Fcode%2Fruby%2Frbot.git win32 thing for signal handling fix quit! :p --- diff --git a/lib/rbot/ircbot.rb b/lib/rbot/ircbot.rb index 2443ec95..91afd94e 100644 --- a/lib/rbot/ircbot.rb +++ b/lib/rbot/ircbot.rb @@ -316,7 +316,7 @@ class IrcBot end begin @socket.connect - rescue => e + rescue => e raise "failed to connect to IRC server at #{@config['server.name']} #{@config['server.port']}: " + e end @socket.puts "PASS " + @config['server.password'] if @config['server.password'] @@ -341,8 +341,10 @@ class IrcBot # exceptions that ARENT SocketError's. How am I supposed to handle # that? #rescue TimeoutError, SocketError => e + rescue SystemExit + exit 0 rescue Exception => e - puts "network exception: connection closed: #{e}" + puts "network exception: connection closed: #{e.inspect}" puts e.backtrace.join("\n") @socket.shutdown # now we reconnect rescue => e @@ -451,9 +453,13 @@ class IrcBot # disconnect from the server and cleanup all plugins and modules def shutdown(message = nil) - trap("SIGTERM", "DEFAULT") - trap("SIGHUP", "DEFAULT") - trap("SIGINT", "DEFAULT") + begin + trap("SIGTERM", "DEFAULT") + trap("SIGHUP", "DEFAULT") + trap("SIGINT", "DEFAULT") + rescue + debug "failed to trap signals, probably running on windows?" + end message = @lang.get("quit") if (message.nil? || message.empty?) @socket.clearq save @@ -461,18 +467,21 @@ class IrcBot @channels.each_value {|v| log "@ quit (#{message})", v.name } + @registry.close @socket.puts "QUIT :#{message}" @socket.flush @socket.shutdown - @registry.close puts "rbot quit (#{message})" end # message:: optional IRC quit message # quit IRC, shutdown the bot def quit(message=nil) - shutdown(message) - exit 0 + begin + shutdown(message) + ensure + exit 0 + end end # totally shutdown and respawn the bot