hds: request default mounted data to ecs 19/41919/1
authorJinhyung Choi <jinhyung2.choi@samsung.com>
Sun, 24 May 2015 10:53:21 +0000 (19:53 +0900)
committerJinhyung Choi <jinhyung2.choi@samsung.com>
Fri, 19 Jun 2015 07:00:18 +0000 (16:00 +0900)
- check specified guest directory
- create directory if it is not available.

Change-Id: I643ff4bb900f01fa3f26d10447789630af59f557
Signed-off-by: Jinhyung Choi <jinhyung2.choi@samsung.com>
include/emuld.h
packaging/emuld.spec
src/common.cpp
src/emuld.cpp

index 7a33d5eceaf7d4ffea3b6108bb64826233069a42..15b9b2c8714cc85364998884c3283d9dcfb5689e 100644 (file)
@@ -194,12 +194,18 @@ void set_vconf_cb(void);
 void send_to_ecs(const char* cat, int group, int action, char* data);
 void send_emuld_connection(void);
 void send_default_suspend_req(void);
+void send_default_mount_req(void);
 void* dbus_booting_done_check(void* data);
 void systemcall(const char* param);
 int parse_val(char *buff, unsigned char data, char *parsbuf);
 
+#define HDS_DEFAULT_ID      "fsdef0"
 #define HDS_DEFAULT_TAG     "fileshare"
 #define HDS_DEFAULT_PATH    "/mnt/host"
+#define COMPAT_DEFAULT_DATA "fileshare\n/mnt/host\n"
+#define HDS_ACTION_DEFAULT  99
+#define MSG_GROUP_HDS       100
+bool valid_hds_path(char* path);
 int try_mount(char* tag, char* path);
 
 #define IJTYPE_SUSPEND      "suspend"
index e3d74bc8629be2d5dd831c5d50da5db848d779db..a32b54299a63a3c15da35a94c60c59aa06e4cac8 100644 (file)
@@ -1,5 +1,5 @@
 Name: emuld
-Version: 0.9.6
+Version: 0.9.7
 Release: 0
 Summary: Emulator daemon
 License: Apache-2.0
@@ -54,9 +54,6 @@ fi
 cp emuld.service %{buildroot}/usr/lib/systemd/system/.
 ln -s ../emuld.service %{buildroot}/usr/lib/systemd/system/emulator.target.wants/emuld.service
 
-# for host file sharing
-mkdir -p %{buildroot}/mnt/host
-
 # for license
 mkdir -p %{buildroot}/usr/share/license
 cp LICENSE %{buildroot}/usr/share/license/%{name}
@@ -81,6 +78,5 @@ chmod 770 %{_prefix}/bin/emuld
 /usr/share/license/%{name}
 /usr/lib/systemd/system/emuld.service
 /usr/lib/systemd/system/emulator.target.wants/emuld.service
-%dir /mnt/host
 
 %changelog
index 575672934f63ab3bfd07e2d82f158644c57e39a4..6bc9aa060047c1bb00b0050bcf5a62b3749ac37f 100644 (file)
@@ -41,6 +41,7 @@
 
 #include <dirent.h>
 #include <sys/stat.h>
+#include <sys/types.h>
 #include <stdlib.h>
 #include <mntent.h>
 
 static pthread_mutex_t mutex_pkg = PTHREAD_MUTEX_INITIALIZER;
 static pthread_mutex_t mutex_cmd = PTHREAD_MUTEX_INITIALIZER;
 
+static const char* hds_available_path [] = {
+    "/mnt/",
+    NULL,
+};
+
 static struct timeval tv_start_poweroff;
 
 static std::multimap<int, std::string> vconf_multimap;
@@ -1297,22 +1303,6 @@ void msgproc_location(ijcommand* ijcmd)
     }
 }
 
-static char* make_header_msg(int group, int action)
-{
-    char *tmp = (char*) malloc(HEADER_SIZE);
-    if (!tmp)
-        return NULL;
-
-    memset(tmp, 0, HEADER_SIZE);
-
-    memcpy(tmp + 2, &group, 1);
-    memcpy(tmp + 3, &action, 1);
-
-    return tmp;
-}
-
-#define MSG_GROUP_HDS   100
-
 int try_mount(char* tag, char* path)
 {
     int ret = 0;
@@ -1345,10 +1335,54 @@ static bool get_tag_path(char* data, char** tag, char** path)
     return true;
 }
 
+static bool secure_hds_path(char* path) {
+    int index = 0;
+    int len = sizeof(hds_available_path);
+    for (index = 0; index < len; index++) {
+        if (!strncmp(path, hds_available_path[index], strlen(hds_available_path[index]))) {
+            return true;
+        }
+    }
+    return false;
+}
+
+bool valid_hds_path(char* path) {
+    struct stat buf;
+    int ret = -1;
+
+    ret = access(path, F_OK);
+    if (ret == -1) {
+        if (errno == ENOENT) {
+            ret = mkdir(path, 0644);
+            if (ret == -1) {
+                LOGERR("failed to create path : %d", errno);
+                return false;
+            }
+        } else {
+            LOGERR("failed to access path : %d", errno);
+            return false;
+        }
+    }
+
+    ret = lstat(path, &buf);
+    if (ret == -1) {
+        LOGERR("lstat is failed to validate path : %d", errno);
+        return false;
+    }
+
+    if (!S_ISDIR(buf.st_mode)) {
+        LOGERR("%s is not a directory.", path);
+        return false;
+    }
+
+    LOGINFO("check '%s' complete.", path);
+
+    return true;
+}
+
 static void* mount_hds(void* args)
 {
     int i, ret = 0;
-    char* tmp;
     int action = 2;
     char* tag;
     char* path;
@@ -1363,10 +1397,26 @@ static void* mount_hds(void* args)
         return NULL;
     }
 
+    if (!strncmp(tag, HDS_DEFAULT_ID, 6)) {
+        free(data);
+        return NULL;
+    }
+
+    if (!secure_hds_path(path)) {
+        send_to_ecs(IJTYPE_HDS, MSG_GROUP_HDS, 11, tag);
+        free(data);
+        return NULL;
+    }
+
+    if (!valid_hds_path(path)) {
+        send_to_ecs(IJTYPE_HDS, MSG_GROUP_HDS, 12, tag);
+        free(data);
+        return NULL;
+    }
+
     LOGINFO("tag : %s, path: %s", tag, path);
-    usleep(50000);
 
-    for (i = 0; i < 20; i++)
+    for (i = 0; i < 10; i++)
     {
         ret = try_mount(tag, path);
         if(ret == 0) {
@@ -1378,17 +1428,9 @@ static void* mount_hds(void* args)
         usleep(500000);
     }
 
-    tmp = make_header_msg(MSG_GROUP_HDS, action);
-    if (!tmp) {
-        LOGERR("failed to alloc: out of resource.");
-        free(data);
-        return NULL;
-    }
-
-    ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_HDS, (const char*) tmp, HEADER_SIZE);
+    send_to_ecs(IJTYPE_HDS, MSG_GROUP_HDS, action, tag);
 
     free(data);
-    free(tmp);
 
     return NULL;
 }
@@ -1396,7 +1438,6 @@ static void* mount_hds(void* args)
 static void* umount_hds(void* args)
 {
     int ret = 0;
-    char* tmp;
     int action = 3;
     char* tag;
     char* path;
@@ -1417,24 +1458,18 @@ static void* umount_hds(void* args)
         action = 4;
     }
 
-    tmp = make_header_msg(MSG_GROUP_HDS, action);
-    if (!tmp) {
-        LOGERR("failed to alloc: out of resource.");
-        free(data);
-        return NULL;
-    }
+    ret = rmdir(path);
+    LOGINFO("remove path result '%d:%d' with %s", ret, errno, path);
 
-    LOGINFO("send result with action %d to evdi", action);
+    send_to_ecs(IJTYPE_HDS, MSG_GROUP_HDS, action, tag);
 
-    ijmsg_send_to_evdi(g_fd[fdtype_device], IJTYPE_HDS, (const char*) tmp, HEADER_SIZE);
+    LOGINFO("send result with action %d to evdi", action);
 
     free(data);
-    free(tmp);
 
     return NULL;
 }
 
-#define COMPAT_DEFAULT_DATA     "fileshare\n/mnt/host\n"
 void msgproc_hds(ijcommand* ijcmd)
 {
     char* data;
@@ -1470,6 +1505,11 @@ void msgproc_hds(ijcommand* ijcmd)
     }
 }
 
+void send_default_mount_req()
+{
+    send_to_ecs(IJTYPE_HDS, 0, 0, NULL);
+}
+
 static void low_memory_cb(keynode_t* pKey, void* pData)
 {
     switch (vconf_keynode_get_type(pKey)) {
index 9f547aaa15b784e014cec1094b3e6ab7c5673ec8..54eaa562323f29630f8484184e303b702bb7350f 100644 (file)
@@ -341,8 +341,7 @@ static bool server_process(void)
 
 int main( int argc , char *argv[])
 {
-    int conn_ret = -1;
-    int ret = 0;
+    int ret = -1;
 
     init_fd();
 
@@ -357,6 +356,8 @@ int main( int argc , char *argv[])
         exit(0);
     }
 
+    ret = register_connection();
+
     send_default_suspend_req();
 
     if (pthread_create(&tid[TID_BOOT], NULL, dbus_booting_done_check, NULL) != 0)
@@ -366,14 +367,20 @@ int main( int argc , char *argv[])
     }
 
     LOGINFO("[START] epoll & device init success");
-    conn_ret = register_connection();
 
-    add_vconf_map_common();
-    add_vconf_map_profile();
-    set_vconf_cb();
+    send_default_mount_req();
 
+    ret = valid_hds_path((char*)HDS_DEFAULT_PATH);
+    LOGINFO("check directory '/mnt/host' for default fileshare: %d", ret);
     ret = try_mount((char*)HDS_DEFAULT_TAG, (char*)HDS_DEFAULT_PATH);
     LOGINFO("try mount /mnt/host for default fileshare: %d", ret);
+    if (ret == 0) {
+        send_to_ecs(IJTYPE_HDS, MSG_GROUP_HDS, HDS_ACTION_DEFAULT, (char*)HDS_DEFAULT_TAG);
+    }
+
+    add_vconf_map_common();
+    add_vconf_map_profile();
+    set_vconf_cb();
 
     while(!exit_flag)
     {
@@ -381,7 +388,7 @@ int main( int argc , char *argv[])
     }
 
     stop_listen();
-    if (conn_ret == 1)
+    if (ret == 1)
     {
         LOGINFO("destroy connection");
         destroy_connection();