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

* Create 1.2.10 branch

svn: 2749
Bryan Drewery 20 лет назад
Родитель
Сommit
b9204d2673
7 измененных файлов с 66 добавлено и 48 удалено
  1. 2 0
      doc/UPDATES
  2. 0 3
      src/binary.c
  3. 10 2
      src/conf.c
  4. 1 1
      src/main.c
  5. 0 6
      src/misc.c
  6. 46 34
      src/misc_file.c
  7. 7 2
      src/misc_file.h

+ 2 - 0
doc/UPDATES

@@ -64,6 +64,8 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Fixed segfault in cmd_slowpart (#191)
 * Fixed a memory leak in the cookie checking functions.
 * Fixed some segfaults with tempfiles
+* Update binaries can now be stored in bins/ within the hub's binary directory.
+* If a tempdir suddenly becomes unavailable, a new one is now immediately sought out.
 
 1.2.8
 * Fixed [bot]* cmds depending on case of botnicks.

+ 0 - 3
src/binary.c

@@ -97,9 +97,6 @@ bin_checksum(const char *fname, int todo)
     char *fname_bak = NULL;
     size_t size = 0, newpos = 0;
 
-    if (!newbin || newbin->error)
-      werr(ERR_TMPSTAT);
-
     size = strlen(fname) + 2;
     fname_bak = (char *) my_calloc(1, size);
     simple_snprintf(fname_bak, size, "%s~", fname);

+ 10 - 2
src/conf.c

@@ -401,7 +401,9 @@ static void conf_compat_pids()
       continue;
 
     for (bot = conf.bots; bot && bot->nick; bot = bot->next)
+      /* returns 1 if: pidfile is there and PID is running AND if there is a socksfile listed, if it is valid. */
       if (checkpid(bot->nick, bot, dir)) {
+        /* Ok so we found a valid pid file, which might include a VALID socksfile. */
         simple_snprintf(path, sizeof(path), "%s/.pid.%s", conf.datadir, bot->nick);
         copyfile(bot->pid_file, path);
       //We only want to unlink if the pidfile is NOT being used, otherwise, it might break a bot that's on timer to restart/update.
@@ -463,11 +465,17 @@ checkpid(const char *nick, conf_bot *bot, const char *usedir)
         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 this pidfile is stale, don't let compat_checkpids copy it over. */
+    if (usedir && bufp[0] && pid) {
+      if (can_stat(bufp))
+        return pid;
+      /* socks file not there? this pidfile is probably stale, move along ... */
+      return 0;
+    }
+
     if (bufp[0] && pid && can_stat(bufp) && (getpid() == pid) &&
         !egg_strcasecmp(nick, origbotname)) {
       socksfile = strdup(bufp);

+ 1 - 1
src/main.c

@@ -69,7 +69,7 @@ extern int		optind;
 
 const time_t 	buildts = BUILDTS;		/* build timestamp (UTC) */
 const char	*revision = REVISION;
-const char	*egg_version = "1.2.10-devel";
+const char	*egg_version = "1.2.9";
 
 bool	used_B = 0;		/* did we get started with -B? */
 int 	role;

+ 0 - 6
src/misc.c

@@ -636,9 +636,6 @@ restart(int idx)
   Tempfile *socks = new Tempfile("socks");
   int fd = 0;
 
-  if (!socks || socks->error)
-    werr(ERR_TMPSTAT);
-
   sdprintf("%s", reason); 
 
   if (tands > 0) {
@@ -790,9 +787,6 @@ int updatebin(int idx, char *par, int secs)
 
   Tempfile *conffile = new Tempfile("conf");
 
-  if (!conffile || conffile->error)
-    return 1;
-
   if (writeconf(NULL, conffile->f, CONF_ENC)) {
     putlog(LOG_MISC, "*", "Failed to write temporary config file for update.");
     delete conffile;

+ 46 - 34
src/misc_file.c

@@ -16,6 +16,8 @@
 #include "shell.h"
 #include "binary.h"
 
+static bool looking = 0;
+
 /* Copy a file from one place to another (possibly erasing old copy).
  *
  * returns:  0 if OK
@@ -152,20 +154,29 @@ int fixmod(const char *s)
   return chmod(s, S_IRUSR | S_IWUSR | S_IXUSR);
 }
 
-Tempfile::Tempfile()
+Tempfile::Tempfile(const char *prefix)
 {
-  len = strlen(tempdir) + 1 + 6 + 1;
-  file = new char[len];
-  simple_sprintf(file, "%s.XXXXXX", tempdir);
+  if (prefix) {
+    plen = strlen(prefix) + 1;
+    this->prefix = new char[plen];
+    strlcpy(this->prefix, prefix, plen);
+  } else {
+    this->prefix = NULL;
+    plen = -1; /* to swallow the '-' */
+  }
 
-  MakeTemp();
+  AllocTempfile();
 }
 
-Tempfile::Tempfile(const char *prefix)
+void Tempfile::AllocTempfile()
 {
-  len = strlen(tempdir) + 1 + strlen(prefix) + 1 + 6 + 1;
+  len = strlen(tempdir) + 1 + plen + 1 + 6 + 1;
   file = new char[len];
-  simple_sprintf(file, "%s.%s-XXXXXX", tempdir, prefix);
+
+  if (prefix)
+    simple_snprintf(file, len, "%s.%s-XXXXXX", tempdir, prefix);
+  else
+    simple_snprintf(file, len, "%s.XXXXXX", tempdir);
 
   MakeTemp();
 }
@@ -188,7 +199,19 @@ void Tempfile::MakeTemp()
 error:
   putlog(LOG_ERRORS, "*", "Couldn't create temporary file '%s': %s", file, strerror(errno));
   error = 1;
-//  fatal("Cannot create temporary file!", 0);
+  /* Since we failed to create a file in the given tempdir, let's try finding a new one */
+  if (!looking) {
+    /* ... Not finding a new tempdir is fatal. */
+    if (FindDir() == ERROR)
+      werr(ERR_TMPSTAT);		/* FIXME: Perhaps this should be an exception? */
+    /* ... If we found one, let's try all over! */
+    else {
+      error = 0;
+      delete[] file;
+      file = NULL;
+      AllocTempfile();
+    }
+  }
 }
 
 void Tempfile::my_close()
@@ -221,13 +244,13 @@ static bool check_tempdir(bool do_mod)
 
   /* test tempdir: it's vital */
   Tempfile *testdir = new Tempfile("test");
-  int result;
 
+  /* There was an error creating a file in this directory, return to move on in list of dirs */
   if (!testdir || testdir->error)
     return 0;
 
   fprintf(testdir->f, "\n");
-  result = fflush(testdir->f);
+  int result = fflush(testdir->f);
   delete testdir;
   if (result) {
     sdprintf("%s: %s", tempdir, strerror(errno));
@@ -236,7 +259,7 @@ static bool check_tempdir(bool do_mod)
   return 1;
 }
 
-void Tempfile::FindDir()
+bool Tempfile::FindDir()
 {
   /* this is temporary until we make tmpdir customizable */
 #ifdef CYGWIN_HACKS
@@ -245,29 +268,21 @@ void Tempfile::FindDir()
     clear_tmpdir = 0;
     simple_snprintf(tempdir, DIRMAX, "./");
   }
-  return;
+  return OK;
 #else
 
+  looking = 1;
+
   /* If this is a hub, use, "./tmp/" */
   if (conf.bots && conf.bots->nick && conf.bots->hub) {
     simple_snprintf(tempdir, DIRMAX, "%s/tmp/", conf.binpath);
-    if (check_tempdir(0))
-      return;
+    if (check_tempdir(0)) {
+      looking = 0;
+      return OK;
+    }
   }
   
-/* WHY
-  else if (conf.homedir && conf.homedir[0]) {
-    //need to create ~/.ssh/  
-    simple_snprintf(tempdir, DIRMAX, "%s/.ssh/", conf.homedir);
-    clear_tmpdir = 0;
-    check_tempdir(0);
-    clear_tmpdir = 1;
-    simple_snprintf(tempdir, DIRMAX, "%s/.ssh/.../", conf.homedir);
-  }
-*/
-
   /* The dirs we WANT to use aren't accessible, try a random one instead to get the job done. */
-
   clear_tmpdir = 0;
 
   char *dirs[] = {
@@ -277,18 +292,15 @@ void Tempfile::FindDir()
     "./",
     NULL
   };
-  int i = 0;
-  bool found = 0;
 
-  for (i = 0; dirs[i]; i++) {
+  for (int i = 0; dirs[i]; i++) {
     strlcpy(tempdir, dirs[i], DIRMAX);
     if (check_tempdir(0)) {
-      found = 1;
-      break;
+      looking = 0;
+      return OK;
     }
   }
 
-  if (!found)
-    werr(ERR_TMPSTAT);
+  werr(ERR_TMPSTAT);
 #endif /* CYGWIN_HACKS */
 }

+ 7 - 2
src/misc_file.h

@@ -21,18 +21,23 @@ int fixmod(const char *);
 class Tempfile 
 {
   public:
-    Tempfile();					//constructor
+    Tempfile() { Tempfile(NULL); };					//constructor
     Tempfile(const char *prefix);		//constructor with file prefix
+
+    void AllocTempfile();			//constructor with file prefix
     void Tempfile::my_close();
     ~Tempfile();				//destructor
-    static void FindDir();
+    static bool FindDir();
 
     bool error;					//exceptions are lame.
     FILE *f;
     char *file;
     int fd;
     size_t len;
+
   private:
+    char *prefix;
+    int plen;
     void MakeTemp();				//Used for mktemp() and checking
 };