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"
#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;
}
}
-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;
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;
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) {
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;
}
static void* umount_hds(void* args)
{
int ret = 0;
- char* tmp;
int action = 3;
char* tag;
char* path;
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;
}
}
+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)) {
int main( int argc , char *argv[])
{
- int conn_ret = -1;
- int ret = 0;
+ int ret = -1;
init_fd();
exit(0);
}
+ ret = register_connection();
+
send_default_suspend_req();
if (pthread_create(&tid[TID_BOOT], NULL, dbus_booting_done_check, NULL) != 0)
}
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)
{
}
stop_listen();
- if (conn_ret == 1)
+ if (ret == 1)
{
LOGINFO("destroy connection");
destroy_connection();