Explorar o código

* Port [3174] to 1.2.13
* Fix bot not checking if it can access datadir on startup. (fixes #330)



svn: 3175

Bryan Drewery %!s(int64=19) %!d(string=hai) anos
pai
achega
1a460f5280
Modificáronse 4 ficheiros con 18 adicións e 4 borrados
  1. 1 0
      doc/UPDATES
  2. 6 1
      src/conf.c
  3. 8 1
      src/shell.c
  4. 3 2
      src/shell.h

+ 1 - 0
doc/UPDATES

@@ -23,6 +23,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Fix cmd_link being used to link to non-hubs. (fixes #329)
 * Fix cmd_mns_chan not sharing console changes. (fixes #328)
 * Fix many instances of hub nicks leaking to leaf bots. (fixes #326)
+* Fix bot not checking if it can access datadir on startup. (fixes #330)
 
 1.2.12 - http://wraith.shatow.net/milestone/1.2.12
 * Clearing a variable via 'set var -' now resets that variable to default settings. (implements #111)

+ 6 - 1
src/conf.c

@@ -1143,7 +1143,12 @@ bin_to_conf(bool error)
     free(tmpp);
   }
 
-  mkdir_p(conf.datadir);
+  char datadir[PATH_MAX] = "";
+  realpath(conf.datadir, datadir);
+  str_redup(&conf.datadir, datadir);
+  if (!mkdir_p(conf.datadir) && error)
+    werr(ERR_DATADIR);
+
   Tempfile::FindDir();
 
   if (clear_tmpdir)

+ 8 - 1
src/shell.c

@@ -666,6 +666,8 @@ char *werr_tostr(int errnum)
     return "Cannot access the global passwd file";
   case ERR_WRONGBINDIR:
     return "Wrong directory/binary name";
+  case ERR_DATADIR: 
+    return STR("Cannot access datadir.");
   case ERR_TMPSTAT:
     return STR("Cannot access tmp directory.");
   case ERR_TMPMOD:
@@ -868,7 +870,7 @@ char *my_username()
   return username[0] ? username : NULL;
 }
 
-void mkdir_p(const char *dir) {
+int mkdir_p(const char *dir) {
   char *p = NULL, *path = NULL;
 
   path = p = strdup(dir);
@@ -888,7 +890,12 @@ void mkdir_p(const char *dir) {
     if (p)
       *p = '/';
   } while(p);
+
+  int couldStat = can_stat(path);
+
   free(path);
+
+  return couldStat;
 }
 
 void expand_tilde(char **ptr)

+ 3 - 2
src/shell.h

@@ -9,7 +9,8 @@
 #define ERR_BINMOD      2
 #define ERR_PASSWD      3
 #define ERR_WRONGBINDIR 4
-#define ERR_TMPSTAT     6
+#define ERR_DATADIR	5
+#define ERR_TMPSTAT     8
 #define ERR_TMPMOD      9
 #define ERR_WRONGUID    12
 #define ERR_WRONGUNAME  13
@@ -73,7 +74,7 @@ char *werr_tostr(int);
 int det_translate(const char *);
 const char *det_translate_num(int);
 char *shell_escape(const char *);
-void mkdir_p(const char *);
+int mkdir_p(const char *);
 extern bool		clear_tmpdir;
 
 #endif /* _SHELL_H */