Update to use the information of mused.conf 74/111574/13
authorYoungHun Kim <yh8004.kim@samsung.com>
Mon, 23 Jan 2017 01:49:48 +0000 (10:49 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Tue, 24 Jan 2017 02:06:23 +0000 (11:06 +0900)
Change-Id: I000abcd7220e0b976283342739000766905a8f43

12 files changed:
include/muse_core.h
include/muse_core_config.h
include/muse_core_internal.h
include/muse_core_module.h
src/muse_core.c
src/muse_core_config.c
src/muse_core_ipc.c
src/muse_core_log.c
src/muse_core_module.c
src/muse_core_security.c
src/muse_core_server.c
src/muse_core_signal.c

index 2713f89..41cf7d3 100644 (file)
@@ -45,6 +45,8 @@ typedef enum {
 
 int muse_core_run(void);
 void muse_core_cmd_dispatch(muse_module_h module, muse_module_command_e cmd);
+void muse_core_set_dispatch_timeout(muse_module_h module, int disp_api, int timeout);
+int muse_core_get_dispatch_timeout(muse_module_h module, int disp_api);
 void muse_core_connection_close(int sock_fd);
 int muse_core_client_new(void);
 int muse_core_client_new_data_ch(void);
@@ -65,6 +67,7 @@ void *muse_core_msg_object_new(char *str, int *parse_len, void *err);
 bool muse_core_msg_object_get_value(void *msg_obj, const char *key, int m_type, void *data);
 void muse_core_msg_object_free(void *msg_obj);
 void muse_core_respawn(int signo);
+int  muse_core_get_api_module(char *module_name, int *api_module);
 
 #ifdef __cplusplus
 }
index b5bae7c..42e7538 100644 (file)
@@ -30,31 +30,40 @@ extern "C" {
 #include "muse_core_module.h"
 
 #define CONFFILE SYSCONFDIR"/multimedia/mused.conf"
-#define HOST_MAX_COUNT 1024
-#define MUSE_MAX_PARAM_NUM 10
 #define MUSEHOST "muse:hosts"
 #define MUSELOG "muse:logfile"
+#define MUSELOCK "muse:lockfile"
+#define MUSEREADY "muse:muse_server_ready"
+#define MUSEMINTIMEOUT "muse:min_timeout"
+#define MUSEMAXTIMEOUT "muse:max_timeout"
 #define MUSEGST "muse:gstparam"
 #define COLON ":"
 #define COMMA ","
 #define PATH "path"
 #define PRELOADED "preloaded"
+#define TIMEOUT "timeout"
 
 typedef struct host_info
 {
        char *path;
        char *preloaded;
+       int timeout;
 } host_info_t;
 
 typedef struct muse_core_config
 {
        char *hosts;
-       char *host[MUSE_MODULE_MAX];
-       int type;
+       char *host[MUSE_MAX_MODULE_NUM];
+       int host_cnt;
        char *logfile;
+       char *lockfile;
+       char *muse_server_ready;
+       int min_timeout;
+       int max_timeout;
+
        char *gst_param_str[MUSE_MAX_PARAM_NUM];
        int gst_param_cnt;
-       host_info_t *host_infos[HOST_MAX_COUNT];
+       host_info_t *host_infos[MUSE_MAX_MODULE_NUM];
        dictionary *muse_dict;
        void (*free)(void);
        char* (*get_path)(int);
@@ -65,7 +74,6 @@ typedef struct muse_core_config
        int (*get_host_cnt)(void);
 } muse_core_config_t;
 
-/*muse_core_config_init must be called before muse_core_config_get_instance*/
 muse_core_config_t *muse_core_config_get_instance(void);
 void muse_core_config_init(void);
 
index cc538e4..79de47e 100644 (file)
@@ -75,34 +75,32 @@ extern "C" {
 
 #undef LOG_TAG
 #define LOG_TAG "TIZEN_N_MUSED"
-#define LOGFILE "/var/log/mused/muse-server"
-#define LOCKFILE "/tmp/.muse_core.lock"
-#define SOCKFILE0 "/tmp/.muse_core_socket"
-#define SOCKFILE1 "/tmp/.muse_core_data_socket"
-#define MUSE_SERVER_READY "/tmp/.muse_server_ready"
-#define MUSE_DEFAULT_PIDFILE "/tmp/.muse-server.pid"
 #define MUSE_DATA_ROOT_PATH TZ_SYS_DATA_PATH"/mused/"
-
-#ifdef MUSE_USE_LOG
-#define MUSE_TIMEOUT_SEC 30
-#define MUSE_TIMEOUT_MSEC 30000
-#else
-#define MUSE_TIMEOUT_SEC 90
-#define MUSE_TIMEOUT_MSEC 90000
-#endif
+#define MUSE_DEFAULT_PIDFILE "/tmp/.muse-server.pid"
+#define MUSE_SOCK_FILE0 "/tmp/.muse_core_socket"
+#define MUSE_SOCK_FILE1 "/tmp/.muse_core_data_socket"
 
 #define READ 0x02
 #define PERSIST 0x10
-#define MUSE_MAX_ERROR_MSG_LEN 256
-#define MUSE_MAX_PARAM_STRLEN 256
-#define MUSE_TUNABLE_CALLER_DEPTH 32
+
+#define MUSE_ERR -1
+#define MUSE_MAX_PARAM_NUM 10
+
+/* message */
 #define MUSE_MSG_LEN 32
+#define MUSE_MAX_MSG_LEN 256
+
+/* module */
+#define MUSE_MAX_MODULE_NUM 10
+
+/* dispatcher */
+#define MUSE_MAX_DISPATCHER_NUM 256
 
-#define SOCK_ERR -1
 #define DISPATCHER "dispatcher"
 #define DISPATCHER_PTR "dispatcher_pointer"
 #define CMD_DISPATCHER "cmd_dispatcher"
 #define END_DELIM '}'
+#define END_DELIM_STR " }"
 
 #define MUSE_FREE(src) \
        do { \
index affc790..714c903 100644 (file)
@@ -35,7 +35,6 @@ typedef enum {
        MUSE_PLAYER,
        MUSE_CAMERA,
        MUSE_RECORDER,
-       MUSE_SOUND,
        MUSE_DRM,
        MUSE_MODULE_MAX
 } muse_core_api_module_e;
@@ -49,12 +48,15 @@ typedef struct muse_core_module {
        GModule* (*get_dllsymbol_value) (int);
        void (*set_value) (int, const char *, gpointer);
        int (*get_value) (int, const char *, gpointer *);
+       void (*set_timeout) (int, int, int);
+       int (*get_timeout) (int, int);
        void (*free) (void);
-       GMutex module_lock[MUSE_MODULE_MAX];
-       gboolean module_loaded[MUSE_MODULE_MAX];
-       GModule *module[MUSE_MODULE_MAX];
-       GHashTable *table[MUSE_MODULE_MAX];
+       GMutex module_lock[MUSE_MAX_MODULE_NUM];
+       gboolean module_loaded[MUSE_MAX_MODULE_NUM];
+       GModule *module[MUSE_MAX_MODULE_NUM];
+       GHashTable *table[MUSE_MAX_MODULE_NUM];
        int api_module;
+       int disp_timeout[MUSE_MAX_MODULE_NUM][MUSE_MAX_DISPATCHER_NUM];
 } muse_core_module_t;
 
 muse_core_module_t *muse_core_module_get_instance(void);
index d60678d..8601254 100644 (file)
 #define MUSE_LWIPC_WAIT_TIME 1000
 #endif
 
-#define MUSE_LOG_SLEEP_TIMER 10
-#define END_DELIM_STR " }"
-#define MUSE_WATCHDOG_TIMEOUT_SEC 30
-
 static GMainLoop *g_loop;
 static GThread *g_thread;
-static const char *UDS_files[MUSE_CHANNEL_MAX] = {SOCKFILE0, SOCKFILE1};
+static const char *UDS_files[MUSE_CHANNEL_MAX] = {MUSE_SOCK_FILE0, MUSE_SOCK_FILE1};
 
 static gboolean (*job_functions[MUSE_CHANNEL_MAX])
        (muse_core_workqueue_job_t *job) = {
@@ -66,12 +62,12 @@ static int _muse_core_client_new(muse_core_channel_e channel);
 static int _muse_core_set_nonblocking(int fd, bool value)
 {
        int flags = fcntl(fd, F_GETFL, NULL);
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
 
        if (flags >= 0) {
                flags = value ? (flags | O_NONBLOCK) : (flags & ~O_NONBLOCK);
                if (fcntl(fd, F_SETFL, flags) == -1) {
-                       strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+                       strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                        LOGE("fcntl (%d, F_SETFL, %d) %s", fd, flags, err_msg);
                        return MM_ERROR_FILE_INTERNAL;
                } else {
@@ -91,11 +87,11 @@ static int _muse_core_check_server_is_running(void)
        int ret = -1;
 
        /* First, check whether the existing file is locked. */
-       fd = open(LOCKFILE, O_RDONLY);
+       fd = open(muse_core_config_get_instance()->lockfile, O_RDONLY);
        if (fd == -1 && errno != ENOENT) {
                /* Cannot open file, but it's not because the file doesn't exist. */
                char msg[1024];
-               snprintf(msg, sizeof(msg), "datserver: Cannot open lock file %s", LOCKFILE);
+               snprintf(msg, sizeof(msg), "datserver: Cannot open lock file %s", muse_core_config_get_instance()->lockfile);
                LOGE("open failed: %s ", msg);
                return ret;
        } else if (fd != -1) {
@@ -108,14 +104,14 @@ static int _muse_core_check_server_is_running(void)
        }
 
        /* Lock file does not exist, or is not locked. Create a new lockfile and lock it. */
-       fd = open(LOCKFILE, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
+       fd = open(muse_core_config_get_instance()->lockfile, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
        if (fd == -1) {
                LOGE("dataserver: Cannot create lock file");
                return ret;
        }
 
        if (flock(fd, LOCK_EX | LOCK_NB) != 0) {
-               LOGE("Can't lock the lock file \"%s\". " "Is another instance running?", LOCKFILE);
+               LOGE("Can't lock the lock file \"%s\". " "Is another instance running?", muse_core_config_get_instance()->lockfile);
                close(fd);
                return ret;
        }
@@ -197,7 +193,7 @@ static int _muse_core_free(muse_core_t *server)
                close(server->data_fd);
        for (i = 0; i < MUSE_CHANNEL_MAX; i++)
                remove(UDS_files[i]);
-       remove(LOCKFILE);
+       remove(muse_core_config_get_instance()->lockfile);
        remove(MUSE_DEFAULT_PIDFILE);
        MUSE_FREE(server);
        muse_core_workqueue_get_instance()->shutdown();
@@ -219,7 +215,7 @@ static int _muse_core_server_new(muse_core_channel_e channel)
        int fd;
        struct sockaddr_un addr_un;
        socklen_t address_len;
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
 
        g_return_val_if_fail(channel < MUSE_CHANNEL_MAX, MM_ERROR_INVALID_ARGUMENT);
 
@@ -228,9 +224,9 @@ static int _muse_core_server_new(muse_core_channel_e channel)
        /* Create Socket */
        fd = socket(AF_UNIX, SOCK_STREAM, 0); /* Unix Domain Socket */
        if (fd < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("socket failed sock: %s", err_msg);
-               return SOCK_ERR;
+               return MUSE_ERR;
        } else {
                LOGD("muse server fd : %d", fd);
        }
@@ -242,19 +238,19 @@ static int _muse_core_server_new(muse_core_channel_e channel)
 
        /* Bind to filename */
        if (bind(fd, (struct sockaddr *)&addr_un, sizeof(addr_un)) < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("socket bind failed : %s", err_msg);
                if (errno == EADDRINUSE)
                        unlink(addr_un.sun_path);
                close(fd);
-               return SOCK_ERR;
+               return MUSE_ERR;
        }
 
        /* Setup listen queue */
-       if (listen(fd, 5) == SOCK_ERR) {
+       if (listen(fd, 5) == MUSE_ERR) {
                LOGE("listen failed");
                close(fd);
-               return SOCK_ERR;
+               return MUSE_ERR;
        }
 
        if (_muse_core_set_nonblocking(fd, false) < 0) /* blocking */
@@ -269,7 +265,7 @@ static gboolean _muse_core_connection_handler(GIOChannel *source, GIOCondition c
        socklen_t client_len;
        struct sockaddr_un client_address;
        muse_core_channel_e channel = (muse_core_channel_e)data;
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
        muse_module_h module = NULL;
        muse_core_workqueue_job_t *job = NULL;
 
@@ -279,8 +275,8 @@ static gboolean _muse_core_connection_handler(GIOChannel *source, GIOCondition c
 
        client_len = sizeof(client_address);
        client_sockfd = accept(server_sockfd, (struct sockaddr *)&client_address, &client_len);
-       if (client_sockfd == SOCK_ERR) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+       if (client_sockfd == MUSE_ERR) {
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("[Critical Error] accept failure : %s", err_msg);
                muse_core_respawn(SIGTERM);
                return FALSE;
@@ -327,23 +323,23 @@ out:
 static int _muse_core_client_new(muse_core_channel_e channel)
 {
        struct sockaddr_un address;
-       int len, ret = SOCK_ERR;
+       int len, ret = MUSE_ERR;
        int sockfd;
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
 
        LOGI("Enter");
        g_return_val_if_fail(channel < MUSE_CHANNEL_MAX, MM_ERROR_INVALID_ARGUMENT);
 
        /*Create socket*/
        if ((sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("[socket failure] sock: %s", err_msg);
                return ret;
        }
        LOGI("sockfd: %d", sockfd);
 
        if (fcntl(sockfd, F_SETFD, FD_CLOEXEC) < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("unable to set on ctrls socket fd %d: %s", sockfd, err_msg);
                close(sockfd);
                return ret;
@@ -359,7 +355,7 @@ static int _muse_core_client_new(muse_core_channel_e channel)
                LOGE("Error - fd (%d) set blocking", sockfd);
 
        if ((ret = connect(sockfd, (struct sockaddr *)&address, len)) < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("[Critical Error] connect failure : %s", err_msg);
                close(sockfd);
                return ret;
@@ -449,14 +445,14 @@ int muse_core_run()
 #ifdef MUSE_USE_LWIPC
        _muse_core_wait_event();
 
-       if (LwipcEventDone(MUSE_SERVER_READY) < 0)
+       if (LwipcEventDone(muse_core_config_get_instance()->muse_server_ready) < 0)
                LOGE("Fail to send server ready done event");
 #else
-       if ((ready_fd = creat(MUSE_SERVER_READY, 0644)) != -1) {
-               LOGD("MUSE_SERVER_READY(%s) file was created", MUSE_SERVER_READY);
+       if ((ready_fd = creat(muse_core_config_get_instance()->muse_server_ready, 0644)) != -1) {
+               LOGD("MUSE_SERVER_READY(%s) file was created", muse_core_config_get_instance()->muse_server_ready);
                close(ready_fd);
        } else {
-               LOGE("Fail to create MUSE_SERVER_READY(%s)", MUSE_SERVER_READY);
+               LOGE("Fail to create MUSE_SERVER_READY(%s)", muse_core_config_get_instance()->muse_server_ready);
        }
 #endif
 
@@ -486,6 +482,20 @@ void muse_core_cmd_dispatch(muse_module_h module, muse_module_command_e cmd)
        }
 }
 
+void muse_core_set_dispatch_timeout(muse_module_h module, int disp_api, int timeout)
+{
+       g_return_if_fail(module);
+
+       muse_core_module_get_instance()->set_timeout(module->api_module, disp_api, timeout);
+}
+
+int muse_core_get_dispatch_timeout(muse_module_h module, int disp_api)
+{
+       g_return_val_if_fail(module, MUSE_ERR);
+
+       return muse_core_module_get_instance()->get_timeout(module->api_module, disp_api);
+}
+
 int muse_core_client_new(void)
 {
        return _muse_core_client_new(MUSE_CHANNEL_MSG);
@@ -558,17 +568,17 @@ int muse_core_client_get_value(muse_module_h module, const char *value_name, int
 
 void muse_core_connection_close(int sock_fd)
 {
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
 
        g_return_if_fail(muse_core_ipc_fd_is_valid(sock_fd));
 
-       if (shutdown(sock_fd, SHUT_RDWR) == SOCK_ERR) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+       if (shutdown(sock_fd, SHUT_RDWR) == MUSE_ERR) {
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("[%d] failed to shutdown %s", sock_fd, err_msg);
        }
 
-       if (close(sock_fd) == SOCK_ERR) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+       if (close(sock_fd) == MUSE_ERR) {
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("[%d] failed to close %s", sock_fd, err_msg);
        }
 
@@ -627,15 +637,15 @@ bool muse_core_check_msg_complete(char *msg)
 void muse_core_log_process_info(int pid)
 {
        FILE *fp;
-       char cmd[MUSE_MAX_PARAM_STRLEN];
-       char buf[MUSE_MAX_PARAM_STRLEN];
+       char cmd[MUSE_MAX_MSG_LEN];
+       char buf[MUSE_MAX_MSG_LEN];
 
        snprintf(cmd, sizeof(cmd), "ps -Lo pcpu,pmem,tid,comm -p %d", (int)pid);
 
        fp = popen(cmd, "r");
 
        if (fp) {
-               while (fgets(buf, MUSE_MAX_PARAM_STRLEN, fp))
+               while (fgets(buf, MUSE_MAX_MSG_LEN, fp))
                        LOGD("%s", buf);
 
                if (pclose(fp) == -1)
@@ -668,3 +678,21 @@ void muse_core_respawn(int signo)
        LOGE("send %d process signal %d", (int)pid, signo);
        kill(pid, signo);
 }
+
+int  muse_core_get_api_module(char *module_name, int *api_module)
+{
+       int idx;
+       g_return_val_if_fail(module_name, MM_ERROR_INVALID_ARGUMENT);
+       g_return_val_if_fail(api_module, MM_ERROR_INVALID_ARGUMENT);
+
+       for (idx = 0; idx < muse_core_config_get_instance()->host_cnt; idx++) {
+               if (strncmp(module_name, muse_core_config_get_instance()->host[idx], strlen(muse_core_config_get_instance()->host[idx])) == 0) {
+                       *api_module = idx;
+                       break;
+               }
+       }
+
+       g_return_val_if_fail(idx < muse_core_config_get_instance()->host_cnt, MM_ERROR_NOT_IMPLEMENTED);
+
+       return MM_ERROR_NONE;
+}
index 6ddeff4..2ae8076 100644 (file)
@@ -40,6 +40,7 @@ static int _muse_core_config_parser(void)
        char *host;
        char *str;
        int idx;
+       int host_cnt;
        char *ptr = NULL;
 
        g_return_val_if_fail(g_muse_core_conf, PARSE_ERROR);
@@ -75,10 +76,66 @@ static int _muse_core_config_parser(void)
                return PARSE_ERROR;
        }
 
+       str = iniparser_getstring(g_muse_core_conf->muse_dict, MUSELOCK, NULL);
+       if (!str) {
+               LOGE("Error - iniparser_getstring (%s)", MUSELOCK);
+               _muse_core_config_free();
+               return PARSE_ERROR;
+       }
+
+       g_muse_core_conf->lockfile = strdup(str);
+       if (!g_muse_core_conf->lockfile) {
+               LOGE("Error - lockfile allocation");
+               _muse_core_config_free();
+               return PARSE_ERROR;
+       }
+
+       str = iniparser_getstring(g_muse_core_conf->muse_dict, MUSEREADY, NULL);
+       if (!str) {
+               LOGE("Error - iniparser_getstring (%s)", MUSEREADY);
+               _muse_core_config_free();
+               return PARSE_ERROR;
+       }
+
+       g_muse_core_conf->muse_server_ready = strdup(str);
+       if (!g_muse_core_conf->muse_server_ready) {
+               LOGE("Error - muse_server_ready allocation");
+               _muse_core_config_free();
+               return PARSE_ERROR;
+       }
+
+       str = iniparser_getstring(g_muse_core_conf->muse_dict, MUSEMINTIMEOUT, NULL);
+       if (!str) {
+               LOGE("Error - iniparser_getstring (%s)", MUSEMINTIMEOUT);
+               _muse_core_config_free();
+               return PARSE_ERROR;
+       }
+
+       g_muse_core_conf->min_timeout = atoi(strdup(str));
+       if (!g_muse_core_conf->min_timeout) {
+               LOGE("Error - Get minimum timeout");
+               _muse_core_config_free();
+               return PARSE_ERROR;
+       }
+
+       str = iniparser_getstring(g_muse_core_conf->muse_dict, MUSEMAXTIMEOUT, NULL);
+       if (!str) {
+               LOGE("Error - iniparser_getstring (%s)",MUSEMAXTIMEOUT);
+               _muse_core_config_free();
+               return PARSE_ERROR;
+       }
+
+       g_muse_core_conf->max_timeout = atoi(strdup(str));
+       if (!g_muse_core_conf->max_timeout) {
+               LOGE("Error - Get maximum timeout");
+               _muse_core_config_free();
+               return PARSE_ERROR;
+       }
+
        g_muse_core_conf->gst_param_cnt = 0;
-       for (idx = 0 ; idx < MUSE_MAX_PARAM_NUM; idx++) {
-               char gst_param_value[MUSE_MAX_PARAM_STRLEN];
-               memset(gst_param_value, 0, MUSE_MAX_PARAM_STRLEN);
+       for (idx = 0 ; idx < muse_core_config_get_instance()->host_cnt; idx++) {
+               char gst_param_value[MUSE_MAX_MSG_LEN];
+               memset(gst_param_value, 0, MUSE_MAX_MSG_LEN);
                snprintf(gst_param_value, strlen(MUSEGST) + 2, "%s%d", MUSEGST, idx + 1);
 
                str = iniparser_getstring(g_muse_core_conf->muse_dict, gst_param_value, NULL);
@@ -97,14 +154,15 @@ static int _muse_core_config_parser(void)
                LOGD("gstparam%d: %s", (g_muse_core_conf->gst_param_cnt)++, g_muse_core_conf->gst_param_str[idx]);
        }
 
-       g_muse_core_conf->type = 0;
+       g_muse_core_conf->host_cnt = 0;
        host = strtok_r(g_muse_core_conf->hosts, COMMA, &ptr);
 
        while (host) {
+               host_cnt = g_muse_core_conf->host_cnt;
                g_strstrip(host);
-               g_muse_core_conf->host[g_muse_core_conf->type] = strdup(host);
-               LOGD("host: %s", g_muse_core_conf->host[g_muse_core_conf->type]);
-               char *host_name = (char *) malloc(HOST_MAX_COUNT);
+               g_muse_core_conf->host[host_cnt] = strdup(host);
+               LOGD("host: %s", g_muse_core_conf->host[host_cnt]);
+               char *host_name = (char *) malloc(MUSE_MAX_MSG_LEN);
                if (!host_name) {
                        LOGE("Error - null host_name");
                        _muse_core_config_free();
@@ -115,42 +173,62 @@ static int _muse_core_config_parser(void)
                strncpy(host_name, host, strlen(host) + 1);
                strncat(host_name, COLON, strlen(COLON));
                strncat(host_name, PATH, strlen(PATH));
-               g_strstrip(host_name); /*Removes leading and trailing whitespace from a string*/
+               g_strstrip(host_name);
 
-               g_muse_core_conf->host_infos[g_muse_core_conf->type] = (host_info_t *) malloc(sizeof(host_info_t));
-               if (!g_muse_core_conf->host_infos[g_muse_core_conf->type]) {
+               g_muse_core_conf->host_infos[host_cnt] = (host_info_t *) malloc(sizeof(host_info_t));
+               if (!g_muse_core_conf->host_infos[host_cnt]) {
                        LOGE("Error - null type");
                        _muse_core_config_free();
                        MUSE_FREE(host_name);
                        return PARSE_ERROR;
                }
 
-               g_muse_core_conf->host_infos[g_muse_core_conf->type]->path = strdup(iniparser_getstring(g_muse_core_conf->muse_dict, host_name, NULL));
-               if (!g_muse_core_conf->host_infos[g_muse_core_conf->type]->path) {
+               g_muse_core_conf->host_infos[host_cnt]->path =
+                       strdup(iniparser_getstring(g_muse_core_conf->muse_dict, host_name, NULL));
+               if (!g_muse_core_conf->host_infos[host_cnt]->path) {
                        LOGE("Error - null path");
                        _muse_core_config_free();
                        MUSE_FREE(host_name);
                        return PARSE_ERROR;
                }
 
-               LOGD("[%d] %s", g_muse_core_conf->type, g_muse_core_conf->host_infos[g_muse_core_conf->type]->path);
+               LOGD("[%d] %s", host_cnt, g_muse_core_conf->host_infos[host_cnt]->path);
 
-               /* path */
+               /* preloaded */
                strncpy(host_name, host, strlen(host) + 1);
                strncat(host_name, COLON, strlen(COLON));
                strncat(host_name, PRELOADED, strlen(PRELOADED));
-               g_strstrip(host_name); /*Removes leading and trailing whitespace from a string*/
+               g_strstrip(host_name);
 
-               g_muse_core_conf->host_infos[g_muse_core_conf->type]->preloaded= strdup(iniparser_getstring(g_muse_core_conf->muse_dict, host_name, NULL));
-               if (!g_muse_core_conf->host_infos[g_muse_core_conf->type]->preloaded) {
+               g_muse_core_conf->host_infos[host_cnt]->preloaded =
+                       strdup(iniparser_getstring(g_muse_core_conf->muse_dict, host_name, NULL));
+               if (!g_muse_core_conf->host_infos[host_cnt]->preloaded) {
                        LOGE("Error - null preloaded");
                        _muse_core_config_free();
                        MUSE_FREE(host_name);
                        return PARSE_ERROR;
                }
 
+               /* timeout */
+               strncpy(host_name, host, strlen(host) + 1);
+               strncat(host_name, COLON, strlen(COLON));
+               strncat(host_name, TIMEOUT, strlen(TIMEOUT));
+               g_strstrip(host_name);
+
+               g_muse_core_conf->host_infos[host_cnt]->timeout =
+                       atoi(strdup(iniparser_getstring(g_muse_core_conf->muse_dict, host_name, NULL)));
+               if (g_muse_core_conf->host_infos[host_cnt]->timeout < g_muse_core_conf->min_timeout ||
+                       g_muse_core_conf->host_infos[host_cnt]->timeout > g_muse_core_conf->max_timeout) {
+                       LOGE("Error - set timeout value [%d] ( %d ~ %d s )",
+                               g_muse_core_conf->host_infos[host_cnt]->timeout,
+                               g_muse_core_conf->min_timeout, g_muse_core_conf->max_timeout);
+                       _muse_core_config_free();
+                       return PARSE_ERROR;
+               }
+
+
                host = strtok_r(NULL, COMMA, &ptr);
-               g_muse_core_conf->type++;
+               g_muse_core_conf->host_cnt++;
                MUSE_FREE(host_name);
        }
 
@@ -169,21 +247,25 @@ static void _muse_core_config_free(void)
                iniparser_freedict(g_muse_core_conf->muse_dict);
 
        host = strtok_r(g_muse_core_conf->hosts, COMMA, &ptr);
-       g_muse_core_conf->type = 0;
+       g_muse_core_conf->host_cnt = 0;
 
        while (host) {
                LOGD("host: %s", host);
-               MUSE_FREE(g_muse_core_conf->host_infos[g_muse_core_conf->type]->path);
-               MUSE_FREE(g_muse_core_conf->host_infos[g_muse_core_conf->type]->preloaded);
-               MUSE_FREE(g_muse_core_conf->host_infos[g_muse_core_conf->type]);
+               MUSE_FREE(g_muse_core_conf->host_infos[g_muse_core_conf->host_cnt]->path);
+               MUSE_FREE(g_muse_core_conf->host_infos[g_muse_core_conf->host_cnt]->preloaded);
+               MUSE_FREE(g_muse_core_conf->host_infos[g_muse_core_conf->host_cnt]);
                host = strtok_r(NULL, COMMA, &ptr);
-               g_muse_core_conf->type++;
+               g_muse_core_conf->host_cnt++;
        }
+
        MUSE_FREE(g_muse_core_conf->hosts);
-       for (i = 0; i <= g_muse_core_conf->type; i++)
+       for (i = 0; i <= g_muse_core_conf->host_cnt; i++)
                MUSE_FREE(g_muse_core_conf->host[i]);
 
        MUSE_FREE(g_muse_core_conf->logfile);
+       MUSE_FREE(g_muse_core_conf->lockfile);
+       MUSE_FREE(g_muse_core_conf->muse_server_ready);
+
        for (i = 0; i <= g_muse_core_conf->gst_param_cnt; i++)
                MUSE_FREE(g_muse_core_conf->gst_param_str[i]);
 
@@ -199,10 +281,7 @@ static void _muse_core_config_init_instance(void (*free)(void), char* (*get_path
 
        g_muse_core_conf = calloc(1, sizeof(*g_muse_core_conf));
        g_return_if_fail(g_muse_core_conf);
-       g_muse_core_conf->hosts = NULL;
-       g_muse_core_conf->type = 0;
-       g_muse_core_conf->logfile = NULL;
-       g_muse_core_conf->muse_dict = NULL;
+
        g_muse_core_conf->free = free;
        g_muse_core_conf->get_path = get_path;
        g_muse_core_conf->get_preloaded = get_preloaded;
@@ -225,7 +304,7 @@ static char *_muse_core_config_get_host(int index)
 static int _muse_core_config_get_host_cnt(void)
 {
        g_return_val_if_fail(g_muse_core_conf, 0);
-       return g_muse_core_conf->type;
+       return g_muse_core_conf->host_cnt;
 }
 
 static int _muse_core_config_get_gst_param_cnt(void)
index 4d42f2a..52e970f 100644 (file)
@@ -98,9 +98,9 @@ static gpointer _muse_core_ipc_dispatch_worker(gpointer data)
        muse_module_h module = NULL;
        gboolean value = TRUE;
        void *jobj = NULL;
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
        g_return_val_if_fail(data, NULL);
-       int tbm_fd[MUSE_NUM_FD] = { SOCK_ERR, };
+       int tbm_fd[MUSE_NUM_FD] = { MUSE_ERR, };
        module = (muse_module_h)data;
        g_return_val_if_fail(module, NULL);
 
@@ -110,7 +110,7 @@ static gpointer _muse_core_ipc_dispatch_worker(gpointer data)
                memset(module->recvMsg, 0x00, sizeof(module->recvMsg));
                len = muse_core_ipc_recv_fd_msg(module->ch[MUSE_CHANNEL_MSG].fd, module->recvMsg, tbm_fd);
                if (len <= 0) {
-                       strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+                       strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                        LOGE("[%s] [%d] recv : %s (%d)",
                                muse_core_config_get_instance()->get_host(module->api_module), module->ch[MUSE_CHANNEL_MSG].fd, err_msg, errno);
                        muse_core_cmd_dispatch(module, MUSE_MODULE_COMMAND_SHUTDOWN);
@@ -138,7 +138,7 @@ static gpointer _muse_core_ipc_dispatch_worker(gpointer data)
                                                        module->is_create_api_called = true;
                                                        module->ch[MUSE_CHANNEL_MSG].dll_handle = muse_core_module_get_instance()->load(api_module);
 #ifndef MUSE_USE_LWIPC
-                                                       if (access(MUSE_SERVER_READY, F_OK) == 0)
+                                                       if (access(muse_core_config_get_instance()->muse_server_ready, F_OK) == 0)
 #endif
                                                                muse_core_cmd_dispatch(module, MUSE_MODULE_COMMAND_CREATE_SERVER_ACK);
                                                        module->ch[MUSE_CHANNEL_DATA].queue = g_queue_new();
@@ -206,7 +206,7 @@ static gpointer _muse_core_ipc_data_worker(gpointer data)
        void *jobj = NULL;
        intptr_t module_addr = 0;
        muse_recv_data_t *qdata = NULL;
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
        g_return_val_if_fail(fd > 0, NULL);
 
        LOGD("Enter");
@@ -226,7 +226,7 @@ static gpointer _muse_core_ipc_data_worker(gpointer data)
                LOGI("buff %p, recv_len %d, cur_len %d, alloc_size %d", recv_buf, recv_len, cur_len, alloc_size);
                if (recv_len <= 0) {
                        if (recv_len != 0) {
-                               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+                               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                                LOGE("[%d] recv : %s (%d)", fd, err_msg, errno);
                        }
                        break;
@@ -494,7 +494,7 @@ static int _muse_core_ipc_get_valid_fd_count(int *fds)
 {
        int idx;
        for (idx = 0; idx < MUSE_NUM_FD; idx++) {
-               if (fds[idx] == SOCK_ERR)
+               if (fds[idx] == MUSE_ERR)
                        break;
        }
        return idx;
@@ -580,7 +580,7 @@ int muse_core_ipc_send_fd_msg(int sock_fd, int *fds, const char *buf)
        struct msghdr msg;
        struct iovec iov;
        char data[CMSG_SPACE(sizeof(int) * MUSE_NUM_FD)];
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
        int *fdptr;
        int fd_cnt = 0;
 
@@ -618,8 +618,8 @@ int muse_core_ipc_send_fd_msg(int sock_fd, int *fds, const char *buf)
                }
        }
 
-       if ((ret = sendmsg(sock_fd, &msg, 0)) == SOCK_ERR) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+       if ((ret = sendmsg(sock_fd, &msg, 0)) == MUSE_ERR) {
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("fail to send msg (%s) %d", err_msg, sock_fd);
        }
 
@@ -640,7 +640,7 @@ int muse_core_ipc_recv_fd_msg(int sock_fd, char *buf, int *out_fd)
        struct iovec iov;
        size_t completed_msg_len = 0;
        char data[CMSG_SPACE(sizeof(int) * MUSE_NUM_FD)];
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
 
        g_return_val_if_fail(buf, MM_ERROR_INVALID_ARGUMENT);
 
@@ -658,8 +658,8 @@ int muse_core_ipc_recv_fd_msg(int sock_fd, char *buf, int *out_fd)
        msg.msg_control = data;
        msg.msg_controllen = sizeof(data);
 
-       if ((ret = recvmsg(sock_fd, &msg, 0)) == SOCK_ERR) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+       if ((ret = recvmsg(sock_fd, &msg, 0)) == MUSE_ERR) {
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("fail to receive msg (%s)", err_msg);
                return ret;
        }
@@ -675,7 +675,7 @@ int muse_core_ipc_recv_fd_msg(int sock_fd, char *buf, int *out_fd)
 
 int muse_core_ipc_set_timeout(int sock_fd, int timeout_sec)
 {
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
        struct timeval tv;
 
        LOGD("Enter");
@@ -683,14 +683,14 @@ int muse_core_ipc_set_timeout(int sock_fd, int timeout_sec)
        tv.tv_sec  = timeout_sec;
        tv.tv_usec = 0L;
 
-       if (setsockopt(sock_fd, SOL_SOCKET, SO_SNDTIMEO, (void*)&tv, (socklen_t)sizeof(tv)) == SOCK_ERR) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+       if (setsockopt(sock_fd, SOL_SOCKET, SO_SNDTIMEO, (void*)&tv, (socklen_t)sizeof(tv)) == MUSE_ERR) {
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("[%d] Failed to set socket send timeout option (%s) %d", sock_fd, err_msg, errno);
                return MM_ERROR_UNKNOWN;
        }
 
-       if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, (void*)&tv, (socklen_t)sizeof(tv)) == SOCK_ERR) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+       if (setsockopt(sock_fd, SOL_SOCKET, SO_RCVTIMEO, (void*)&tv, (socklen_t)sizeof(tv)) == MUSE_ERR) {
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("[%d] Failed to set socket recv timeout option (%s) %d", sock_fd, err_msg, errno);
                return MM_ERROR_UNKNOWN;
        }
@@ -702,7 +702,7 @@ int muse_core_ipc_set_timeout(int sock_fd, int timeout_sec)
 
 int muse_core_ipc_push_data(int sock_fd, const char *data, int size, uint64_t data_id)
 {
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
        muse_recv_data_head_t header;
        int sended_len = 0;
 
@@ -716,12 +716,12 @@ int muse_core_ipc_push_data(int sock_fd, const char *data, int size, uint64_t da
                                        sock_fd, header.marker, header.size, header.id);
 
        if ((sended_len = send(sock_fd, &header, sizeof(muse_recv_data_head_t), 0)) < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("[%d] fail to send msg (%s) %d", sock_fd, err_msg, errno);
        }
 
        if ((sended_len += send(sock_fd, data, size, 0)) < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("[%d] fail to send msg (%s) %d", sock_fd, err_msg, errno);
        }
 
@@ -754,7 +754,7 @@ char *muse_core_ipc_get_data(muse_module_h module)
        while (g_queue_is_empty(ch->queue)) {
                end_time = g_get_monotonic_time() + WAIT_MSEC * G_TIME_SPAN_MILLISECOND;
                if (!g_cond_wait_until(&ch->cond, &ch->mutex, end_time) || wait_try++ > MAX_RETRIES) {
-                       LOGW("[%d] No signal during %lldms", wait_try, end_time);
+                       LOGW("[%d] No signal during %lldus", wait_try, end_time);
                        g_mutex_unlock (&ch->mutex);
                        return NULL;
                }
@@ -828,7 +828,7 @@ int muse_core_ipc_set_fd(muse_module_h module, int fd)
 
 gboolean muse_core_ipc_fd_is_valid(int fd)
 {
-       return (fcntl(fd, F_GETFL) != SOCK_ERR || errno != EBADF) && (fd > STDERR_FILENO);
+       return (fcntl(fd, F_GETFL) != MUSE_ERR || errno != EBADF) && (fd > STDERR_FILENO);
 }
 
 int muse_core_ipc_get_bufmgr(tbm_bufmgr *bufmgr)
index 0ead344..e8cbc40 100644 (file)
@@ -62,7 +62,7 @@ static void _muse_core_log_free(void);
 
 static gboolean _muse_core_log_pid_is_valid(pid_t pid)
 {
-       char client_buf[MUSE_MAX_ERROR_MSG_LEN];
+       char client_buf[MUSE_MAX_MSG_LEN];
 
        snprintf(client_buf, sizeof(client_buf), "/proc/%d", (int)pid);
 
@@ -104,7 +104,7 @@ static void _muse_core_log_latest_msgs(void)
 
 static void _muse_core_log_pid_info(pid_t pid)
 {
-       char client_buf[MUSE_MAX_ERROR_MSG_LEN];
+       char client_buf[MUSE_MAX_MSG_LEN];
 
        g_return_if_fail(g_muse_core_log);
        g_return_if_fail(muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd));
@@ -119,7 +119,7 @@ static void _muse_core_log_pid_info(pid_t pid)
 
 static void _muse_core_log_cmdline(pid_t pid)
 {
-       char client_buf[MUSE_MAX_ERROR_MSG_LEN];
+       char client_buf[MUSE_MAX_MSG_LEN];
        FILE *fp;
 
        g_return_if_fail(g_muse_core_log);
@@ -129,7 +129,7 @@ static void _muse_core_log_cmdline(pid_t pid)
        snprintf(client_buf, sizeof(client_buf), "/proc/%d/cmdline", (int)pid);
        fp = fopen(client_buf, "r");
        if (fp) {
-               size_t size = fread(client_buf, sizeof(char), MUSE_MAX_ERROR_MSG_LEN, fp);
+               size_t size = fread(client_buf, sizeof(char), MUSE_MAX_MSG_LEN, fp);
                client_buf[size] = '\0';
 
                if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
@@ -143,7 +143,7 @@ static void _muse_core_log_cmdline(pid_t pid)
 
 static void _muse_core_log_process_info(pid_t pid)
 {
-       char client_buf[MUSE_MAX_ERROR_MSG_LEN];
+       char client_buf[MUSE_MAX_MSG_LEN];
        FILE *fp;
 
        g_return_if_fail(g_muse_core_log);
@@ -158,7 +158,7 @@ static void _muse_core_log_process_info(pid_t pid)
                else if (write(g_muse_core_log->log_fd, "\n", 1) == WRITE_FAIL)
                        LOGE("fail to write process command");
 
-               while (fgets(client_buf, MUSE_MAX_ERROR_MSG_LEN, fp)) {
+               while (fgets(client_buf, MUSE_MAX_MSG_LEN, fp)) {
                        if (write(g_muse_core_log->log_fd, client_buf, strlen(client_buf)) == WRITE_FAIL)
                                LOGE("fail to write command info to logfile");
                }
@@ -184,14 +184,14 @@ static void _muse_core_log_api_name(gpointer ptr)
 static void _muse_core_log_api_info(void)
 {
        Dl_info info;
-       char client_buf[MUSE_MAX_ERROR_MSG_LEN];
+       char client_buf[MUSE_MAX_MSG_LEN];
        gpointer ptr;
        int i;
 
        g_return_if_fail(g_muse_core_log);
        g_return_if_fail(muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd));
 
-       for (i = 0; i < MUSE_MODULE_MAX; i++) {
+       for (i = 0; i < muse_core_config_get_instance()->host_cnt; i++) {
                muse_core_module_get_instance()->get_value(i, DISPATCHER_PTR, &ptr);
                memset(&info, 0, sizeof(info));
                if (dladdr((const void *) ptr, &info) && info.dli_sname) {
@@ -204,7 +204,7 @@ static void _muse_core_log_api_info(void)
 
 static void _muse_core_log_binary_info(void)
 {
-       char client_buf[MUSE_MAX_ERROR_MSG_LEN];
+       char client_buf[MUSE_MAX_MSG_LEN];
        FILE *fp;
        char *label;
        char *value;
@@ -216,10 +216,10 @@ static void _muse_core_log_binary_info(void)
        fp = fopen("/etc/tizen-release", "r");
        g_return_if_fail(fp);
 
-       while (fgets(client_buf, MUSE_MAX_ERROR_MSG_LEN, fp)) {
+       while (fgets(client_buf, MUSE_MAX_MSG_LEN, fp)) {
                label = strtok_r(client_buf, delimiter, &ptr);
                if (label) {
-                       if (strcmp(label, BUILD_ID) == 0) {
+                       if (strncmp(label, BUILD_ID, strlen(BUILD_ID)) == 0) {
                                value = strtok_r(NULL, delimiter, &ptr);
                                if (value) {
                                        if (write(g_muse_core_log->log_fd, value, strlen(value)) != WRITE_FAIL)
@@ -279,12 +279,12 @@ static void _muse_core_log_create_fd(void)
 {
        int selected_index, index;
        struct stat st;
-       char file[MAX_FILE_NUM][MUSE_TUNABLE_CALLER_DEPTH];
+       char file[MAX_FILE_NUM][MUSE_MSG_LEN];
 
        g_return_if_fail(g_muse_core_log);
 
        for (index = 0; index < MAX_FILE_NUM; index++)
-               snprintf(file[index], strlen(LOGFILE) + 3, "%s.%d", LOGFILE, index);
+               snprintf(file[index], strlen(muse_core_config_get_instance()->logfile) + 3, "%s.%d", muse_core_config_get_instance()->logfile, index);
 
        for (index = 0; index < MAX_FILE_NUM; index++) {
                if (access(file[index], F_OK) == 0) { /* if 0, then there is file */
@@ -314,7 +314,7 @@ static void _muse_core_log_create_fd(void)
 
 static void _muse_core_log_set_log_fd(void)
 {
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
        g_return_if_fail(g_muse_core_log);
 
        _muse_core_log_create_fd();
@@ -322,7 +322,7 @@ static void _muse_core_log_set_log_fd(void)
        g_return_if_fail(muse_core_ipc_fd_is_valid(g_muse_core_log->log_fd));
 
        if (fcntl(g_muse_core_log->log_fd, F_SETFD, FD_CLOEXEC) < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("unable to set CLO_EXEC on log fd %d: %s", g_muse_core_log->log_fd, err_msg);
        }
 
@@ -339,9 +339,7 @@ static void _muse_core_log_init_instance(void (*log)(char *), void (*log_attr)(c
 
        g_muse_core_log = calloc(1, sizeof(*g_muse_core_log));
        g_return_if_fail(g_muse_core_log);
-       memset(g_muse_core_log->buf, 0, MUSE_MSG_MAX_LENGTH + 1);
-       g_muse_core_log->size = 0;
-       memset(g_muse_core_log->cache, 0, MUSE_MSG_MAX_LENGTH + 1);
+
        g_muse_core_log->log = log;
        g_muse_core_log->log_attr = log_attr;
        g_muse_core_log->fatal = fatal;
@@ -352,7 +350,6 @@ static void _muse_core_log_init_instance(void (*log)(char *), void (*log_attr)(c
        g_muse_core_log->save_debug_info = save_debug_info;
        g_muse_core_log->free = free;
        g_mutex_init(&g_muse_core_log->log_lock);
-       g_muse_core_log->currnt_index = 0;
 }
 
 static void
index bac6c5f..a2e3d8c 100644 (file)
@@ -37,9 +37,11 @@ static void _muse_core_module_set_dllsymbol_loaded_value(int api_module, GModule
 static gboolean _muse_core_module_get_dllsymbol_loaded_value(int api_module);
 static void _muse_core_module_set_dllsymbol_value(int api_module, const char *keyname, gpointer value);
 static int _muse_core_module_get_dllsymbol_value(int api_module, const char *keyname, gpointer *value);
+static void _muse_core_module_set_timeout(int api_module, int disp_api, int timeout);
+static int _muse_core_module_get_timeout(int api_module, int disp_api);
 static void _muse_core_module_init_instance(GModule* (*load) (int), void (*dispatch) (int, muse_module_h), gboolean (*close) (muse_module_h),
        void (*free) (void), GModule * (*get_dllsymbol_value) (int), void (*set_dllsymbol_loaded_value) (int, GModule *, gboolean), gboolean(*get_dllsymbol_loaded_value) (int),
-       void (*set_value) (int, const char *, gpointer), int (*get_value) (int, const char *, gpointer *));
+       void (*set_value) (int, const char *, gpointer), int (*get_value) (int, const char *, gpointer *), void (*set_timeout) (int, int, int), int (*get_timeout) (int, int));
 
 
 static GModule *_muse_core_module_load(int api_module)
@@ -81,7 +83,8 @@ static void _muse_core_module_dispatch(int cmd, muse_module_h module)
                g_module_symbol(module->ch[MUSE_CHANNEL_MSG].dll_handle, DISPATCHER, (gpointer *)&dispatcher);
 
                if (dispatcher && dispatcher[cmd]) {
-                       id = g_timeout_add_seconds(MUSE_TIMEOUT_SEC, (GSourceFunc) _muse_core_module_dispatch_callback, (gpointer) module);
+                       id = g_timeout_add_seconds((guint)g_muse_core_module->disp_timeout[module->api_module][module->disp_api],
+                               (GSourceFunc) _muse_core_module_dispatch_callback, (gpointer) module);
 #ifdef MUSE_USE_LOG
                        _muse_core_module_set_dllsymbol_value(module->api_module, DISPATCHER_PTR, (gpointer) dispatcher[cmd]);
                        muse_core_log_get_instance()->log_api_name((gpointer) dispatcher[cmd]);
@@ -134,11 +137,11 @@ static gboolean _muse_core_module_get_dllsymbol_loaded_value(int api_module)
 
 static void _muse_core_module_set_dllsymbol_value(int api_module, const char *keyname, gpointer value)
 {
+       gpointer orig_key;
+
        g_return_if_fail(g_muse_core_module);
        g_return_if_fail(keyname);
 
-       gpointer orig_key;
-
        g_mutex_lock(&g_muse_core_module->module_lock[api_module]);
 
        /* Try looking up this key. */
@@ -167,6 +170,26 @@ static int _muse_core_module_get_dllsymbol_value(int api_module, const char *key
        }
 }
 
+static void _muse_core_module_set_timeout(int api_module, int disp_api, int timeout)
+{
+       g_return_if_fail(g_muse_core_module);
+       g_return_if_fail(timeout >= muse_core_config_get_instance()->min_timeout &&
+               timeout <= muse_core_config_get_instance()->max_timeout);
+
+       g_mutex_lock(&g_muse_core_module->module_lock[api_module]);
+
+       g_muse_core_module->disp_timeout[api_module][disp_api] = timeout;
+
+       g_mutex_unlock(&g_muse_core_module->module_lock[api_module]);
+}
+
+static int _muse_core_module_get_timeout(int api_module, int disp_api)
+{
+       g_return_val_if_fail(g_muse_core_module, MUSE_ERR);
+
+       return g_muse_core_module->disp_timeout[api_module][disp_api];
+}
+
 static gboolean _muse_core_module_free_key(gpointer key, gpointer value, gpointer user_data)
 {
        MUSE_G_FREE(key);
@@ -179,7 +202,7 @@ static void _muse_core_module_free(void)
 
        g_return_if_fail(g_muse_core_module);
 
-       for (idx = 0; idx < MUSE_MODULE_MAX; idx++) {
+       for (idx = 0; idx < muse_core_config_get_instance()->host_cnt; idx++) {
                g_mutex_clear(&g_muse_core_module->module_lock[idx]);
                g_module_close(g_muse_core_module->module[idx]);
                g_hash_table_foreach_remove(g_muse_core_module->table[idx], _muse_core_module_free_key, NULL);
@@ -191,11 +214,14 @@ static void _muse_core_module_free(void)
 
 static void _muse_core_module_init_instance(GModule* (*load) (int), void (*dispatch) (int, muse_module_h), gboolean (*close) (muse_module_h),
        void (*free) (void), GModule * (*get_dllsymbol_value) (int), void (*set_dllsymbol_loaded_value) (int, GModule *, gboolean), gboolean(*get_dllsymbol_loaded_value) (int),
-       void (*set_value) (int, const char *, gpointer), int (*get_value) (int, const char *, gpointer *))
+       void (*set_value) (int, const char *, gpointer), int (*get_value) (int, const char *, gpointer *), void (*set_timeout) (int, int, int), int (*get_timeout) (int, int))
 {
+       int module_idx = 0;
+       int module_timeout = 0;
+       int disp_idx = 0;
+
        g_return_if_fail(g_muse_core_module == NULL);
 
-       int idx = 0;
        g_muse_core_module = calloc(1, sizeof(*g_muse_core_module));
        g_return_if_fail(g_muse_core_module);
 
@@ -209,11 +235,14 @@ static void _muse_core_module_init_instance(GModule* (*load) (int), void (*dispa
        g_muse_core_module->set_value = set_value;
        g_muse_core_module->get_value = get_value;
 
-       for (idx = 0; idx < MUSE_MODULE_MAX; idx++) {
-               g_mutex_init(&g_muse_core_module->module_lock[idx]);
-               g_muse_core_module->module_loaded[idx] = FALSE;
-               g_muse_core_module->table[idx] = g_hash_table_new(g_str_hash, g_str_equal);
-               g_return_if_fail(g_muse_core_module->table[idx]);
+       for (module_idx = 0; module_idx < muse_core_config_get_instance()->host_cnt; module_idx++) {
+               module_timeout = muse_core_config_get_instance()->host_infos[module_idx]->timeout;
+               g_mutex_init(&g_muse_core_module->module_lock[module_idx]);
+               g_muse_core_module->module_loaded[module_idx] = FALSE;
+               g_muse_core_module->table[module_idx] = g_hash_table_new(g_str_hash, g_str_equal);
+               g_return_if_fail(g_muse_core_module->table[module_idx]);
+               for (disp_idx = 0; disp_idx < MUSE_MAX_DISPATCHER_NUM; disp_idx++)
+                       _muse_core_module_set_timeout(module_idx, disp_idx, module_timeout);
        }
 }
 
@@ -232,7 +261,8 @@ void muse_core_module_init(void)
        if (g_muse_core_module == NULL)
                _muse_core_module_init_instance(_muse_core_module_load, _muse_core_module_dispatch, _muse_core_module_close, _muse_core_module_free,
                                        _muse_core_module_get_dllsymbol, _muse_core_module_set_dllsymbol_loaded_value, _muse_core_module_get_dllsymbol_loaded_value,
-                                       _muse_core_module_set_dllsymbol_value, _muse_core_module_get_dllsymbol_value);
+                                       _muse_core_module_set_dllsymbol_value, _muse_core_module_get_dllsymbol_value,
+                                       _muse_core_module_set_timeout, _muse_core_module_get_timeout);
 
        LOGD("Leave");
 }
index 92623cc..ecbeed3 100644 (file)
@@ -159,7 +159,7 @@ static void _muse_core_security_init_instance(int (*new)(void), void (*free)(voi
 
        g_muse_core_security = calloc(1, sizeof(*g_muse_core_security));
        g_return_if_fail(g_muse_core_security);
-       g_muse_core_security->p_cynara= NULL;
+
        g_muse_core_security->new= new;
        g_muse_core_security->free = free;
 }
index f02f673..db29862 100644 (file)
@@ -89,12 +89,12 @@ static int _muse_core_server_pidfile_create(const char *path, pid_t pid)
        int fd;
        struct flock lock;
        char pid_buf[MUSE_MSG_LEN] = {'\0',};
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
 
        fd = open(path, O_WRONLY | O_CREAT, (S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH));
 
        if (fd < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("Fail to open pidfile [%s] : %s", path, err_msg);
                return MM_ERROR_FILE_NOT_FOUND;
        }
@@ -106,7 +106,7 @@ static int _muse_core_server_pidfile_create(const char *path, pid_t pid)
 
        if (fcntl(fd, F_SETLK, &lock) < 0) {
                if (errno != EACCES && errno != EAGAIN) {
-                       strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+                       strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                        LOGE("Fail to lock pidfile [%s] : %s", path, err_msg);
                } else {
                        LOGE("process is already running");
@@ -116,7 +116,7 @@ static int _muse_core_server_pidfile_create(const char *path, pid_t pid)
        }
 
        if (ftruncate(fd, 0) < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("Fail to truncate pidfile [%s] : %s", path, err_msg);
                close(fd);
                return MM_ERROR_FILE_INTERNAL;
@@ -126,7 +126,7 @@ static int _muse_core_server_pidfile_create(const char *path, pid_t pid)
        snprintf(pid_buf, sizeof(pid_buf), "%u", pid);
 
        if (write(fd, pid_buf, strlen(pid_buf)) != (int)strlen(pid_buf)) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("Fail to write pid to pidfile [%s] : %s", path, err_msg);
                close(fd);
                return MM_ERROR_FILE_WRITE;
@@ -141,7 +141,7 @@ int main(int argc, char **argv)
        int result;
        pid_t pid;
        int index;
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
 
 #ifdef MUSE_TTRACE_LOG
        trace_begin("MUSE:START");
@@ -151,7 +151,7 @@ int main(int argc, char **argv)
 
        /* daemonizing */
        if ((pid = fork()) < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("Error: fork() failed: %s", err_msg);
                exit(EXIT_SUCCESS);
        } else if (pid != 0) {
@@ -191,7 +191,7 @@ int main(int argc, char **argv)
        trace_begin("MUSE:preloading module");
 #endif
        for (index = 0; index < muse_core_config_get_instance()->get_host_cnt(); index++) {
-               if (0 == strcmp(muse_core_config_get_instance()->get_preloaded(index), "yes")) {
+               if (0 == strncmp(muse_core_config_get_instance()->get_preloaded(index), "yes", strlen("yes"))) {
                        muse_module_h module = NULL;
                        muse_module_cmd_dispatchfunc *cmd_dispatcher = NULL;
 
index 77a8112..28f057f 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "muse_core_log.h"
 #include "muse_core_internal.h"
+#include "muse_core_config.h"
 
 struct sigaction muse_segv_old_action;
 struct sigaction muse_abrt_old_action;
@@ -74,18 +75,18 @@ static void _muse_core_signal_save_debug_info(pid_t pid)
 
 static void _muse_core_signal_backtrace(void *arg)
 {
-       void *trace[MUSE_TUNABLE_CALLER_DEPTH];
+       void *trace[MUSE_MSG_LEN];
        int tracesize;
        int i;
        char **strings = NULL;
        ucontext_t *uctxt = NULL;
-       char err_msg[MUSE_MAX_ERROR_MSG_LEN] = {'\0',};
+       char err_msg[MUSE_MAX_MSG_LEN] = {'\0',};
 
        LOGE("----------BEGIN MUSE DYING MESSAGE----------");
 
-       tracesize = backtrace(trace, MUSE_TUNABLE_CALLER_DEPTH);
+       tracesize = backtrace(trace, MUSE_MSG_LEN);
        if (tracesize < 0) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("backtrace error: %s", err_msg);
        }
 
@@ -102,7 +103,7 @@ static void _muse_core_signal_backtrace(void *arg)
        #endif
        strings = backtrace_symbols(trace, tracesize);
        if (strings == NULL) {
-               strerror_r(errno, err_msg, MUSE_MAX_ERROR_MSG_LEN);
+               strerror_r(errno, err_msg, MUSE_MAX_MSG_LEN);
                LOGE("backtrace_symbols error: %s", err_msg);
        } else {
                /* skip the first stack frame because it just points here. */
@@ -122,10 +123,10 @@ static void _muse_core_signal_sigaction(int signo, siginfo_t *si, void *arg)
        g_return_if_fail(arg);
 
 #ifdef MUSE_USE_LWIPC
-       if (LwipcResetEvent(MUSE_SERVER_READY) < 0)
+       if (LwipcResetEvent(muse_core_config_get_instance()->muse_server_ready) < 0)
                LOGE("Fail to reset light weight IPC");
 #else
-       remove(MUSE_SERVER_READY);
+       remove(muse_core_config_get_instance()->muse_server_ready);
 #endif
 
        _muse_core_signal_backtrace(arg);