Bläddra i källkod

* Ported [2698] to 1.2.9 (copy pidfiles over from old tempdirs to datadir)

svn: 2699
Bryan Drewery 20 år sedan
förälder
incheckning
4888081a11
3 ändrade filer med 47 tillägg och 6 borttagningar
  1. 45 4
      src/conf.c
  2. 1 1
      src/conf.h
  3. 1 1
      src/shell.c

+ 45 - 4
src/conf.c

@@ -370,12 +370,45 @@ init_conf()
   expand_tilde(&conf.datadir);
 }
 
+/* FIXME: Remove after 1.2.9 I guess; or revise to work for when datadir changes. */
+/* This technically doesn't belong in the trunk, but it will be adapated for future use */
+static void conf_compat_pids()
+{
+  conf_bot *bot = NULL;
+  char path[DIRMAX] = "", dir[DIRMAX] = "";
+  int i = 0;
+
+  for (i = 0; i < 5; i++) {
+    if (i == 0) {
+      if (!conf.bot || !conf.bot->hub)
+        simple_snprintf(dir, sizeof(dir), "%s/.ssh/...", conf.homedir);
+      else
+        simple_snprintf(dir, sizeof(dir), "%s/tmp", conf.binpath);
+    } else if (i == 1) {
+      simple_snprintf(dir, sizeof(dir), "/tmp");
+    } else if (i == 2) {
+      simple_snprintf(dir, sizeof(dir), "/usr/tmp");
+    } else if (i == 3) {
+      simple_snprintf(dir, sizeof(dir), "/var/tmp");
+    } else if (i == 4) {
+      simple_snprintf(dir, sizeof(dir), "%s", conf.binpath);
+    }
+
+    for (bot = conf.bots; bot && bot->nick; bot = bot->next)
+      if (checkpid(bot->nick, bot, dir)) {
+        simple_snprintf(path, sizeof(path), "%s/.pid.%s", conf.datadir, bot->nick);
+        copyfile(bot->pid_file, path);
+      } else if (can_stat(bot->pid_file))
+        unlink(bot->pid_file);
+  }  
+}
+
 void conf_checkpids()
 {
   conf_bot *bot = NULL;
 
   for (bot = conf.bots; bot && bot->nick; bot = bot->next)
-    bot->pid = checkpid(bot->nick, bot);
+    bot->pid = checkpid(bot->nick, bot, NULL);
 }
 
 /*
@@ -383,7 +416,7 @@ void conf_checkpids()
  */
 
 pid_t
-checkpid(const char *nick, conf_bot *bot)
+checkpid(const char *nick, conf_bot *bot, const char *usedir)
 {
   FILE *f = NULL;
   char buf[DIRMAX] = "", *tmpnick = NULL, *tmp_ptr = NULL;
@@ -391,7 +424,11 @@ checkpid(const char *nick, conf_bot *bot)
 
   tmpnick = tmp_ptr = strdup(nick);
 
-  simple_snprintf(buf, sizeof buf, "%s/.pid.%s", conf.datadir, tmpnick);
+  /* FIXME: remove after 1.2.9 */
+  if (usedir)
+    simple_snprintf(buf, sizeof buf, "%s/.pid.%s", usedir, tmpnick);
+  else
+    simple_snprintf(buf, sizeof buf, "%s/.pid.%s", conf.datadir, tmpnick);
   free(tmp_ptr);
 
   if (bot && !(bot->pid_file))
@@ -419,6 +456,9 @@ checkpid(const char *nick, conf_bot *bot)
         pid = 0;
     }
 
+    /* FIXME: remove after 1.2.9 - this is so, when we are moving pidfiles, dont bother with socksfile stuff, just return if the pid is valid or not. */
+    if (!usedir)
+
     //There is a socksfile given and it's accessable, plus the pid in the file is my own
     //So it's a good chance we just did a soft restart
     if (bufp[0] && pid && can_stat(bufp) && (getpid() == pid) &&
@@ -541,7 +581,7 @@ conf_delbot(char *botn)
 
   for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
     if (!strcmp(bot->nick, botn)) {     /* found it! */
-      bot->pid = checkpid(bot->nick, bot);
+      bot->pid = checkpid(bot->nick, bot, NULL);
       conf_killbot(NULL, bot, SIGKILL);
       free_bot(bot);
       return 0;
@@ -1068,6 +1108,7 @@ bin_to_conf(void)
   if (clear_tmpdir)
     clear_tmp();	/* clear out the tmp dir, no matter if we are localhub or not */
 
+  conf_compat_pids();
   conf_checkpids();
 
   tellconf();

+ 1 - 1
src/conf.h

@@ -60,7 +60,7 @@ int conf_killbot(const char *, conf_bot *, int);
 void confedit() __attribute__((noreturn));
 void conf_addbot(char *, char *, char *, char *);
 int conf_delbot(char *);
-pid_t checkpid(const char *, conf_bot *);
+pid_t checkpid(const char *, conf_bot *, const char *);
 void init_conf();
 void free_conf();
 void free_conf_bots(conf_bot *);

+ 1 - 1
src/shell.c

@@ -161,7 +161,7 @@ void check_mypid()
   pid_t pid = 0;
   
   if (can_stat(conf.bot->pid_file))
-    pid = checkpid(conf.bot->nick, NULL);
+    pid = checkpid(conf.bot->nick, NULL, NULL);
 
   if (pid && (pid != getpid()))
     fatal(STR("getpid() does not match pid in file. Possible cloned process, exiting.."), 0);