Selaa lähdekoodia

* tempdir is now filled in bin_to_conf
* Added function conf_checkpids() to be called after tempdir is initialized and checked
will fill in all the pid_file strings and checkpid() on each bot


svn: 1900

Bryan Drewery 21 vuotta sitten
vanhempi
commit
488f4d034f
4 muutettua tiedostoa jossa 32 lisäystä ja 20 poistoa
  1. 5 5
      src/binary.c
  2. 25 1
      src/conf.c
  3. 1 0
      src/conf.h
  4. 1 14
      src/main.c

+ 5 - 5
src/binary.c

@@ -346,7 +346,7 @@ static void edpack(settings_t *incfg, const char *hash, int what)
 #undef dofield
 }
 
-/* 
+ 
 static void
 tellconfig(settings_t *incfg)
 {
@@ -376,7 +376,7 @@ tellconfig(settings_t *incfg)
   dofield(incfg->portmax);
 #undef dofield
 }
-*/
+
 
 void
 check_sum(const char *fname, const char *cfgfile)
@@ -388,16 +388,16 @@ check_sum(const char *fname, const char *cfgfile)
 
     readcfg(cfgfile);
 
-// tellconfig(&settings); 
+ tellconfig(&settings); 
     if (bin_checksum(fname, WRITE_CHECKSUM|WRITE_CONF|WRITE_PACK))
       printf("* Wrote settings to binary.\n"); 
     exit(0);
   } else {
     char *hash = bin_checksum(fname, GET_CHECKSUM);
 
-// tellconfig(&settings); 
+ tellconfig(&settings); 
     edpack(&settings, hash, PACK_DEC);
-// tellconfig(&settings); 
+ tellconfig(&settings); 
 
     if (strcmp(settings.hash, hash)) {
       unlink(fname);

+ 25 - 1
src/conf.c

@@ -302,6 +302,14 @@ init_conf()
   conf.homedir = NULL;
 }
 
+void conf_checkpids()
+{
+  conf_bot *bot = NULL;
+
+  for (bot = conf.bots; bot && bot->nick; bot = bot->next)
+    bot->pid = checkpid(bot->nick, bot);
+}
+
 /*
  * Return the PID of a bot if it is running, otherwise return 0
  */
@@ -377,7 +385,7 @@ conf_addbot(char *nick, char *ip, char *host, char *ip6)
     bot->net.v6 = 1;
 
   bot->u = NULL;
-  bot->pid = checkpid(nick, bot);
+//  bot->pid = checkpid(nick, bot);
 
   if (settings.hubs) {
     char *p = settings.hubs, *p2 = NULL;
@@ -857,5 +865,21 @@ bin_to_conf(void)
     }
     free(tmpp);
   }
+
+  /* this is temporary until we make tmpdir customizable */
+  if (conf.bots && conf.bots->nick && conf.bots->hub)
+    egg_snprintf(tempdir, DIRMAX, "%s/tmp/", conf.binpath);
+  else
+    egg_snprintf(tempdir, DIRMAX, "%s/.ssh/.../", conf.homedir);
+
+#ifdef CYGWIN_HACKS
+  egg_snprintf(tempdir, DIRMAX, "tmp/");
+#endif /* CYGWIN_HACKS */
+
+  check_tempdir();      /* ensure we can access tmpdir if it changed */
+  clear_tmp();          /* clear out the tmp dir, no matter if we are localhub or not */
+
+  conf_checkpids();
+
   tellconf();
 }

+ 1 - 0
src/conf.h

@@ -68,6 +68,7 @@ int parseconf(bool);
 int writeconf(char *, FILE *, int);
 void fill_conf_bot();
 void bin_to_conf(void);
+void conf_checkpids();
 
 #ifdef CYGWIN_HACKS
 extern char		cfile[DIRMAX];

+ 1 - 14
src/main.c

@@ -561,7 +561,7 @@ static void startup_checks(int hack) {
    werr(ERR_BINSTAT);
   else if (fixmod(binname))
    werr(ERR_BINMOD);
-  
+
 #ifndef CYGWIN_HACKS
   move_bin(conf.binpath, conf.binname, 1);
 #endif /* !CYGWIN_HACKS */
@@ -697,19 +697,6 @@ printf("out: %s\n", out);
   /* Check and load conf file */
   startup_checks(0);
 
-  /* this is temporary until we make tmpdir customizable */
-  if (conf.bot->hub)
-    egg_snprintf(tempdir, sizeof tempdir, "%s/tmp/", conf.binpath);
-  else
-    egg_snprintf(tempdir, sizeof tempdir, "%s/.ssh/.../", conf.homedir);
-
-#ifdef CYGWIN_HACKS
-  egg_snprintf(tempdir, sizeof tempdir, "tmp/");
-#endif /* CYGWIN_HACKS */
-
-  check_tempdir();	/* ensure we can access tmpdir if it changed */
-  clear_tmp();		/* clear out the tmp dir, no matter if we are localhub or not */
-
   if ((conf.bot->localhub && !updating) || !conf.bot->localhub) {
     if ((conf.bot->pid > 0) && conf.bot->pid_file) {
       sdprintf("%s is already running, pid: %d", conf.bot->nick, conf.bot->pid);