瀏覽代碼

* Finished up code for updating bots with new conf system

svn: 728
Bryan Drewery 22 年之前
父節點
當前提交
b1a5846a3f
共有 3 個文件被更改,包括 16 次插入26 次删除
  1. 9 3
      src/conf.c
  2. 2 11
      src/main.c
  3. 5 12
      src/misc.c

+ 9 - 3
src/conf.c

@@ -25,7 +25,7 @@
 
 extern char             origbotname[], tempdir[],
                         userfile[], natip[], *binname;
-extern int              localhub;
+extern int              localhub, updating;
 extern uid_t		myuid;
 extern conf_t           conf;
 
@@ -42,12 +42,18 @@ void spawnbots() {
       /* kill it if running */
       if (bot->pid) kill(bot->pid, SIGKILL);
       else continue;
-    } else if (!strcmp(bot->nick, conf.bot->nick) || bot->pid) {
+    } else if (!strcmp(bot->nick, conf.bot->nick) || (bot->pid && !updating)) {
       continue;
     } else {
       char *run = NULL;
       size_t size = 0;
-  
+
+      if (updating && bot->pid) {
+        kill(bot->pid, SIGKILL);
+        /* remove the pid incase we start the new bot before the old dies */
+        unlink(bot->pid_file);		
+      }
+
       size = strlen(bot->nick) + strlen(binname) + 20;
       run = calloc(1, size);
       egg_snprintf(run, size, "%s -B %s", binname, bot->nick);

+ 2 - 11
src/main.c

@@ -347,16 +347,7 @@ static void dtx_arg(int argc, char *argv[])
 #ifdef LEAF
       case 'L':
       {
-        FILE *fp = NULL;
-        char buf2[DIRMAX] = "", s[11] = "";
-
-        egg_snprintf(buf2, sizeof buf2, "%s/.../.pid.%s", confdir(), optarg);
-        if ((fp = fopen(buf2, "r"))) {
-          fgets(s, 10, fp);
-          localhub_pid = atoi(s);
-          fclose(fp);
-          /* printf("LOCALHUB PID: %d\n", localhub_pid); */
-        }
+        localhub_pid = checkpid(optarg, NULL);
         break;
       }
       case 'P':
@@ -730,7 +721,7 @@ int main(int argc, char **argv)
       exit(0);
     } else {
       spawnbots();
-      if (updating) exit(0); /* just let cron restart us bleh */
+      if (updating) exit(0); /* just let the timer restart us (our parent) */
     }
   }
 #endif /* LEAF */

+ 5 - 12
src/misc.c

@@ -809,20 +809,10 @@ int updatebin(int idx, char *par, int autoi)
     return 1;
   }
 
-  sprintf(buf, "%s", binname);
-#ifdef LEAF
-  if (localhub) {
-    /* if localhub = 1, this is the spawn bot and controls
-     * the spawning of new bots. */
-     sprintf(buf, "%s -L %s -P %d", buf, conf.bot->nick, getpid());
-  } 
-#endif /* LEAF */
+  egg_snprintf(buf, sizeof buf, "%s", binname);
 
   /* safe to run new binary.. */
-#ifdef LEAF
-  if (!autoi && !localhub) /* dont delete pid for auto update!!! */
-#endif /* LEAF */
-    unlink(conf.bot->pid_file); /* delete pid so new binary doesnt exit. */
+
 #ifdef HUB
   listen_all(my_port, 1); /* close the listening port... */
   usleep(5000);
@@ -843,10 +833,13 @@ int updatebin(int idx, char *par, int autoi)
     botnet_send_bye();
     fatal("Updating...", 1);
     usleep(2000 * 500);
+    unlink(conf.bot->pid_file); /* delete pid so new binary doesnt exit. */
     system(buf);		/* run the binary, it SHOULD work from earlier tests.. */
     exit(0);
 #ifdef LEAF
   } else if (localhub && autoi) {
+    egg_snprintf(buf, sizeof buf, "%s -L %s -P %d", binname, conf.bot->nick, getpid());	
+    /* will exit after run, cron will restart us later */
     system(buf);
     add_hook(HOOK_SECONDLY, (Function) updatelocal);
     return 0;