From 2cff4a7f65cee31deda62c130e813af0cbd906fa Mon Sep 17 00:00:00 2001 From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com> Date: Tue, 10 Nov 2009 11:24:18 -0500 Subject: [PATCH] [#2313] Force $(HOME).cache directory creation at startup --- sflphone-common/src/main.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/sflphone-common/src/main.cpp b/sflphone-common/src/main.cpp index 8de4f43532..48975876a9 100644 --- a/sflphone-common/src/main.cpp +++ b/sflphone-common/src/main.cpp @@ -60,19 +60,20 @@ main (int argc, char **argv) unsigned int iPid = getpid(); char cPid[64], cOldPid[64]; sprintf (cPid,"%d", iPid); - std::string xdg_config, xdg_env, path; + std::string xdg_cache, xdg_env, path; - xdg_config = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".cache/sflphone"; + xdg_cache = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".cache/"; if (XDG_CACHE_HOME != NULL) { xdg_env = std::string (XDG_CACHE_HOME); (xdg_env.length() > 0) ? path = xdg_env - : path = xdg_config; + : path = xdg_cache; } else - path = xdg_config; + path = xdg_cache; sprintf (sfldir, "%s", path.c_str ()); + path = path + "sflphone"; sprintf (homepid, "%s/%s", path.c_str (), PIDFILE); if ( (fp = fopen (homepid,"r")) == NULL) { @@ -87,6 +88,16 @@ main (int argc, char **argv) } } + // Then create the sflphone directory inside the $XDG_CACHE_HOME dir + sprintf (sfldir, "%s", path.c_str ()); + if ( (dir = opendir (sfldir)) == NULL) { + //Create it + if (mkdir (sfldir, 0755) != 0) { + fprintf (stderr, "Creating directory %s failed. Exited.\n", sfldir); + exit (-1); + } + } + // PID file doesn't exists, create and write pid in it if ( (fp = fopen (homepid,"w")) == NULL) { fprintf (stderr, "Creating PID file %s failed. Exited.\n", homepid); -- GitLab