=== modified file 'common/common.cpp'
--- common/common.cpp	2014-12-23 13:01:59 +0000
+++ common/common.cpp	2015-01-05 21:51:33 +0000
@@ -305,6 +305,46 @@
     return cfg;
 }
 
+wxString GetKicadLockFilePath()
+{
+    wxFileName lockpath;
+    lockpath.AssignDir( wxGetHomeDir() ); // Default wx behavior
+
+#if defined( __WXMAC__ )
+    // In OSX use the standard per user cache directory
+    lockpath.AppendDir( wxT( "Library" ) );
+    lockpath.AppendDir( wxT( "Caches" ) );
+    lockpath.AppendDir( wxT( "kicad" ) );
+#elif defined( __UNIX__ )
+    wxString envstr;
+    // Try first the standard XDG_RUNTIME_DIR, falling back to XDG_CACHE_HOME
+    if( wxGetEnv( wxT( "XDG_RUNTIME_DIR" ), &envstr ) && !envstr.IsEmpty() )
+    {
+        lockpath.AssignDir( envstr );
+    }
+    else if( wxGetEnv( wxT( "XDG_CACHE_HOME" ), &envstr ) && !envstr.IsEmpty() )
+    {
+        lockpath.AssignDir( envstr );
+    }
+    else
+    {
+        // If all fails, just use ~/.cache
+        lockpath.AppendDir( wxT( ".cache" ) ); 
+    }
+
+    lockpath.AppendDir( wxT( "kicad" ) );
+#endif
+    
+#if defined( __WXMAC__ ) || defined( __UNIX__ )
+    if( !lockpath.DirExists() )
+    {
+	// Lockfiles should be only readable by the user
+        lockpath.Mkdir( 0700, wxPATH_MKDIR_FULL );
+    }
+#endif
+    return lockpath.GetPath();
+}
+
 
 wxString GetKicadConfigPath()
 {

=== modified file 'common/lockfile.cpp'
--- common/lockfile.cpp	2014-10-19 20:20:16 +0000
+++ common/lockfile.cpp	2015-01-05 04:00:09 +0000
@@ -24,6 +24,7 @@
 
 #include <wx/filename.h>
 #include <wx/snglinst.h>
+#include <common.h>
 
 
 wxSingleInstanceChecker* LockFile( const wxString& aFileName )
@@ -41,7 +42,7 @@
     // We can have filenames coming from Windows, so also convert Windows separator
     lockFileName.Replace( wxT( "\\" ), wxT( "_" ) );
 
-    wxSingleInstanceChecker* p = new wxSingleInstanceChecker( lockFileName );
+    wxSingleInstanceChecker* p = new wxSingleInstanceChecker( lockFileName, GetKicadLockFilePath() );
 
     if( p->IsAnotherRunning() )
     {

=== modified file 'common/pgm_base.cpp'
--- common/pgm_base.cpp	2014-10-17 17:45:33 +0000
+++ common/pgm_base.cpp	2015-01-05 03:31:13 +0000
@@ -353,7 +353,7 @@
 
     wxInitAllImageHandlers();
 
-    m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) + wxGetUserId() );
+    m_pgm_checker = new wxSingleInstanceChecker( pgm_name.GetName().Lower() + wxT( "-" ) + wxGetUserId(), GetKicadLockFilePath() );
 
     if( m_pgm_checker->IsAnotherRunning() )
     {

=== modified file 'include/common.h'
--- include/common.h	2014-12-23 13:01:59 +0000
+++ include/common.h	2015-01-05 03:29:04 +0000
@@ -434,6 +434,12 @@
 wxConfigBase* GetNewConfig( const wxString& aProgName );
 
 /**
+ * Function GetKicadLockFilePath
+ * @return A wxString containing the path for lockfiles in Kicad
+ */
+wxString GetKicadLockFilePath();
+
+/**
  * Function GetKicadConfigPath
  * @return A wxString containing the config path for Kicad
  */

