浏览代码

* Port [3222] to 1.2.14
* Fix 'cmd_conf change' to delete old bot first
* Fix cmd_conf to act like confedit() and then simulate a SIGUSR1



svn: 3223

Bryan Drewery 19 年之前
父节点
当前提交
f7184be603
共有 3 个文件被更改,包括 35 次插入14 次删除
  1. 18 5
      src/cmds.c
  2. 15 7
      src/conf.c
  3. 2 2
      src/conf.h

+ 18 - 5
src/cmds.c

@@ -47,6 +47,7 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <sys/types.h>
 #include <sys/types.h>
 #include <sys/utsname.h>
 #include <sys/utsname.h>
+#include <signal.h>
 
 
 extern egg_traffic_t 	traffic;
 extern egg_traffic_t 	traffic;
 
 
@@ -1641,6 +1642,9 @@ static void cmd_conf(int idx, char *par)
     if (par[0])
     if (par[0])
       ipsix = newsplit(&par);
       ipsix = newsplit(&par);
 
 
+    if (cmd[0] == 'c' || cmd[0] == 'C')
+      conf_delbot(nick, 0);
+
     conf_addbot(nick, ip, host, ipsix);
     conf_addbot(nick, ip, host, ipsix);
     if (cmd[0] == 'a' || cmd[0] == 'A')
     if (cmd[0] == 'a' || cmd[0] == 'A')
       dprintf(idx, "Added bot: %s\n", nick);
       dprintf(idx, "Added bot: %s\n", nick);
@@ -1775,14 +1779,23 @@ static void cmd_conf(int idx, char *par)
     /* rewrite our binary */
     /* rewrite our binary */
     conf_to_bin(&conf, 0, -1);
     conf_to_bin(&conf, 0, -1);
 
 
-//    kill_removed_bots(oldlist, conf.bots);
-    conf_add_userlist_bots();
+    /* Now signal all of the old bots with SIGUSR1
+     * They will auto die and determine new localhub, etc..
+     */
+    conf_checkpids(oldlist);
+    conf_killbot(oldlist, conf.bot->nick, NULL, SIGUSR1, 1); /* Don't kill me. */
+
+    /* Now spawn new bots */
     conf_checkpids(conf.bots);
     conf_checkpids(conf.bots);
-    spawnbots(conf.bots, 1);
+    spawnbots(conf.bots, 1); /* Not me. */
     conf_checkpids(conf.bots, 0);
     conf_checkpids(conf.bots, 0);
-  }
 
 
-  free_conf_bots(oldlist);
+    /* So reload_bin_data can process correctly */
+    conf.bots = oldlist;
+
+    do_restart = 2; /* SIGUSR1 -- reload_bin_data(); */
+  } else
+    free_conf_bots(oldlist);
 }
 }
 
 
 static void cmd_encrypt(int idx, char *par)
 static void cmd_encrypt(int idx, char *par)

+ 15 - 7
src/conf.c

@@ -135,7 +135,7 @@ spawnbots(conf_bot *bots, bool rehashed)
 }
 }
 
 
 int
 int
-conf_killbot(conf_bot *bots, const char *botnick, conf_bot *bot, int signal)
+conf_killbot(conf_bot *bots, const char *botnick, conf_bot *bot, int signal, bool notbotnick)
 {
 {
   int ret = -1;
   int ret = -1;
 
 
@@ -146,12 +146,18 @@ conf_killbot(conf_bot *bots, const char *botnick, conf_bot *bot, int signal)
     for (bot = bots; bot && bot->nick; bot = bot->next) {
     for (bot = bots; bot && bot->nick; bot = bot->next) {
       /* kill all bots but myself if botnick==NULL, otherwise just kill botnick */
       /* kill all bots but myself if botnick==NULL, otherwise just kill botnick */
       if ((!conf.bot) || 
       if ((!conf.bot) || 
-          (!botnick && (conf.bot->nick && egg_strcasecmp(conf.bot->nick, bot->nick))) || 
-          (botnick && !egg_strcasecmp(botnick, bot->nick))) {
+          (!botnick && 
+             (conf.bot->nick && egg_strcasecmp(conf.bot->nick, bot->nick))) || 
+          (botnick && 
+             ((notbotnick == 0 && !egg_strcasecmp(botnick, bot->nick)) || 
+              (notbotnick == 1 && egg_strcasecmp(botnick, bot->nick))
+             )  
+          ) 
+         ) {
         if (bot->pid)
         if (bot->pid)
           ret = kill(bot->pid, signal);
           ret = kill(bot->pid, signal);
 
 
-        if (botnick)
+        if (botnick && !notbotnick)
           break;
           break;
       }
       }
     }
     }
@@ -610,14 +616,16 @@ free_bot(conf_bot *bot)
 }
 }
 
 
 int
 int
-conf_delbot(char *botn)
+conf_delbot(char *botn, bool kill)
 {
 {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
 
 
   for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
   for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
     if (!egg_strcasecmp(bot->nick, botn)) {     /* found it! */
     if (!egg_strcasecmp(bot->nick, botn)) {     /* found it! */
-      bot->pid = checkpid(bot->nick, bot, NULL);
-      conf_killbot(conf.bots, NULL, bot, SIGKILL);
+      if (kill) {
+        bot->pid = checkpid(bot->nick, bot, NULL);
+        conf_killbot(conf.bots, NULL, bot, SIGKILL);
+      }
       free_bot(bot);
       free_bot(bot);
       return 0;
       return 0;
     }
     }

+ 2 - 2
src/conf.h

@@ -57,10 +57,10 @@ enum {
 
 
 void spawnbot(const char *);
 void spawnbot(const char *);
 void spawnbots(conf_bot *bots, bool rehashed = 0);
 void spawnbots(conf_bot *bots, bool rehashed = 0);
-int conf_killbot(conf_bot *, const char *, conf_bot *, int);
+int conf_killbot(conf_bot *, const char *, conf_bot *, int, bool = 0);
 void confedit() __attribute__((noreturn));
 void confedit() __attribute__((noreturn));
 void conf_addbot(char *, char *, char *, char *);
 void conf_addbot(char *, char *, char *, char *);
-int conf_delbot(char *);
+int conf_delbot(char *, bool kill = 1);
 pid_t checkpid(const char *, conf_bot *, const char *);
 pid_t checkpid(const char *, conf_bot *, const char *);
 void init_conf();
 void init_conf();
 void free_conf();
 void free_conf();