Просмотр исходного кода

* After changing conf with -C, binary is now moved to binpath/binname.

svn: 1392
Bryan Drewery 21 лет назад
Родитель
Сommit
52289087b8
6 измененных файлов с 84 добавлено и 57 удалено
  1. 1 0
      doc/UPDATES
  2. 4 2
      src/binary.c
  3. 2 10
      src/conf.c
  4. 5 45
      src/main.c
  5. 68 0
      src/shell.c
  6. 4 0
      src/shell.h

+ 1 - 0
doc/UPDATES

@@ -52,6 +52,7 @@ This is a summary of ChangeLog basically.
 * Raised max dcc/fd to 300.
 * Bots will auto-restart if 150 or more bogus fd are detected.
 * Conf/uname email now includes binary path.
+* After changing conf with -C, binary is now moved to binpath/binname.
 
 1.1.9
 

+ 4 - 2
src/binary.c

@@ -352,7 +352,8 @@ clear_settings(void)
 void conf_to_bin(conf_t *in)
 {
   conf_bot *bot = NULL;
-  
+  char *newbin = NULL;
+
   clear_settings();
   sdprintf("converting conf to bin\n");
   sprintf(settings.uid, "%d", in->uid);
@@ -378,6 +379,7 @@ void conf_to_bin(conf_t *in)
                            bot->ip6 ? bot->ip6 : "");
     }
 
+  newbin = move_bin(in->binpath, in->binname, 0);
   /* tellconfig(&settings); */
-  write_settings(binname, 1);
+  write_settings(newbin, 1);
 }

+ 2 - 10
src/conf.c

@@ -231,6 +231,7 @@ confedit()
     fatal("Error reading new config file", 0);
   readconf(tmpconf.file, 0);               /* read cleartext conf tmp into &settings */
   unlink(tmpconf.file);
+  fix_tilde(&conffile.binpath);
   conf_to_bin(&conffile);       /* will exit */
   exit(0);                      /* never reached */
 
@@ -480,17 +481,8 @@ parseconf()
     conffile.homedir = strdup(homedir());
   }
 
-  if (strchr(conffile.binpath, '~')) {
-    char *p = NULL;
-
-    if (conffile.binpath[strlen(conffile.binpath) - 1] == '/')
-      conffile.binpath[strlen(conffile.binpath) - 1] = 0;
+  fix_tilde(&conffile.binpath);
 
-    if ((p = replace(conffile.binpath, "~", homedir())))
-      str_redup(&conffile.binpath, p);
-    else
-      fatal("Unforseen error expanding '~'", 0);
-  }
 #endif /* !CYGWIN_HACKS */
   return 0;
 }

+ 5 - 45
src/main.c

@@ -622,52 +622,9 @@ static void startup_checks() {
    werr(ERR_BINSTAT);
   else if (fixmod(binname))
    werr(ERR_BINMOD);
-
+  
 #ifndef CYGWIN_HACKS
-  /* move the binary to the correct place */
-  {
-    char newbin[DIRMAX] = "", real[DIRMAX] = "";
-
-    sdprintf("my euid: %d my uuid: %d, my ppid: %d my pid: %d", geteuid(), myuid, getppid(), getpid());
-    egg_snprintf(newbin, sizeof newbin, "%s%s%s", conffile.binpath, 
-                 conffile.binpath[strlen(conffile.binpath) - 1] == '/' ? "" : "/",
-                 conffile.binname);
-    sdprintf("newbin at: %s", newbin);
-    
-    ContextNote("realpath()");
-    realpath(binname, real);		/* get the realpath of binname */
-    ContextNote("realpath(): Success");
-    /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
-    if (strcmp(binname, newbin) && strcmp(newbin, real)) { 		/* if wrong path and new path != current */
-      bool ok = 1;
-
-      sdprintf("real: %s", real);
-      sdprintf("wrong dir, is: %s :: %s", binname, newbin);
-
-      unlink(newbin);
-      if (copyfile(binname, newbin))
-        ok = 0;
-
-      if (ok && !can_stat(newbin)) {
-         unlink(newbin);
-         ok = 0;
-      }
-
-      if (ok && fixmod(newbin)) {
-          unlink(newbin);
-          ok = 0;
-      }
-
-      if (!ok) {
-        werr(ERR_WRONGBINDIR);
-      } else {
-        unlink(binname);
-        system(newbin);
-        sdprintf("exiting to let new binary run...");
-        exit(0);
-      }
-    }
-  }
+  move_bin(conffile.binpath, conffile.binname, 1);
 #endif /* !CYGWIN_HACKS */
 
   fillconf(&conf);
@@ -805,6 +762,9 @@ printf("out: %s\n", out);
     sdprintf("Calling dtx_arg with %d params.", argc);
     dtx_arg(argc, argv);
   }
+
+  sdprintf("my euid: %d my uuid: %d, my ppid: %d my pid: %d", geteuid(), myuid, getppid(), getpid());
+
 #ifndef CYGWIN_HACKS
   if (checktrace)
     check_trace(1);

+ 68 - 0
src/shell.c

@@ -880,6 +880,23 @@ char *confdir()
   return confdir_buf;
 }
 
+void fix_tilde(char **binptr)
+{
+  char *binpath = binptr ? *binptr : NULL;
+
+  if (binpath && strchr(binpath, '~')) {
+    char *p = NULL;
+
+    if (binpath[strlen(binpath) - 1] == '/')
+      binpath[strlen(binpath) - 1] = 0;
+
+    if ((p = replace(binpath, "~", homedir())))
+      str_redup(binptr, p);
+    else
+      fatal("Unforseen error expanding '~'", 0);
+  }
+}
+
 char *my_uname()
 {
   static char os_uname[250] = "";
@@ -905,6 +922,57 @@ char *my_uname()
 }
 
 #ifndef CYGWIN_HACKS
+char *move_bin(const char *path, const char *file, bool run)
+{
+  /* move the binary to the correct place */
+  static char newbin[DIRMAX] = "";
+  char real[DIRMAX] = "";
+
+  egg_snprintf(newbin, sizeof newbin, "%s%s%s", path, path[strlen(path) - 1] == '/' ? "" : "/", file);
+  sdprintf("newbin: %s", newbin);
+
+  ContextNote("realpath()");
+  realpath(binname, real);            /* get the realpath of binname */
+  ContextNote("realpath(): Success");
+  /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
+  if (strcmp(binname, newbin) && strcmp(newbin, real)) {              /* if wrong path and new path != current */
+    bool ok = 1;
+
+    sdprintf("real: %s", real);
+    sdprintf("wrong dir, is: %s :: %s", binname, newbin);
+
+    unlink(newbin);
+    if (copyfile(binname, newbin))
+      ok = 0;
+
+    if (ok && !can_stat(newbin)) {
+       unlink(newbin);
+       ok = 0;
+    }
+
+    if (ok && fixmod(newbin)) {
+        unlink(newbin);
+        ok = 0;
+    }
+
+    if (ok) {
+      sdprintf("Binary successfully moved to: %s", newbin);
+      unlink(binname);
+      if (run) {
+        system(newbin);
+        sdprintf("exiting to let new binary run...");
+        exit(0);
+      }
+    } else {
+      if (run)
+        werr(ERR_WRONGBINDIR);
+      sdprintf("Binary move failed to: %s", newbin);
+      return binname;
+    }
+  }
+  return newbin;
+}
+
 void check_crontab()
 {
   int i = 0;

+ 4 - 0
src/shell.h

@@ -47,6 +47,10 @@ char *homedir();
 char *my_username();
 char *my_uname();
 char *confdir();
+#ifndef CYGWIN_HACKS 
+char *move_bin(const char *, const char *, bool);
+#endif /* !CYGWIN_HACKS */
+void fix_tilde(char **);
 void baduname(char *, char *);
 int email(char *, char *, int);
 int shell_exec(char *, char *, char **, char **);