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

* Some hacks so updating from 1.1.9->1.2.0 will read in the conf file
and auto write to binary
- Is done when update_bin() calls system(bin) with -2


svn: 1406

Bryan Drewery 21 лет назад
Родитель
Сommit
e7b7cbdb45
3 измененных файлов с 31 добавлено и 33 удалено
  1. 6 2
      src/binary.c
  2. 23 31
      src/main.c
  3. 2 0
      src/main.h

+ 6 - 2
src/binary.c

@@ -339,8 +339,12 @@ void write_settings(const char *fname, int die)
     edpack(&settings, hash, PACK_DEC);
   }
 
-  if (die)
-    exit(0);
+  if (die) {
+    if (old_hack == 2)
+      exit(2);			/* we were called with -2 so exit with 2 ! */
+    else
+      exit(0);
+  }
 }
 
 static void 

+ 23 - 31
src/main.c

@@ -67,6 +67,8 @@ extern int		optind;
 const time_t 	buildts = CVSBUILD;		/* build timestamp (UTC) */
 const char	egg_version[1024] = "1.2";
 
+/* FIXME: remove after 1.2 ??? OR NOT */
+bool old_hack = 0;
 bool 	localhub = 1; 		/* we set this to 0 if we get a -B */
 int 	role;
 bool 	loading = 0;
@@ -265,7 +267,8 @@ static void show_help()
   printf(format, "-v", "Displays bot version");
   exit(0);
 }
-
+/* FIXME: remove after 1.2 */
+static void startup_checks(int);
 
 #ifdef LEAF
 # define PARSE_FLAGS "02B:Cd:De:Eg:G:k:L:P:hnstu:U:v"
@@ -289,6 +292,11 @@ static void dtx_arg(int argc, char *argv[])
       case '0':
         exit(0);
       case '2':		/* used for testing new binary through update */
+        if (settings.uname[0])		/* we're already initialized with data, just exit! */
+          exit(2);
+	/* FIXME: remove after 1.2 */
+	/* ... otherwise, we need to check if ~/.ssh/.known_hosts exists and write to our binary */
+        startup_checks(2);
         exit(2);
 #ifdef LEAF
       case 'B':
@@ -520,10 +528,9 @@ static void core_halfhourly()
 #endif /* HUB */
 }
 
-/* FIXME: Remove after 1.2 */
-static void startup_checks() {
+/* FIXME: Remove after 1.2 (the hacks) */
+static void startup_checks(int hack) {
   int enc = CONF_ENC;
-  bool old_hack = 0;
 
   /* for compatability with old conf files 
    * only check/use conf file if it exists and settings.uname is empty.
@@ -547,7 +554,7 @@ static void startup_checks() {
     if (mkdir(confdir(),  S_IRUSR | S_IWUSR | S_IXUSR)) {
       unlink(confdir());
       if (!can_stat(confdir()))
-        if (mkdir(confdir(), S_IRUSR | S_IWUSR | S_IXUSR))
+        if (mkdir(confdir(), S_IRUSR | S_IWUSR | S_IXUSR) && !hack)
 #endif /* LEAF */
           werr(ERR_CONFSTAT);
 #ifdef LEAF
@@ -555,7 +562,7 @@ static void startup_checks() {
 #endif /* LEAF */
   }
 
-  if (fixmod(confdir()))
+  if (fixmod(confdir()) && !hack)
     werr(ERR_CONFDIRMOD);
  
   if (can_stat(cfile) && !settings.uname[0])
@@ -563,21 +570,25 @@ static void startup_checks() {
   if (can_stat(cfile) && settings.uname[0])
     unlink(cfile);		/* kill the old one! */
 
-  if (old_hack && can_stat(cfile) && fixmod(cfile))
+  if (old_hack && hack)
+    old_hack = 2;		/* this is so write_settings() will exit(2); */
+
+  if (old_hack && can_stat(cfile) && fixmod(cfile) && !hack)
     werr(ERR_CONFMOD);
 
   if (!can_stat(tempdir)) {
     if (mkdir(tempdir,  S_IRUSR | S_IWUSR | S_IXUSR)) {
       unlink(tempdir);
       if (!can_stat(tempdir))
-        if (mkdir(tempdir, S_IRUSR | S_IWUSR | S_IXUSR))
+        if (mkdir(tempdir, S_IRUSR | S_IWUSR | S_IXUSR) && !hack)
           werr(ERR_TMPSTAT);
     }
   }
-  if (fixmod(tempdir))
+  if (fixmod(tempdir) && !hack)
     werr(ERR_TMPMOD);
 
   /* test tempdir: it's vital */
+  if (!hack)
   {
     Tempfile *testdir = new Tempfile("test");
     int result;
@@ -592,7 +603,7 @@ static void startup_checks() {
   if (old_hack && can_stat(cfile))
     readconf(cfile, enc);	/* will read into &conffile struct */
   else if (settings.uname[0])
-    bin_to_conf();
+    bin_to_conf();		/* read our memory from settings[] into conf[] */
 
 #ifndef CYGWIN_HACKS
   if (do_confedit)
@@ -601,23 +612,7 @@ static void startup_checks() {
   parseconf();
 
   if (old_hack)
-    conf_to_bin(&conffile);
-/* -- */
-//exit(1);
-
-/* NO?
-  if (old_hack) {
-#ifdef LEAF
-    if (localhub)
-#endif
-      writeconf(cfile, NULL, enc);
-  } else if (!old_hack) {
-#ifdef LEAF
-    if (localhub)
-#endif
-    write_settings(binname);
-  }
-*/
+    conf_to_bin(&conffile);	/* this will exit() in write_settings() */
 
   if (!can_stat(binname))
    werr(ERR_BINSTAT);
@@ -771,11 +766,8 @@ printf("out: %s\n", out);
     check_trace(1);
 #endif /* !CYGWIN_HACKS */
 
-//  strcpy(settings.username, "bryan");
-//  write_settings(binname);
-
   /* Check and load conf file */
-  startup_checks();
+  startup_checks(0);
 
   if ((localhub && !updating) || !localhub) {
     if ((conf.bot->pid > 0) && conf.bot->pid_file) {

+ 2 - 0
src/main.h

@@ -5,6 +5,8 @@
 
 extern int		role, default_flags, default_uflags,
 			updating;
+/* FIXME: remove after 1.2? */
+extern bool		old_hack;
 extern bool		use_stderr, backgrd, localhub, term_z, loading;
 extern char		tempdir[], *binname, owner[], version[], ver[], quit_msg[];
 extern time_t		online_since, now;