try to fallback on missing XDG_RUNTIME_DIR
authorGustavo Sverzut Barbieri <barbieri@gmail.com>
Tue, 9 Oct 2012 20:12:02 +0000 (20:12 +0000)
committerGustavo Sverzut Barbieri <barbieri@gmail.com>
Tue, 9 Oct 2012 20:12:02 +0000 (20:12 +0000)
SVN revision: 77682

legacy/efreet/src/lib/efreet_base.c
legacy/efreet/src/lib/efreet_private.h

index 3b84ee0..ea71bf9 100644 (file)
@@ -33,6 +33,8 @@ static int _efreet_base_log_dom = -1;
 #include "Efreet.h"
 #include "efreet_private.h"
 
+#include <Ecore_File.h>
+
 static Efreet_Version _version = { VMAJ, VMIN, VMIC, VREV };
 EAPI Efreet_Version *efreet_version = &_version;
 
@@ -258,8 +260,38 @@ efreet_cache_home_get(void)
 EAPI const char *
 efreet_runtime_dir_get(void)
 {
+    struct stat st;
     if (xdg_runtime_dir) return xdg_runtime_dir;
     xdg_runtime_dir = efreet_dir_get("XDG_RUNTIME_DIR", "/tmp");
+    if (stat(xdg_runtime_dir, &st) == -1)
+      {
+         ERR("$XDG_RUNTIME_DIR did not exist, creating '%s' (breaks spec)",
+             xdg_runtime_dir);
+         if (ecore_file_mkpath(xdg_runtime_dir))
+           chmod(xdg_runtime_dir, 0700);
+         else
+           {
+              CRITICAL("Failed to create XDG_RUNTIME_DIR=%s", xdg_runtime_dir);
+              eina_stringshare_replace(&xdg_runtime_dir, NULL);
+           }
+      }
+    else if (!S_ISDIR(st.st_mode))
+      {
+         CRITICAL("XDG_RUNTIME_DIR=%s is not a directory!", xdg_runtime_dir);
+         eina_stringshare_replace(&xdg_runtime_dir, NULL);
+      }
+    else if ((st.st_mode & 0777) != 0700)
+      {
+         ERR("XDG_RUNTIME_DIR=%s is mode %o, changing to 0700",
+             xdg_runtime_dir, st.st_mode & 0777);
+         if (chmod(xdg_runtime_dir, 0700) != 0)
+           {
+              CRITICAL("Cannot fix XDG_RUNTIME_DIR=%s incorrect mode %o: %s",
+                       xdg_runtime_dir, st.st_mode & 0777, strerror(errno));
+              eina_stringshare_replace(&xdg_runtime_dir, NULL);
+           }
+      }
+
     return xdg_runtime_dir;
 }
 
index 8705e3b..19ffe25 100644 (file)
  * four macros are defined ERR, WRN, DGB, INF. 
  * EFREET_MODULE_LOG_DOM should be defined individually for each module
  */
+#ifdef CRITICAL
+#undef CRITICAL
+#endif
+#define CRITICAL(...) EINA_LOG_DOM_CRIT(EFREET_MODULE_LOG_DOM, __VA_ARGS__)
 #ifdef ERR
 #undef ERR
 #endif