瀏覽代碼

* Fixed bots not updating/restarting correctly (being killed before finishing process of restart/update)

svn: 1733
Bryan Drewery 21 年之前
父節點
當前提交
9ebcdaed6b
共有 7 個文件被更改,包括 40 次插入18 次删除
  1. 2 1
      doc/UPDATES
  2. 2 1
      src/binary.c
  3. 1 1
      src/cmds.c
  4. 12 2
      src/conf.c
  5. 10 5
      src/main.c
  6. 5 0
      src/main.h
  7. 8 8
      src/misc.c

+ 2 - 1
doc/UPDATES

@@ -61,7 +61,8 @@ Lines prefixxed with '-' were disabled before release and are not finishsed.
 * Added a (temporarily) static auto-op delay of 6 seconds.
 * Added a (temporarily) static auto-op delay of 6 seconds.
 * Added primitive CIDR ban support (enforcebans/kickban/getop).
 * Added primitive CIDR ban support (enforcebans/kickban/getop).
 * Fixed cookie/manop protections to kick all opped nicks.
 * Fixed cookie/manop protections to kick all opped nicks.
-* Internal userlist adding misc bug fixes.
+* Misc bug fixes/improvements to internal userlist adding (perm owners/hubs).
+* Fixed bots not updating/restarting correctly (being killed before finishing process of restart/update)
 
 
 1.2
 1.2
 * No longer displaying SALTS on ./bin -v
 * No longer displaying SALTS on ./bin -v

+ 2 - 1
src/binary.c

@@ -334,7 +334,8 @@ void write_settings(const char *fname, int die)
   MD5_Init(&ctx);
   MD5_Init(&ctx);
   if ((hash = bin_checksum(fname, WRITE_CHECKSUM, &ctx))) {
   if ((hash = bin_checksum(fname, WRITE_CHECKSUM, &ctx))) {
     printf("* Wrote settings to: %s.\n", fname);
     printf("* Wrote settings to: %s.\n", fname);
-    edpack(&settings, hash, PACK_DEC);
+    if (die == -1)			/* only bother decrypting if we aren't about to exit */
+      edpack(&settings, hash, PACK_DEC);
   }
   }
 
 
   if (die >= 0)
   if (die >= 0)

+ 1 - 1
src/cmds.c

@@ -910,7 +910,7 @@ static void cmd_update(int idx, char *par)
 #endif /* LEAF */
 #endif /* LEAF */
   if (!par[0])
   if (!par[0])
     dprintf(idx, "Usage: update <binname>\n");
     dprintf(idx, "Usage: update <binname>\n");
-  updatebin(idx, par, 20);
+  updatebin(idx, par, 1);
 }
 }
 
 
 static void cmd_uptime(int idx, char *par)
 static void cmd_uptime(int idx, char *par)

+ 12 - 2
src/conf.c

@@ -69,26 +69,36 @@ tellconf(conf_t * inconf)
 }
 }
 
 
 #ifdef LEAF
 #ifdef LEAF
+/* spawn and kill bots accordingly
+ * bots prefixxed with '/' will be killed auto if running.
+ * if (updating) then we were called with -L and -P, we need to restart all running bots except our parent and localhub */
 void
 void
 spawnbots()
 spawnbots()
 {
 {
   conf_bot *bot = NULL;
   conf_bot *bot = NULL;
 
 
   for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
   for (bot = conffile.bots; bot && bot->nick; bot = bot->next) {
+    sdprintf("checking bot: %s", bot->nick);
     if (bot->nick[0] == '/') {
     if (bot->nick[0] == '/') {
       /* kill it if running */
       /* kill it if running */
       if (bot->pid)
       if (bot->pid)
         kill(bot->pid, SIGKILL);
         kill(bot->pid, SIGKILL);
       else
       else
         continue;
         continue;
-    } else if (bot->pid && !updating) {
+    /* if we're updating automatically, we were called with -L -P, and are only supposed to kill non-localhubs
+      -if updating and we find our nick, skip
+      -if pid exists and not updating, bot is running and we have nothing more to do, skip.
+     */
+    } else if ((!strcmp(bot->nick, conf.bot->nick) && updating == UPDATE_AUTO) || (bot->pid && !updating)) {
+      sdprintf(" ... skipping. Updating: %d, pid: %d", updating, bot->pid);
       continue;
       continue;
     } else {
     } else {
       int status = 0;
       int status = 0;
       char *run = NULL;
       char *run = NULL;
       size_t size = 0;
       size_t size = 0;
 
 
-      if (updating && bot->pid) {
+      /* if we are updating with -L -P, then we need to restart ALL bots */
+      if (updating == UPDATE_AUTO && bot->pid) {
         kill(bot->pid, SIGKILL);
         kill(bot->pid, SIGKILL);
         /* remove the pid incase we start the new bot before the old dies */
         /* remove the pid incase we start the new bot before the old dies */
         unlink(bot->pid_file);
         unlink(bot->pid_file);

+ 10 - 5
src/main.c

@@ -355,7 +355,10 @@ static void dtx_arg(int argc, char *argv[])
       case 'U':
       case 'U':
         if (optarg) {
         if (optarg) {
           update_bin = strdup(optarg);
           update_bin = strdup(optarg);
-          updating = (i == 'u' ? 1 : 2);	/* use 2 if 'U' to not kill/spawn bots. */
+          if (i == 'u')
+            updating = UPDATE_AUTO;
+          else
+            updating = UPDATE_EXIT;
           break;
           break;
         } else
         } else
           exit(0);
           exit(0);
@@ -384,7 +387,7 @@ static void dtx_arg(int argc, char *argv[])
         else
         else
           sdprintf("Updating...");
           sdprintf("Updating...");
         localhub = 1;
         localhub = 1;
-        updating = 1;
+        updating = UPDATE_AUTO;
         break;
         break;
 #endif
 #endif
       case '?':
       case '?':
@@ -614,21 +617,23 @@ static void startup_checks(int hack) {
   if (localhub && !used_B) {
   if (localhub && !used_B) {
     if (do_killbot[0]) {
     if (do_killbot[0]) {
       if (killbot(do_killbot) == 0)
       if (killbot(do_killbot) == 0)
-          printf("'%s' successfully killed.\n", do_killbot);
+        printf("'%s' successfully killed.\n", do_killbot);
       else
       else
         printf("Error killing '%s'\n", do_killbot);
         printf("Error killing '%s'\n", do_killbot);
       exit(0);
       exit(0);
     } else {
     } else {
 #endif /* LEAF */
 #endif /* LEAF */
       /* this needs to be both hub/leaf */
       /* this needs to be both hub/leaf */
-      if (update_bin)	{			/* invoked with -u bin */
-        if (updating != 2 && conf.bot->pid) {
+      if (update_bin) {					/* invokved with -u/-U */
+        if (updating == UPDATE_AUTO && conf.bot->pid) {		/* invoked with -u bin, so kill  */
+          
           kill(conf.bot->pid, SIGKILL);
           kill(conf.bot->pid, SIGKILL);
           unlink(conf.bot->pid_file);
           unlink(conf.bot->pid_file);
           writepid(conf.bot->pid_file, getpid());
           writepid(conf.bot->pid_file, getpid());
         }
         }
         updatebin(DP_STDOUT, update_bin, 1);	/* will call restart all bots */
         updatebin(DP_STDOUT, update_bin, 1);	/* will call restart all bots */
         /* never reached */
         /* never reached */
+        exit(0);
       }
       }
 #ifdef LEAF
 #ifdef LEAF
       spawnbots();
       spawnbots();

+ 5 - 0
src/main.h

@@ -3,6 +3,11 @@
 
 
 #include <sys/types.h>
 #include <sys/types.h>
 
 
+enum {
+  UPDATE_AUTO = 1,
+  UPDATE_EXIT
+};
+
 extern int		role, default_flags, default_uflags,
 extern int		role, default_flags, default_uflags,
 			updating;
 			updating;
 extern bool		use_stderr, backgrd, localhub, term_z, loading;
 extern bool		use_stderr, backgrd, localhub, term_z, loading;

+ 8 - 8
src/misc.c

@@ -619,7 +619,8 @@ restart(int idx)
 {
 {
   char buf[1024] = "";
   char buf[1024] = "";
   const char *reason = updating ? "Updating..." : "Restarting...";
   const char *reason = updating ? "Updating..." : "Restarting...";
- 
+
+  sdprintf("restarting [%s]", reason); 
 #ifdef HUB
 #ifdef HUB
   write_userfile(idx);
   write_userfile(idx);
 #endif /* HUB */
 #endif /* HUB */
@@ -723,26 +724,24 @@ int updatebin(int idx, char *par, int secs)
     free(path);
     free(path);
     return 1;
     return 1;
   }
   }
-  if (updating == 2)
-    printf("* Moved binary to: %s\n", binname);
 
 
-  /* safe to run new binary.. */
-  
-  if (updating == 2) /* dont restart/kill/spawn bots, just die ! */
+  if (updating == UPDATE_EXIT) {	  /* dont restart/kill/spawn bots, just die ! */
+    printf("* Moved binary to: %s\n", binname);
     fatal("Binary updated.", 0);
     fatal("Binary updated.", 0);
+  }
 
 
 #ifdef LEAF
 #ifdef LEAF
   if (secs > 0) {
   if (secs > 0) {
     char buf[DIRMAX] = "";
     char buf[DIRMAX] = "";
 
 
-    /* will exit after run, cron will restart us later */
+    /* this forces all running bots to be restarted (except localhub/me) */
     egg_snprintf(buf, sizeof buf, "%s -L %s -P %d", binname, conf.bot->nick, getpid());
     egg_snprintf(buf, sizeof buf, "%s -L %s -P %d", binname, conf.bot->nick, getpid());
     putlog(LOG_DEBUG, "*", "Running for update: %s", buf);
     putlog(LOG_DEBUG, "*", "Running for update: %s", buf);
     system(buf);	/* restarts other bots running, removes pid files */
     system(buf);	/* restarts other bots running, removes pid files */
     
     
     /* this odd statement makes it so specifying 1 sec will restart other bots running
     /* this odd statement makes it so specifying 1 sec will restart other bots running
      * and then just restart with no delay */
      * and then just restart with no delay */
-    updating = 1;
+    updating = UPDATE_AUTO;
     if (secs > 1) {
     if (secs > 1) {
       egg_timeval_t howlong;
       egg_timeval_t howlong;
       howlong.sec = secs;
       howlong.sec = secs;
@@ -750,6 +749,7 @@ int updatebin(int idx, char *par, int secs)
       timer_create_complex(&howlong, "restarting for update", (Function) restart, (void *) idx, 0);
       timer_create_complex(&howlong, "restarting for update", (Function) restart, (void *) idx, 0);
     } else
     } else
       restart(idx);
       restart(idx);
+
     return 0;
     return 0;
   } else
   } else
 #endif /* LEAF */
 #endif /* LEAF */