Просмотр исходного кода

* Detection system run by localhub will kill all other running bots on shell with DIE/SUICIDE now.

svn: 2044
Bryan Drewery 21 лет назад
Родитель
Сommit
7a2f224078
5 измененных файлов с 33 добавлено и 16 удалено
  1. 1 0
      doc/UPDATES
  2. 17 9
      src/conf.c
  3. 1 1
      src/conf.h
  4. 2 2
      src/main.c
  5. 12 4
      src/shell.c

+ 1 - 0
doc/UPDATES

@@ -97,6 +97,7 @@ Lines prefixxed with '-' were disabled before release and are not finishsed, or
 * Fixed cmd_mns_(ban|exempt|invite) to remove the proper ban if a number is used (#38)
 * Fixed cmd_stick/cmd_unstick not making leaf bots set/unset the masks in channels. (#41)
 * Use /tmp/ as the default tempdir until tempdir is read from config
+* Detection system run by localhub will kill all other running bots with DIE/SUICIDE now.
 
 1.2.2
 * Don't sanity check flags for users on DCC CHAT if they are on the bot via .botcmd.

+ 17 - 9
src/conf.c

@@ -129,17 +129,25 @@ spawnbots()
 }
 
 int
-killbot(char *botnick, conf_bot *bot, int signal)
+conf_killbot(const char *botnick, conf_bot *bot, int signal)
 {
-  if (!bot) {
-    for (bot = conf.bots; bot && bot->nick; bot = bot->next)
-      if (!egg_strcasecmp(botnick, bot->nick))
-        break;
-  }
-  if (bot)
+  int return = -1;
+
+  if (bot) {
     if (bot->pid)
-      return kill(bot->pid, signal);
-  return -1;
+      ret = kill(bot->pid, signal);
+  } else {
+    for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
+      /* kill all bots but myself if botnick==NULL, otherwise just kill botnick */
+      if ((!botnick && egg_strcasecmp(conf.bot->nick, bot->nick)) || !egg_strcasecmp(botnick, bot->nick)) {
+        if (bot->pid)
+          ret = kill(bot->pid, signal);
+
+        if (botnick)
+          break;
+    }
+  }
+  return ret;
 }
 
 #ifndef CYGWIN_HACKS

+ 1 - 1
src/conf.h

@@ -55,7 +55,7 @@ enum {
 
 void spawnbot(const char *);
 void spawnbots();
-int killbot(char *, conf_bot *, int);
+int conf_killbot(const char *, conf_bot *, int);
 void confedit() __attribute__((noreturn));
 void conf_addbot(char *, char *, char *, char *);
 int conf_delbot(char *);

+ 2 - 2
src/main.c

@@ -418,7 +418,7 @@ void core_10secondly()
   if (curcheck == 1)
     check_trace(0);
 
-  if (!conf.bot->hub && conf.bot->localhub) {
+  if (conf.bot->hub || conf.bot->localhub) {
     check_promisc();
 
     if (curcheck == 2)
@@ -580,7 +580,7 @@ static void startup_checks(int hack) {
     if (do_killbot[0]) {
       const char *what = (kill_sig == SIGKILL ? "kill" : "restart");
 
-      if (killbot(do_killbot, NULL, kill_sig) == 0)
+      if (conf_killbot(do_killbot, NULL, kill_sig) == 0)
         printf("'%s' successfully %sed.\n", do_killbot, what);
       else {
         printf("Error %sing '%s'\n", what, do_killbot);

+ 12 - 4
src/shell.c

@@ -550,8 +550,8 @@ void detected(int code, char *msg)
   char *p = NULL, tmp[512] = "";
   struct userrec *u = NULL;
   struct flag_record fr = { FR_GLOBAL, 0, 0, 0 };
-  int act;
-
+  int act, do_fatal = 0, killbots = 0;
+  
   u = get_user_by_handle(userlist, conf.bot->nick);
   if (code == DETECT_LOGIN)
     p = (char *) (CFG_LOGIN.ldata ? CFG_LOGIN.ldata : (CFG_LOGIN.gdata ? CFG_LOGIN.gdata : NULL));
@@ -599,7 +599,8 @@ void detected(int code, char *msg)
     if (!conf.bot->hub)
       nuke_server("BBL");
     sleep(1);
-    fatal(msg, 0);
+    killbots++;
+    do_fatal++;
     break;
   case DET_SUICIDE:
     putlog(LOG_WARN, "*", "Comitting suicide: %s", msg);
@@ -614,9 +615,16 @@ void detected(int code, char *msg)
       unlink(tmp);
     }
     unlink(binname);
-    fatal(msg, 0);
+    killbots++;
+    do_fatal++;
     break;
   }
+  if (killbots && conf.bot->localhub) {
+    conf_checkpids();
+    conf_killbot(NULL, NULL, SIGKILL);
+  }
+  if (do_fatal)
+    fatal(msg, 0);
 }
 
 char *werr_tostr(int errnum)