Преглед изворни кода

* Dont let cmd_update be run on non localhubs
* Fixed locahub -P checking for FreeBSD


svn: 423

Bryan Drewery пре 22 година
родитељ
комит
bc104212c6
3 измењених фајлова са 34 додато и 12 уклоњено
  1. 5 1
      src/cmds.c
  2. 24 7
      src/main.c
  3. 5 4
      src/misc.c

+ 5 - 1
src/cmds.c

@@ -25,7 +25,7 @@ extern tcl_timer_t	 *timer, *utimer;
 extern int		 dcc_total, remote_boots, backgrd, 
 			 do_restart, conmask, must_be_owner,
 			 strict_host, quiet_save, cfg_count,
-			 server_lag, egg_numver;
+			 server_lag, egg_numver, localhub;
 
 extern unsigned long	 otraffic_irc, otraffic_irc_today,
 			 itraffic_irc, itraffic_irc_today,
@@ -958,6 +958,10 @@ static void cmd_match(struct userrec *u, int idx, char *par)
 static void cmd_update(struct userrec *u, int idx, char *par)
 {
   putlog(LOG_CMDS, "*", STR("#%s# update %s"), dcc[idx].nick, par);
+#ifdef LEAF
+  if (!localhub)
+    dprintf(idx, STR("Please use this command on the first listed in the conf for this user@box\n"));
+#endif /* LEAF */
   if (!par[0])
     dprintf(idx, STR("Usage: update <binname>\n"));
   updatebin(idx, par, 0);

+ 24 - 7
src/main.c

@@ -593,15 +593,16 @@ void show_help()
 
 
 #ifdef LEAF
-#define PARSE_FLAGS "cedghnstvDEGP"
+#define PARSE_FLAGS "cedghnstvDEGLP"
 #endif /* LEAF */
 #ifdef HUB
 #define PARSE_FLAGS "edghnstvDEG"
 #endif /* HUB */
 #define FLAGS_CHECKPASS "edhgntDEGv"
+char *confdir();
 static void dtx_arg(int argc, char *argv[])
 {
-  int i;
+  int i, localhub_pid = 0;
   char *p = NULL, *p2 = NULL;
   while ((i = getopt(argc, argv, PARSE_FLAGS)) != EOF) {
     if (strchr(FLAGS_CHECKPASS, i))
@@ -691,12 +692,28 @@ static void dtx_arg(int argc, char *argv[])
         break; /* this should never be reached */
       }
 #ifdef LEAF
-      case 'P':
-        if (getppid() != atoi(argv[optind]))
-          exit(0);
-        else {
-          sdprintf(STR("Updating..."));
+      case 'L':
+      {
+        p = argv[optind];
+        if (p && p[0]) {
+          FILE *fp;
+          char buf2[DIRMAX], s[11];
+
+          egg_snprintf(buf2, sizeof buf2, "%s/.../.pid.%s", confdir(), p);
+          if ((fp = fopen(buf2, "r"))) {
+            fgets(s, 10, fp);
+            localhub_pid = atoi(s);
+            fclose(fp);
+            /* printf("LOCALHUB PID: %d\n", localhub_pid); */
+          }
         }
+        break;
+      }
+      case 'P':	
+        if (atoi(argv[optind]) != localhub_pid)
+          exit(1);
+        else
+          sdprintf(STR("Updating..."));
         localhub = 1;
         updating = 1;
         break;

+ 5 - 4
src/misc.c

@@ -1333,6 +1333,7 @@ int updatebin (int idx, char *par, int autoi)
   module_entry *me;
 #endif /* LEAF */
 
+  buf[0] = 0;
   path = newsplit(&par);
   par = path;
   if (!par[0]) {
@@ -1396,7 +1397,7 @@ int updatebin (int idx, char *par, int autoi)
     /* if localhub = 1, this is the spawn bot and controls
      * the spawning of new bots. */
 
-    sprintf(buf, "%s -P %d", buf, getpid());
+     sprintf(buf, "%s -L %s -P %d", buf, botnetnick, getpid());
   } 
 #endif /* LEAF */
 
@@ -1409,16 +1410,16 @@ int updatebin (int idx, char *par, int autoi)
   listen_all(my_port, 1); //close the listening port...
   usleep(5000);
 #endif /* HUB */
+  putlog(LOG_DEBUG, "*", "Running for update: %s", buf);
   if ((i = system(buf))) {
     if (idx)
       dprintf(idx, STR("Couldn't restart new binary (error %d)\n"), i);
-      putlog(LOG_MISC, "*", STR("Couldn't restart new binary (error %d)\n"), i);
+    putlog(LOG_MISC, "*", STR("Couldn't restart new binary (error %d)\n"), i);
     return i;
 
   } else {
-
 #ifdef LEAF
-    if (!autoi && !localhub) {
+    if (!autoi && localhub) {
       /* let's drop the server connection ASAP */
       if ((me = module_find("server", 0, 0))) {
         Function *func = me->funcs;