update non-volitile information when crashed 59/46259/4
authorYoungHun Kim <yh8004.kim@samsung.com>
Tue, 18 Aug 2015 13:17:34 +0000 (22:17 +0900)
committerYoungHun Kim <yh8004.kim@samsung.com>
Thu, 20 Aug 2015 07:21:56 +0000 (16:21 +0900)
Change-Id: Idfab2aeac0a544b36c8e490d53a63c2713ba40ec

include/mmsvc_core_config.h
include/mmsvc_core_internal.h
include/mmsvc_core_log.h
src/mmsvc_core_config.c
src/mmsvc_core_log.c
src/mmsvc_core_msg_json.c

index 0615fb1..bb4d616 100644 (file)
@@ -57,6 +57,7 @@ typedef struct config
        char* (*get_path)(int);
        int (*get_gst_param_cnt)(void);
        char* (*get_gst_param_str)(int);
+       char* (*get_hosts)(void);
 } config_t;
 
 /*mmsvc_core_config_init must be called before mmsvc_core_config_get_instance*/
index 89994a0..cee1aca 100644 (file)
@@ -61,7 +61,7 @@ extern "C" {
 
 #undef LOG_TAG
 #define LOG_TAG "TIZEN_N_MUSED"
-#define LOGFILE "/tmp/mmsvc_core_log"
+#define LOGFILE "/var/log/mused-server.log"
 #define LOCKFILE "/tmp/.mmsvc-core.lock"
 #define SOCKFILE0 "/tmp/.mmsvc_core_socket"
 #define SOCKFILE1 "/tmp/.mmsvc_core_data_socket"
index 929c25f..e812a9c 100755 (executable)
@@ -41,6 +41,8 @@ typedef struct mmsvc_core_log {
        void (*fatal)(char *);
        void (*set_module_value) (int, GModule *, gboolean);
        gboolean (*get_module_opened) (int);
+       void (*set_msg) (char *);
+       char* (*get_msg) (void);
        GModule* (*get_module_value) (int);
        gboolean module_opened[MMSVC_CLIENT_MAX];
        GModule *module[MMSVC_CLIENT_MAX];
index 454d4d4..ffd51db 100644 (file)
@@ -28,8 +28,10 @@ static int _mmsvc_core_config_parser(void);
 static void _mmsvc_core_config_free(void);
 static char *_mmsvc_core_config_get_path(int api_client);
 static int _mmsvc_core_config_get_gst_param_cnt(void);
+static char *_mmsvc_core_config_get_hosts(void);
 static char *_mmsvc_core_config_get_gst_param_str(int idx);
-static void _mmsvc_core_config_init_instance(void (*free)(void), char* (*get_path)(int), int (*get_gst_param_cnt)(void), char* (*get_gst_param_str)(int));
+static void _mmsvc_core_config_init_instance(void (*free)(void), char* (*get_path)(int), int (*get_gst_param_cnt)(void),
+       char* (*get_gst_param_str)(int), char* (*get_hosts)(void));
 
 static int _mmsvc_core_config_parser(void)
 {
@@ -156,7 +158,7 @@ static void _mmsvc_core_config_free(void)
        MMSVC_FREE(g_conf);
 }
 
-static void _mmsvc_core_config_init_instance(void (*free)(void), char* (*get_path)(int), int (*get_gst_param_cnt)(void), char* (*get_gst_param_str)(int))
+static void _mmsvc_core_config_init_instance(void (*free)(void), char* (*get_path)(int), int (*get_gst_param_cnt)(void), char* (*get_gst_param_str)(int), char* (*get_hosts)(void))
 {
        g_return_if_fail(free != NULL);
        g_return_if_fail(get_path != NULL);
@@ -171,14 +173,22 @@ static void _mmsvc_core_config_init_instance(void (*free)(void), char* (*get_pat
        g_conf->get_path = get_path;
        g_conf->get_gst_param_cnt= get_gst_param_cnt;
        g_conf->get_gst_param_str = get_gst_param_str;
+       g_conf->get_hosts = get_hosts;
        LOGD("conf: %0x2x", g_conf);
 
        if (_mmsvc_core_config_parser() != 0)
                LOGE("parser() error");
 }
 
+static char *_mmsvc_core_config_get_hosts(void)
+{
+       g_return_val_if_fail(g_conf->hosts != NULL, NULL);
+       return g_conf->hosts;
+}
+
 static int _mmsvc_core_config_get_gst_param_cnt(void)
 {
+       g_return_val_if_fail(g_conf != NULL, 0);
        return g_conf->gst_param_cnt;
 }
 
@@ -199,7 +209,8 @@ static char *_mmsvc_core_config_get_path(int api_client)
 config_t *mmsvc_core_config_get_instance(void)
 {
        if (g_conf == NULL)
-               _mmsvc_core_config_init_instance(_mmsvc_core_config_free, _mmsvc_core_config_get_path, _mmsvc_core_config_get_gst_param_cnt, _mmsvc_core_config_get_gst_param_str);
+               _mmsvc_core_config_init_instance(_mmsvc_core_config_free, _mmsvc_core_config_get_path, _mmsvc_core_config_get_gst_param_cnt,
+               _mmsvc_core_config_get_gst_param_str, _mmsvc_core_config_get_hosts);
 
        return g_conf;
 }
@@ -208,6 +219,7 @@ void mmsvc_core_config_init(void)
 {
        LOGD("Enter");
        if (g_conf == NULL)
-               _mmsvc_core_config_init_instance(_mmsvc_core_config_free, _mmsvc_core_config_get_path, _mmsvc_core_config_get_gst_param_cnt, _mmsvc_core_config_get_gst_param_str);
+               _mmsvc_core_config_init_instance(_mmsvc_core_config_free, _mmsvc_core_config_get_path, _mmsvc_core_config_get_gst_param_cnt,
+               _mmsvc_core_config_get_gst_param_str, _mmsvc_core_config_get_hosts);
        LOGD("Leave");
 }
index 790c04e..46ec63c 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include "mmsvc_core_internal.h"
+#include "mmsvc_core_config.h"
 #include "mmsvc_core_log.h"
 #ifndef __USE_GNU
 #define __USE_GNU /* for gregs */
@@ -55,11 +56,14 @@ static void _mmsvc_core_log_init_signals(void);
 static int _mmsvc_core_log_fd_set_block(int fd);
 static void _mmsvc_core_log_sigaction(int signo, siginfo_t *si, void *arg);
 static void _mmsvc_core_log_set_log_fd(void);
-static void _mmsvc_core_log_init_instance(void (*log)(char *), void (*fatal)(char *), void (*set_module_value) (int, GModule *, gboolean), gboolean(*get_module_opened) (int), GModule * (*get_module_value) (int));
+static void _mmsvc_core_log_init_instance(void (*log)(char *), void (*fatal)(char *), void (*set_module_value) (int, GModule *, gboolean),
+       gboolean(*get_module_opened) (int), GModule * (*get_module_value) (int), void (*set_msg) (char *), char * (*get_msg) (void));
 static void _mmsvc_core_log_monitor(char *msg);
 static void _mmsvc_core_log_fatal(char *msg);
 static int _mmsvc_core_log_init_signal_set(void);
 static void _mmsvc_core_log_set_module_value(int index, GModule *module, gboolean value);
+static void _mmsvc_core_log_set_msg(char *msg);
+static char *_mmsvc_core_log_get_msg(void);
 static gboolean _mmsvc_core_log_get_module_opened(int index);
 static GModule *_mmsvc_core_log_get_module_value(int index);
 
@@ -78,6 +82,31 @@ static void _mmsvc_core_log_sig_abort(int signo)
        if (SIG_ERR == signal(SIGABRT, SIG_DFL))
                LOGE("SIGABRT andler: %s", strerror(errno));
 
+       static char client_name[256];
+       memset(client_name, '\0', sizeof(client_name));
+       snprintf(client_name, sizeof(client_name) - 1, "[client name] %s", mmsvc_core_config_get_instance()->get_hosts());
+       if (write(g_mused_log->log_fd, client_name, strlen(client_name)) != strlen(client_name))
+               LOGE("There was an error writing client name to testfile");
+       else if (write(g_mused_log->log_fd, "\n", 1) != 1)
+               LOGE("write %s", client_name);
+
+       static char client_pid[256];
+       memset(client_pid, '\0', sizeof(client_pid));
+       snprintf(client_pid, sizeof(client_pid) - 1, "[client pid] %lu", (unsigned long) getpid());
+       if (write(g_mused_log->log_fd, client_pid, strlen(client_pid)) != strlen(client_pid))
+               LOGE("There was an error writing client pid to testfile");
+       else if (write(g_mused_log->log_fd, "\n", 1) != 1)
+               LOGE("write %s", client_pid);
+
+       static char latest_called_api[256];
+       memset(latest_called_api, '\0', sizeof(latest_called_api));
+       snprintf(latest_called_api, sizeof(latest_called_api) - 1, "[client's latest called api] %s", _mmsvc_core_log_get_msg());
+
+       if (write(g_mused_log->log_fd, latest_called_api, strlen(latest_called_api)) != strlen(latest_called_api))
+               LOGE("There was an error writing client's latest called api to testfile");
+       else if (write(g_mused_log->log_fd, "\n", 1) != 1)
+               LOGE("write %s", latest_called_api);
+
        abort();
 }
 
@@ -246,7 +275,8 @@ static void _mmsvc_core_log_set_log_fd(void)
        (void) _mmsvc_core_log_fd_set_block(g_mused_log->log_fd);
 }
 
-static void _mmsvc_core_log_init_instance(void (*log)(char *), void (*fatal)(char *), void (*set_module_value) (int, GModule *, gboolean), gboolean(*get_module_opened) (int), GModule * (*get_module_value) (int))
+static void _mmsvc_core_log_init_instance(void (*log)(char *), void (*fatal)(char *), void (*set_module_value) (int, GModule *, gboolean),
+       gboolean(*get_module_opened) (int), GModule * (*get_module_value) (int), void (*set_msg) (char *), char * (*get_msg) (void))
 {
        g_return_if_fail(log != NULL);
        g_return_if_fail(fatal != NULL);
@@ -264,6 +294,8 @@ static void _mmsvc_core_log_init_instance(void (*log)(char *), void (*fatal)(cha
        g_mused_log->get_module_value = get_module_value;
        g_mused_log->timer = g_timer_new();
        g_mused_log->count = 0;
+       g_mused_log->set_msg = set_msg;
+       g_mused_log->get_msg = get_msg;
        g_timer_stop(g_mused_log->timer);
        for (idx = 0; idx < MMSVC_CLIENT_MAX; idx++) {
                g_mused_log->module_opened[idx] = false;
@@ -283,13 +315,10 @@ static void _mmsvc_core_log_monitor(char *msg)
                return;
        }
 
-       if (write(g_mused_log->log_fd, msg, strlen(msg)) != strlen(msg)) {
-               if (write(g_mused_log->log_fd, msg, strlen(msg)) != strlen(msg))
-                       LOGE("There was an error writing to testfile");
-       } else {
-               if (write(g_mused_log->log_fd, "\n", 1) != 1)
-                       LOGE("write %s", msg);
-       }
+       if (write(g_mused_log->log_fd, msg, strlen(msg)) != strlen(msg))
+               LOGE("There was an error writing to testfile");
+       else if (write(g_mused_log->log_fd, "\n", 1) != 1)
+               LOGE("write %s", msg);
 
        if (g_mused_log->count != 0)
                g_timer_stop(g_mused_log->timer);
@@ -315,6 +344,22 @@ static void _mmsvc_core_log_set_module_value(int index, GModule *module, gboolea
        LOGD("module: %p", g_mused_log->module[index]);
 }
 
+static void _mmsvc_core_log_set_msg(char *msg)
+{
+       g_return_if_fail(g_mused_log != NULL);
+       g_return_if_fail(msg != NULL);
+
+       g_mused_log->buf = g_strdup(msg);
+}
+
+static char *_mmsvc_core_log_get_msg(void)
+{
+       g_return_if_fail(g_mused_log != NULL);
+       g_return_val_if_fail(g_mused_log->buf != NULL, NULL);
+
+       return g_mused_log->buf;
+}
+
 static gboolean _mmsvc_core_log_get_module_opened(int index)
 {
        g_return_val_if_fail(g_mused_log != NULL, false);
@@ -334,7 +379,7 @@ mmsvc_core_log_t *mmsvc_core_log_get_instance(void)
 {
        if (g_mused_log == NULL)
                _mmsvc_core_log_init_instance(_mmsvc_core_log_monitor, _mmsvc_core_log_fatal, _mmsvc_core_log_set_module_value,
-               _mmsvc_core_log_get_module_opened, _mmsvc_core_log_get_module_value);
+               _mmsvc_core_log_get_module_opened, _mmsvc_core_log_get_module_value, _mmsvc_core_log_set_msg, _mmsvc_core_log_get_msg);
 
        return g_mused_log;
 }
@@ -345,7 +390,7 @@ void mmsvc_core_log_init(void)
 
        if (g_mused_log == NULL)
                _mmsvc_core_log_init_instance(_mmsvc_core_log_monitor, _mmsvc_core_log_fatal, _mmsvc_core_log_set_module_value,
-               _mmsvc_core_log_get_module_opened, _mmsvc_core_log_get_module_value);
+               _mmsvc_core_log_get_module_opened, _mmsvc_core_log_get_module_value, _mmsvc_core_log_set_msg, _mmsvc_core_log_get_msg);
 
        _mmsvc_core_log_set_log_fd();
        _mmsvc_core_log_init_signals();
index 92b9fb1..74ef34a 100644 (file)
@@ -22,6 +22,7 @@
 #include <json.h>
 #include <json_tokener.h>
 #include "mmsvc_core_msg_json.h"
+#include "mmsvc_core_log.h"
 #include "mmsvc_core_internal.h"
 
 static json_object *_mmsvc_core_msg_json_find_obj(json_object * jobj, char *find_key)
@@ -155,6 +156,7 @@ char *mmsvc_core_msg_json_factory_new(int api, const char *arg_name, int64_t arg
 
        jsonMsg = json_object_to_json_string(jobj);
        sndMsg = g_strdup(jsonMsg);
+       mmsvc_core_log_get_instance()->set_msg(sndMsg);
        LOGD("json msg : %s\n", sndMsg);
 
        json_object_put(jobj);