From 83a9a00dcc5c6bc9c4badc81b0e689e84abe2911 Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Date: Fri, 31 Jul 2009 13:01:27 -0400
Subject: [PATCH] [#1791] Use XDG_CACHE_HOME to save pid file

---
 sflphone-common/src/main.cpp | 21 +++++++++++++++++----
 1 file changed, 17 insertions(+), 4 deletions(-)

diff --git a/sflphone-common/src/main.cpp b/sflphone-common/src/main.cpp
index f20d721611..fe01b911cc 100644
--- a/sflphone-common/src/main.cpp
+++ b/sflphone-common/src/main.cpp
@@ -60,13 +60,24 @@ 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;
 
-        // TODO Use $XDG_CACHE_HOME instead of $HOME
-        sprintf (homepid, "%s/.%s/%s", HOMEDIR, PROGDIR, PIDFILE);
-        sprintf (sfldir, "%s/.%s", HOMEDIR, PROGDIR);
+		xdg_config = std::string (HOMEDIR) + DIR_SEPARATOR_STR + ".cache/sflphone";
+
+		if (XDG_CACHE_HOME != NULL) 
+		{
+			xdg_env = std::string (XDG_CACHE_HOME);
+			(xdg_env.length() > 0) ? path = xdg_env
+							:		path = xdg_config;
+		}
+		else
+			path = xdg_config;
+
+        sprintf (sfldir, "%s", path.c_str ());
+        sprintf (homepid, "%s/%s", path.c_str (), PIDFILE);
 
         if ( (fp = fopen (homepid,"r")) == NULL) {
-            // Check if $HOME/.sflphone directory exists or not.
+            // Check if $XDG_CACHE_HOME directory exists or not.
             DIR *dir;
 
             if ( (dir = opendir (sfldir)) == NULL) {
@@ -95,6 +106,8 @@ main (int argc, char **argv)
             else {
                 fclose (fp);
 
+				_debug ("SDLauiobvzsfivbsfivbsuobvsobvasbvfasdkbvkdbvbvksdbvksdbvkzsdbvasdfb: %i\n", atoi (cOldPid));
+
                 if (kill (atoi (cOldPid), 0) == SUCCESS) {
                     fprintf (stderr, "There is already a sflphoned daemon running in the system. Starting Failed.\n");
                     exit (-1);
-- 
GitLab