Redefine the working directory path of the SDB server.
authorKim Gunsoo <gunsoo83.kim@samsung.com>
Mon, 7 Sep 2015 11:06:12 +0000 (20:06 +0900)
committerKim Gunsoo <gunsoo83.kim@samsung.com>
Mon, 7 Sep 2015 11:06:12 +0000 (20:06 +0900)
- A working directory places in the module path of the SDB
  server in Windows OS.

Change-Id: I0ce8167468997378773138d4cd714f9a069a7802
Signed-off-by: Kim Gunsoo <gunsoo83.kim@samsung.com>
src/sdb.c

index b7d7c439cade0b9616a09941815e80d92c055659..ba44497216b22ea866397c0d98cbcd86e1946ce3 100755 (executable)
--- a/src/sdb.c
+++ b/src/sdb.c
@@ -114,6 +114,43 @@ static void init_map() {
 #endif
 }
 
+#ifdef OS_WINDOWS
+void change_working_directory(void)
+{
+    TCHAR currentDir[MAX_PATH] = {0,};
+    TCHAR modulePath[MAX_PATH] = {0,};
+    DWORD dwRet = 0;
+    char* p = NULL;
+
+    dwRet = GetCurrentDirectory(MAX_PATH, currentDir);
+    if (dwRet == 0) {
+        LOG_INFO("GetCurrentDirectory failed (%d)\n", GetLastError());
+        return;
+    }
+    if (dwRet > MAX_PATH) {
+        LOG_INFO("Buffer too small; need %d charactors\n", dwRet);
+        return;
+    }
+    LOG_INFO("Current directory : %s\n", currentDir);
+
+    if (!GetModuleFileName(NULL, modulePath, sizeof(modulePath))) {
+        LOG_INFO("GetModuleFileName failed (%d)\n", GetLastError());
+        return;
+    }
+    LOG_INFO("Module path : %s\n", modulePath);
+
+    p = strrchr(modulePath, '\\');
+    if (p) {
+        p[1] = '\0';
+    }
+
+    if (!SetCurrentDirectory(modulePath)) {
+        LOG_INFO("SetCurrentDirectory failed (%d)\n", GetLastError());
+        return;
+    }
+    LOG_INFO("Set current directory to : %s\n", modulePath);
+}
+#endif
 
 int sdb_main(int is_daemon, int server_port)
 {
@@ -141,6 +178,8 @@ int sdb_main(int is_daemon, int server_port)
     sdb_usb_init();
 
 #ifdef OS_WINDOWS
+    change_working_directory();
+
     sdb_thread_t thr;
     void* (*func)(void *);
     func = local_init_thread;