From 353cfacf037c663e38dd034aefc1e7a3fff2be99 Mon Sep 17 00:00:00 2001 From: "terry%netscape.com" Date: Sat, 17 Oct 1998 02:50:48 +0000 Subject: [PATCH] Restart ourselves whenever the source code changes. git-svn-id: svn://10.0.0.236/trunk@13063 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/webtools/mozbot/mozbot.pl | 36 ++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/mozilla/webtools/mozbot/mozbot.pl b/mozilla/webtools/mozbot/mozbot.pl index afba488ec66..81c6b2eaa72 100755 --- a/mozilla/webtools/mozbot/mozbot.pl +++ b/mozilla/webtools/mozbot/mozbot.pl @@ -64,6 +64,8 @@ my %cmds = "url" => "bot_urls", ); +@::origargv = @ARGV; + my $server = shift; my $port = shift; my $nick = shift; @@ -132,6 +134,7 @@ $bot->add_handler ('msg', \&on_msg); $bot->add_handler('public', \&on_public); $bot->schedule (0, \&tinderbox); +$bot->schedule (0, \&checksourcechange); &debug ("connecting to $server $port as $nick on $channel"); $irc->start; @@ -242,9 +245,12 @@ sub on_public } } +$::dontQuitOnSignal = 0; sub on_boot { - die "$0: disconnected from network"; + if (!$::dontQuitOnSignal) { + die "$0: disconnected from network"; + } } ################ @@ -421,3 +427,31 @@ sub tinderbox $bot->schedule (360, \&tinderbox); } + +# See if someone has changed our source. + +$::ourdate = 0; +$::tinderboxdate = 0; + +sub checksourcechange { + my ($self) = @_; + my $lastourdate = $::ourdate; + my $lasttinderboxdate = $::tinderboxdate; + my ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, + $atime,$mtime,$ctime,$blksize,$blocks) + = stat("./mozbot.pl"); + $::ourdate = $mtime; + ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size, + $atime,$mtime,$ctime,$blksize,$blocks) + = stat("./Tinderbox.pm"); + $::tinderboxdate = $mtime; + if ($lastourdate > 0 && ($::ourdate > $lastourdate || + $::tinderboxdate > $lasttinderboxdate)) { + $self->privmsg($channel, "Whoops; someone seems to have changed my source code. Be right back..."); + $::dontQuitOnSignal = 1; + $self->quit(); + &debug ("restarting self"); + exec "$0 @::origargv"; + } + $bot->schedule (60, \&checksourcechange); +}