fix getting user_runtime_dir for dbus
authorWonYoung Choi <wy80.choi@samsung.com>
Tue, 18 Aug 2015 06:27:13 +0000 (15:27 +0900)
committerWonYoung Choi <wy80.choi@samsung.com>
Tue, 18 Aug 2015 06:27:13 +0000 (15:27 +0900)
Change-Id: Ibf121f7f1af21d3a6328dfa8d3d6bd7c63808ffc

src/common/dbus_client.cc
src/common/dbus_server.cc
src/common/file_utils.cc
src/common/file_utils.h

index c82337f..a7bdbb3 100755 (executable)
@@ -17,6 +17,7 @@
 #include "common/dbus_client.h"
 
 #include "common/logger.h"
+#include "common/file_utils.h"
 
 namespace wrt {
 
@@ -52,7 +53,7 @@ DBusClient::~DBusClient() {
 
 bool DBusClient::ConnectByName(const std::string& name) {
   std::string address("unix:path=");
-  address.append(g_get_user_runtime_dir());
+  address.append(utils::GetUserRuntimeDir());
   address.append("/.");
   address.append(name);
   return Connect(address);
index d6f770b..c663b6e 100755 (executable)
@@ -17,6 +17,7 @@
 #include "common/dbus_server.h"
 
 #include "common/logger.h"
+#include "common/file_utils.h"
 
 namespace wrt {
 
@@ -184,7 +185,7 @@ void DBusServer::Start(const std::string& name) {
   GError* err = NULL;
 
   address_path_.clear();
-  address_path_.append(g_get_user_runtime_dir());
+  address_path_.append(utils::GetUserRuntimeDir());
   address_path_.append("/.");
   address_path_.append(name);
   // unlink existing bus address
index bbfc443..6cf7bdb 100755 (executable)
 
 #include <unistd.h>
 #include <libgen.h>
+#include <sys/types.h>
+
 #include <string>
+#include <sstream>
 #include <algorithm>
 
 namespace wrt {
@@ -58,5 +61,16 @@ std::string ExtName(const std::string& path) {
   }
 }
 
+std::string GetUserRuntimeDir() {
+  uid_t uid = getuid();
+  std::stringstream ss;
+  ss << "/run/user/" << uid;
+  std::string path = ss.str();
+  if (!Exists(path)) {
+    path = "/tmp";
+  }
+  return path;
+}
+
 }  // namespace utils
 }  // namespace wrt
index d7d5565..d5fd344 100755 (executable)
@@ -32,6 +32,7 @@ std::string SchemeName(const std::string& uri);
 
 std::string ExtName(const std::string& path);
 
+std::string GetUserRuntimeDir();
 
 }  // namespace utils
 }  // namespace wrt