1
0
Эх сурвалжийг харах

* Tempdir is now chosen from a list as follows: (hub) ./tmp/ (leaf) ~/.ssh/..., /tmp/, ./

svn: 2093
Bryan Drewery 21 жил өмнө
parent
commit
756c56ffe4
8 өөрчлөгдсөн 55 нэмэгдсэн , 24 устгасан
  1. 2 1
      doc/UPDATES
  2. 2 0
      src/chanprog.c
  3. 3 10
      src/conf.c
  4. 1 2
      src/main.c
  5. 35 6
      src/misc_file.c
  6. 1 1
      src/misc_file.h
  7. 8 3
      src/shell.c
  8. 3 1
      src/shell.h

+ 2 - 1
doc/UPDATES

@@ -98,7 +98,6 @@ Lines prefixxed with '-' were disabled before release and are not finishsed, or
 * botcmd * wasn't correctly being restricted to +n (#35)
 * Fixed cmd_mns_(ban|exempt|invite) to remove the proper ban if a number is used (#38)
 * Fixed cmd_stick/cmd_unstick not making leaf bots set/unset the masks in channels. (#41)
-* Use /tmp/ as the default tempdir until tempdir is read from config
 * Detection system run by localhub will kill all other running bots with DIE/SUICIDE now.
 * During update, bot uplinks aren't permanently changed now.
 * Bans aren't checked on join anymore if the channel is +take
@@ -122,6 +121,8 @@ Lines prefixxed with '-' were disabled before release and are not finishsed, or
 * Added entry to help for ban-time in chanset: ban-time requires +dynamicbans
 * Fixed a bug where a bot would stop trying to connect to servers if using ipv6.
 * New channels get a default chanset of: flood-ctcp 5:30
+* Tempdir is now chosen from a list as follows: (hub) ./tmp/ (leaf) ~/.ssh/..., /tmp/, ./
+
 
 1.2.2
 * Don't sanity check flags for users on DCC CHAT if they are on the bot via .botcmd.

+ 2 - 0
src/chanprog.c

@@ -326,6 +326,8 @@ void tell_verbose_status(int idx)
 
   dprintf(idx, "OS: %s %s\n", uni_t, vers_t);
   dprintf(idx, "Running from: %s\n", binname);
+  if (tempdir[0])
+    dprintf(idx, "Tempdir     : %s\n", tempdir);
 }
 
 /* Show all internal state variables

+ 3 - 10
src/conf.c

@@ -996,18 +996,11 @@ bin_to_conf(void)
     free(tmpp);
   }
 
-  /* this is temporary until we make tmpdir customizable */
-  if (conf.bots && conf.bots->nick && conf.bots->hub)
-    simple_snprintf(tempdir, DIRMAX, "%s/tmp/", conf.binpath);
-  else
-    simple_snprintf(tempdir, DIRMAX, "%s/.ssh/.../", conf.homedir);
 
-#ifdef CYGWIN_HACKS
-  simple_snprintf(tempdir, DIRMAX, "tmp/");
-#endif /* CYGWIN_HACKS */
+  Tempfile::FindDir();
 
-  check_tempdir(1);      /* ensure we can access tmpdir if it changed */
-  clear_tmp();          /* clear out the tmp dir, no matter if we are localhub or not */
+  if (clear_tmpdir)
+    clear_tmp();	/* clear out the tmp dir, no matter if we are localhub or not */
 
   conf_checkpids();
 

+ 1 - 2
src/main.c

@@ -679,8 +679,7 @@ printf("out: %s\n", out);
   binname = getfullbinname(argv[0]);
   chdir(dirname(binname));
 
-  simple_snprintf(tempdir, sizeof(tempdir), "/tmp/");
-  check_tempdir(0);	/* make sure directory exists and we can access it */
+  Tempfile::FindDir();
 
   /* This allows -2/-0 to be used without an initialized binary */
 //  if (!(argc == 2 && (!strcmp(argv[1], "-2") || !strcmp(argv[1], "0")))) {

+ 35 - 6
src/misc_file.c

@@ -212,18 +212,18 @@ Tempfile::~Tempfile()
   delete[] file;
 }
 
-void check_tempdir(bool do_chmod)
+static bool check_tempdir(bool do_mod)
 {
   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))
-          werr(ERR_TMPSTAT);
+          return 0;
     }
   }
-  if (do_chmod && fixmod(tempdir))
-    werr(ERR_TMPMOD);
+  if (do_mod && fixmod(tempdir))
+    return 0;
 
   /* test tempdir: it's vital */
   Tempfile *testdir = new Tempfile("test");
@@ -232,7 +232,36 @@ void check_tempdir(bool do_chmod)
   fprintf(testdir->f, "\n");
   result = fflush(testdir->f);
   delete testdir;
-  if (result)
-    fatal(strerror(errno), 0);
+  if (result) {
+    sdprintf("%s: %s", tempdir, strerror(errno));
+    return 0;
+  }
+  return 1;
 }
 
+void Tempfile::FindDir()
+{
+  /* this is temporary until we make tmpdir customizable */
+  if (conf.bots && conf.bots->nick && conf.bots->hub)
+    simple_snprintf(tempdir, DIRMAX, "%s/tmp/", conf.binpath);
+  else
+    simple_snprintf(tempdir, DIRMAX, "%s/.ssh/.../", conf.homedir);
+
+#ifdef CYGWIN_HACKS
+  simple_snprintf(tempdir, DIRMAX, "tmp/");
+#endif /* CYGWIN_HACKS */
+
+  if (!check_tempdir(0)) {
+    clear_tmpdir = 0;
+    simple_snprintf(tempdir, DIRMAX, "/tmp/");
+  }
+
+  if (!check_tempdir(0)) {
+    simple_snprintf(tempdir, DIRMAX, "./");
+  }
+
+  if (!check_tempdir(0)) {
+    check_tempdir(0);
+    werr(ERR_TMPSTAT);
+  }
+}

+ 1 - 1
src/misc_file.h

@@ -17,7 +17,6 @@ int can_lstat(const char *);
 int is_symlink(const char *);
 int is_dir(const char *);
 int fixmod(const char *);
-void check_tempdir(bool);
 
 class Tempfile 
 {
@@ -26,6 +25,7 @@ class Tempfile
     Tempfile(const char *prefix);		//constructor with file prefix
     void Tempfile::my_close();
     ~Tempfile();				//destructor
+    static void FindDir();
 
     bool error;					//exceptions are lame.
     FILE *f;

+ 8 - 3
src/shell.c

@@ -47,6 +47,8 @@
 #include <unistd.h>
 #include <dirent.h>
 
+bool clear_tmpdir = 0;
+
 #ifdef WIN32
 int
 my_system(const char *run)
@@ -75,12 +77,15 @@ my_system(const char *run)
 }
 #endif /* WIN32 */
 
-int clear_tmp()
+void clear_tmp()
 {
+  if (!clear_tmpdir)
+    return;
+
   DIR *tmp = NULL;
 
   if (!(tmp = opendir(tempdir))) 
-    return 1;
+    return;
 
   struct dirent *dir_ent = NULL;
   char *file = NULL;
@@ -100,7 +105,7 @@ int clear_tmp()
     }
   }
   closedir(tmp);
-  return 0;
+  return;
 }
 
 void check_maxfiles()

+ 3 - 1
src/shell.h

@@ -38,7 +38,7 @@
 
 void check_maxfiles();
 void check_mypid();
-int clear_tmp();
+void clear_tmp();
 char *homedir(bool = 1);
 char *my_username();
 char *my_uname();
@@ -63,4 +63,6 @@ void detected(int, char *);
 void werr(int) __attribute__((noreturn));
 char *werr_tostr(int);
 
+extern bool		clear_tmpdir;
+
 #endif /* _SHELL_H */