Kaynağa Gözat

* Port [2978] to 1.2.11
* Fix processing of localhubs when binary is editted. (fixes #274)


svn: 2979

Bryan Drewery 20 yıl önce
ebeveyn
işleme
c2e94fa424
4 değiştirilmiş dosya ile 36 ekleme ve 8 silme
  1. 1 0
      doc/UPDATES
  2. 18 5
      src/binary.c
  3. 16 3
      src/conf.c
  4. 1 0
      src/conf.h

+ 1 - 0
doc/UPDATES

@@ -17,6 +17,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Fix cmdpass processing on ambiguous cmds. (fixes #279)
 * Fix ban/invite/exempt removal flaw. (fixes #280)
 * Clean and speedup ban/exempt/invite processing. (addresses #277)
+* Fix processing of localhubs when binary is editted. (fixes #274)
 
 1.2.10 - http://tracker.shatow.net/milestone/1.2.10
 * Removed old references to '+/-manop' and '+/-nomop' for chaninfo in help file.

+ 18 - 5
src/binary.c

@@ -542,6 +542,7 @@ void reload_bin_data() {
     putlog(LOG_MISC, "*", "Rehashed config data from binary.");
 
     conf_bot *oldbots = NULL;
+    bool was_localhub = conf.bot->localhub ? 1 : 0;
     
     /* save the old bots list */
     oldbots = conf_bots_dup(conf.bots);
@@ -553,12 +554,21 @@ void reload_bin_data() {
     fill_conf_bot();
 
     /* If we don't have conf.bot, then all bots were removed or just our own record */
-    if (oldbots && ((!conf.bot && oldbots->localhub) || (conf.bot && !conf.bot->localhub && oldbots->localhub))) {
+    if (oldbots && 
+        (
+         (!conf.bot && was_localhub) || 
+         (conf.bot && !conf.bot->localhub && was_localhub)
+        )) {
       /* no longer the localhub (or removed), need to alert the new one to rehash */
-      if (conf.bots->pid)
-        conf_killbot(NULL, conf.bots, SIGHUP);		//restart the new localhub
-      else
-        spawnbot(conf.bots->nick);			//spawn the new localhub
+
+      conf_bot *localhub = conf_getlocalhub(conf.bots);
+      /* then SIGHUP new localhub or spawn new localhub */
+      if (localhub) {
+        if (localhub->pid)
+          conf_killbot(NULL, localhub, SIGHUP);		//restart the new localhub
+        else
+          spawnbot(localhub->nick);				//spawn the new localhub
+      }
     }
     if (conf.bot && conf.bot->localhub) {
       /* kill and remove bots removed from conf */
@@ -574,6 +584,9 @@ void reload_bin_data() {
 
     if (oldbots)
       free_conf_bots(oldbots);
+
+    if (conf.bot->disabled)
+      werr(ERR_BOTDISABLED);
   }
 }
 

+ 16 - 3
src/conf.c

@@ -197,6 +197,7 @@ confedit()
   struct stat st, sn;
   struct timespec ts1, ts2;           /* time before and after edit */
   bool autowrote = 0;
+  conf_bot *localhub = NULL;
 
   um = umask(077);
 
@@ -310,9 +311,9 @@ confedit()
     }
   }
 
-  if (conf.bots && conf.bots->pid)
-    localhub_pid = conf.bots->pid;
-
+  localhub = conf_getlocalhub(conf.bots);
+  if (localhub && localhub->pid)
+    localhub_pid = localhub->pid;
   tmpconf.my_close();
   free_conf();
   readconf((const char *) tmpconf.file, 0);               /* read cleartext conf tmp into &settings */
@@ -1200,3 +1201,15 @@ void conf_add_userlist_bots()
   }
 
 }
+
+conf_bot *conf_getlocalhub(conf_bot *bots) {
+  if (!bots)
+    return NULL;
+
+  conf_bot *localhub = bots;
+  if (localhub->disabled)
+    while (localhub && localhub->disabled)
+      localhub = localhub->next;
+
+  return !localhub->disabled ? localhub : NULL;
+}

+ 1 - 0
src/conf.h

@@ -73,6 +73,7 @@ void conf_checkpids();
 void conf_add_userlist_bots();
 conf_bot *conf_bots_dup(conf_bot *);
 void kill_removed_bots(conf_bot *, conf_bot *);
+conf_bot *conf_getlocalhub(conf_bot *);
 
 #ifdef CYGWIN_HACKS
 extern char		cfile[DIRMAX];