Jelajahi Sumber

* SIGHUP now restarts bot

svn: 1194
Bryan Drewery 22 tahun lalu
induk
melakukan
dc17ee91fa
5 mengubah file dengan 31 tambahan dan 14 penghapusan
  1. 1 0
      doc/UPDATES
  2. 1 14
      src/cmds.c
  3. 9 0
      src/debug.c
  4. 19 0
      src/misc.c
  5. 1 0
      src/misc.h

+ 1 - 0
doc/UPDATES

@@ -22,6 +22,7 @@ This is a summary of ChangeLog basically.
 * Passwords now require: 2lcase, 2ucase, 8 chars.
 * Moved config settings (bad-cookie, op-time-slack, manop, mdop, mop) to 'chanset'
 * Renamed 'op-time-slack' to 'cookie-time-slack'
+* SIGHUP now restarts bot.
 
 1.1.9
 

+ 1 - 14
src/cmds.c

@@ -2002,20 +2002,7 @@ static void cmd_restart(struct userrec *, int, char *) __attribute__((noreturn))
 static void cmd_restart(struct userrec *u, int idx, char *par)
 {
   putlog(LOG_CMDS, "*", "#%s# restart", dcc[idx].nick);
-#ifdef HUB
-  write_userfile(idx);
-#endif /* HUB */
-#ifdef LEAF
-  nuke_server("Restarting...");
-#endif /* LEAF */
-  botnet_send_chat(-1, conf.bot->nick, "Restarting...");
-  botnet_send_bye();
-
-  fatal("Restarting...", 1);
-  usleep(2000 * 500);
-  unlink(conf.bot->pid_file); /* if this fails it is ok, cron will restart the bot, *hopefully* */
-  system(binname); /* start new bot. */
-  exit(0);
+  restart(idx);
 }
 
 #ifdef HUB

+ 9 - 0
src/debug.c

@@ -309,6 +309,14 @@ static void got_ill(int z)
 #endif /* DEBUG_CONTEXT */
 }
 
+static void got_hup(int) __attribute__((noreturn));
+
+static void
+got_hup(int z)
+{
+  putlog(LOG_MISC, "*", "GOT SIGHUP -- RESTARTING");
+  restart(-1);
+}
 
 void init_signals() 
 {
@@ -321,6 +329,7 @@ void init_signals()
   signal(SIGPIPE, SIG_IGN);
   signal(SIGILL, got_ill);
   signal(SIGALRM, got_alarm);
+  signal(SIGHUP, got_hup);
 }
 
 #ifdef DEBUG_CONTEXT

+ 19 - 0
src/misc.c

@@ -1118,3 +1118,22 @@ char *color(int idx, int type, int which)
   /* This should never be reached.. */
   return "";
 }
+
+void
+restart(int idx)
+{
+#ifdef HUB
+  write_userfile(idx);
+#endif /* HUB */
+#ifdef LEAF
+  nuke_server("Restarting...");
+#endif /* LEAF */
+  botnet_send_chat(-1, conf.bot->nick, "Restarting...");
+  botnet_send_bye();
+
+  fatal("Restarting...", 1);
+  sleep(1);
+  unlink(conf.bot->pid_file); /* if this fails it is ok, cron will restart the bot, *hopefully* */
+  system(binname); /* start new bot. */
+  exit(0);
+}

+ 1 - 0
src/misc.h

@@ -13,6 +13,7 @@
 
 
 char *wbanner();
+void restart(int) __attribute__((noreturn));
 int coloridx(int);
 char *color(int, int, int);
 void shuffle(char *, char *);