From ec0b41836b632df7a4ece31ec1752aab0e6caddb Mon Sep 17 00:00:00 2001 From: Marko Saukko Date: Mon, 14 May 2012 20:38:44 +0300 Subject: [PATCH] Move files from /var/run/ to user's home directory. Signed-off-by: Marko Saukko --- doc/singleinstance.dox | 2 +- src/launcherlib/daemon.cpp | 35 +++++++++++-------- src/launcherlib/daemon.h | 4 +-- .../README-QDECLARATIVEBOOSTER | 2 +- src/single-instance/main.cpp | 5 +-- tests/meego/testscripts/utils.py | 2 +- 6 files changed, 28 insertions(+), 22 deletions(-) diff --git a/doc/singleinstance.dox b/doc/singleinstance.dox index ab01de4..d7b5ef6 100644 --- a/doc/singleinstance.dox +++ b/doc/singleinstance.dox @@ -20,7 +20,7 @@ Exec=/usr/bin/invoker --single-instance --type=e /usr/bin/myApp \endverbatim As a result, a lock file -\c /var/run/single-instance-locks/usr/bin/myApp/instance.lock is created. +\c $HOME/.single-instance-locks/usr/bin/myApp/instance.lock is created. If applauncherd cannot acquire the lock, it tries to find the corresponding window and activates it. diff --git a/src/launcherlib/daemon.cpp b/src/launcherlib/daemon.cpp index 9a26a11..f2104ed 100644 --- a/src/launcherlib/daemon.cpp +++ b/src/launcherlib/daemon.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #ifdef HAVE_AEGIS_CRYPTO #include @@ -53,8 +54,9 @@ extern char ** environ; Daemon * Daemon::m_instance = NULL; int Daemon::m_lockFd = -1; const int Daemon::m_boosterSleepTime = 2; -const char *Daemon::m_stateDir = "/var/run/applauncherd"; -const char *Daemon::m_stateFile = "/var/run/applauncherd/saved-state"; + +const std::string Daemon::m_stateDir = std::string(getenv("HOME"))+"/.applauncherd"; +const std::string Daemon::m_stateFile = Daemon::m_stateDir + "/saved-state"; Daemon::Daemon(int & argc, char * argv[]) : m_daemon(false), @@ -116,7 +118,10 @@ bool Daemon::lock() fl.l_start = 0; fl.l_len = 1; - if((m_lockFd = open("/var/run/applauncherd.lock", O_WRONLY | O_CREAT, 0666)) == -1) + std::stringstream lock_file; + lock_file << getenv("HOME") << "/applauncherd.lock"; + + if((m_lockFd = open(lock_file.str().c_str(), O_WRONLY | O_CREAT, 0666)) == -1) return false; if(fcntl(m_lockFd, F_SETLK, &fl) == -1) @@ -849,31 +854,31 @@ void Daemon::reExec() Logger::logInfo("Daemon: Re-exec requested."); struct stat st; - if (stat(m_stateDir, &st) != 0) + if (stat(m_stateDir.c_str(), &st) != 0) { - Logger::logDebug("Daemon: State saving directory %s does not exist", m_stateDir); + Logger::logDebug("Daemon: State saving directory %s does not exist", m_stateDir.c_str()); Logger::logDebug("Daemon: Attempting to create it"); - if (mkdir(m_stateDir, S_IRUSR | S_IWUSR | S_IXUSR) != 0) + if (mkdir(m_stateDir.c_str(), S_IRUSR | S_IWUSR | S_IXUSR) != 0) { Logger::logDebug("Daemon: Failed to create directory, re-exec failed, exiting."); _exit(1); } } - if (stat(m_stateDir, &st) != 0) + if (stat(m_stateDir.c_str(), &st) != 0) { Logger::logDebug("Daemon: Directory vanished, re-exec failed, exiting."); _exit(1); } if (!S_ISDIR(st.st_mode)) { - Logger::logDebug("Daemon: %s exists but it is not a directory, re-exec failed, exiting.", m_stateDir); + Logger::logDebug("Daemon: %s exists but it is not a directory, re-exec failed, exiting.", m_stateDir.c_str()); _exit(1); } try { - std::ofstream ss(m_stateFile); + std::ofstream ss(m_stateFile.c_str()); ss.exceptions (std::ifstream::failbit | std::ifstream::badbit); // dump the pid to double check that the state file is from this process @@ -959,7 +964,7 @@ void Daemon::restoreState() { #ifdef HAVE_AEGIS_CRYPTO aegis_system_mode_t aegisMode; - if (aegis_crypto_verify_aegisfs(m_stateDir, &aegisMode) != 0 + if (aegis_crypto_verify_aegisfs(m_stateDir.c_str(), &aegisMode) != 0 || aegisMode != aegis_system_protected) { #ifndef DEBUG_BUILD @@ -974,7 +979,7 @@ void Daemon::restoreState() try { // We have saved state, try to restore it. - std::ifstream ss(m_stateFile); + std::ifstream ss(m_stateFile.c_str()); ss.exceptions (std::ifstream::failbit | std::ifstream::badbit); std::string token; @@ -1013,9 +1018,9 @@ void Daemon::restoreState() // In debug mode it is better to leave the file there // so it can be examined. - if (!m_debugMode && remove(m_stateFile) == -1) + if (!m_debugMode && remove(m_stateFile.c_str()) == -1) { - Logger::logError("Daemon: could not remove state file %s", m_stateFile); + Logger::logError("Daemon: could not remove state file %s", m_stateFile.c_str()); } Logger::logDebug("Daemon: state restore completed"); return; @@ -1118,9 +1123,9 @@ void Daemon::restoreState() // In debug mode it is better to leave the file there // so it can be examined. - if (!m_debugMode && remove(m_stateFile) == -1) + if (!m_debugMode && remove(m_stateFile.c_str()) == -1) { - Logger::logError("Daemon: could not remove state file %s", m_stateFile); + Logger::logError("Daemon: could not remove state file %s", m_stateFile.c_str()); } // This is only reached if state restore was unsuccessful. diff --git a/src/launcherlib/daemon.h b/src/launcherlib/daemon.h index 42063f0..c506f28 100644 --- a/src/launcherlib/daemon.h +++ b/src/launcherlib/daemon.h @@ -241,8 +241,8 @@ private: bool m_reExec; //! Name of the state saving directory and file - static const char *m_stateDir; - static const char *m_stateFile; + static const std::string m_stateDir; + static const std::string m_stateFile; #ifdef UNIT_TEST friend class Ut_Daemon; diff --git a/src/qdeclarativebooster/README-QDECLARATIVEBOOSTER b/src/qdeclarativebooster/README-QDECLARATIVEBOOSTER index addeb9f..83b8a8e 100644 --- a/src/qdeclarativebooster/README-QDECLARATIVEBOOSTER +++ b/src/qdeclarativebooster/README-QDECLARATIVEBOOSTER @@ -178,7 +178,7 @@ This can be achieved by adding --single-instance to the invoker command: Name=com.nokia. Exec=/usr/bin/invoker --single-instance --type=d /usr/bin/ -As a result, a lock file /var/run/single-instance-locks//instance.lock +As a result, a lock file $HOME/.single-instance-locks//instance.lock is created. If applauncherd cannot acquire the lock, it tries to find the corresponding window and activates it. diff --git a/src/single-instance/main.cpp b/src/single-instance/main.cpp index ac91b2b..9acbbe8 100644 --- a/src/single-instance/main.cpp +++ b/src/single-instance/main.cpp @@ -33,13 +33,14 @@ extern "C" { #include "report.h" } +#include #define DECL_EXPORT extern "C" __attribute__ ((__visibility__("default"))) namespace { int g_lockFd = -1; - const std::string LOCK_PATH_BASE("/var/run/single-instance-locks/"); + const std::string LOCK_PATH_BASE(std::string(getenv("HOME"))+"/.single-instance-locks/"); const std::string LOCK_FILE_NAME("instance.lock"); } @@ -263,7 +264,7 @@ extern "C" * \brief Try to acquire a lock file. * * Tries to acquire a lock currently at - * /var/run/single-instance-locks/[binaryName]/instance.lock + * $HOME/.single-instance-locks/[binaryName]/instance.lock * * \param binaryName Full path to the binary. * \return true if succeeded, false on failure. diff --git a/tests/meego/testscripts/utils.py b/tests/meego/testscripts/utils.py index 72a07df..3ce9c15 100644 --- a/tests/meego/testscripts/utils.py +++ b/tests/meego/testscripts/utils.py @@ -28,7 +28,7 @@ def remove_applauncherd_runtime_files(): Removes files that applauncherd leaves behind after it has been stopped """ - files = ['/var/run/applauncherd.lock'] + files = ["%s/applauncherd.lock" % (os.environ['HOME'])] files += glob.glob('/tmp/boost*') for f in files: