Add restore logic when daemon get signal 00/74400/1
authorKwangyoun Kim <ky85.kim@samsung.com>
Tue, 14 Jun 2016 06:50:33 +0000 (15:50 +0900)
committerKwangyoun Kim <ky85.kim@samsung.com>
Tue, 14 Jun 2016 06:50:53 +0000 (15:50 +0900)
Change-Id: I59b6cb9ff71ab67716333354a6ad6351ba6c3ae3
Signed-off-by: Kwangyoun Kim <ky85.kim@samsung.com>
client/tts.c
client/tts_dbus.c
include/tts.h
server/ttsd_dbus.c
server/ttsd_main.h
server/ttsd_server.c

index 4bd0740..19684fc 100644 (file)
@@ -83,6 +83,7 @@ static const char* __tts_get_error_code(tts_error_e err)
        case TTS_ERROR_OPERATION_FAILED:        return "TTS_ERROR_OPERATION_FAILED";
        case TTS_ERROR_AUDIO_POLICY_BLOCKED:    return "TTS_ERROR_AUDIO_POLICY_BLOCKED";
        case TTS_ERROR_NOT_SUPPORTED_FEATURE:   return "TTS_ERROR_NOT_SUPPORTED_FEATURE";
+       case TTS_ERROR_SERVICE_RESET:           return "TTS_ERROR_SERVICE_RESET";
        default:
                return "Invalid error code";
        }
@@ -1630,6 +1631,15 @@ int __tts_cb_error(int uid, tts_error_e reason, int utt_id, char* err_msg)
                SLOG(LOG_WARN, TAG_TTSC, "No registered callback function of error ");
        }
 
+       if (TTS_ERROR_SERVICE_RESET == reason) {
+               SLOG(LOG_WARN, TAG_TTSC, "[WARNING] Service Reset");
+
+               client->current_state = TTS_STATE_CREATED;
+               if (0 != tts_prepare(client->tts)) {
+                       SLOG(LOG_ERROR, TAG_TTSC, "[ERROR] Fail to prepare");
+               }
+       }
+
        return 0;
 }
 
index b8725c6..b0ab133 100644 (file)
@@ -121,7 +121,7 @@ static Eina_Bool listener_event_callback(void* data, Ecore_Fd_Handler *fd_handle
                        DBUS_TYPE_INT32, &uid,
                        DBUS_TYPE_INT32, &uttid,
                        DBUS_TYPE_INT32, &reason,
-                       DBUS_TYPE_INT32, &err_msg,
+                       DBUS_TYPE_STRING, &err_msg,
                        DBUS_TYPE_INVALID);
 
                if (dbus_error_is_set(&err)) {
index c49acab..71f99fb 100644 (file)
@@ -51,7 +51,8 @@ typedef enum {
        TTS_ERROR_ENGINE_NOT_FOUND      = TIZEN_ERROR_TTS | 0x03,       /**< No available engine */
        TTS_ERROR_OPERATION_FAILED      = TIZEN_ERROR_TTS | 0x04,       /**< Operation failed */
        TTS_ERROR_AUDIO_POLICY_BLOCKED  = TIZEN_ERROR_TTS | 0x05,       /**< Audio policy blocked */
-       TTS_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_TTS | 0x06        /**< Not supported feature of current engine*/
+       TTS_ERROR_NOT_SUPPORTED_FEATURE = TIZEN_ERROR_TTS | 0x06,       /**< Not supported feature of current engine*/
+       TTS_ERROR_SERVICE_RESET         = TIZEN_ERROR_TTS | 0x07        /**< Service reset */
 } tts_error_e;
 
 /** 
index a089213..60b2799 100644 (file)
@@ -48,6 +48,7 @@ const char* __ttsd_get_error_code(ttsd_error_e err)
        case TTSD_ERROR_OPERATION_FAILED:       return "TTS_ERROR_OPERATION_FAILED";
        case TTSD_ERROR_AUDIO_POLICY_BLOCKED:   return "TTS_ERROR_AUDIO_POLICY_BLOCKED";
        case TTSD_ERROR_NOT_SUPPORTED_FEATURE:  return "TTSD_ERROR_NOT_SUPPORTED_FEATURE";
+       case TTSD_ERROR_SERVICE_RESET:          return "TTSD_ERROR_SERVICE_RESET";
        default:
                return "Invalid error code";
        }
@@ -197,7 +198,7 @@ int ttsdc_send_error_message(int pid, int uid, int uttid, int reason, char* err_
                DBUS_TYPE_INT32, &uid,
                DBUS_TYPE_INT32, &uttid,
                DBUS_TYPE_INT32, &reason,
-               DBUS_TYPE_INT32, &err_msg,
+               DBUS_TYPE_STRING, &err_msg,
                DBUS_TYPE_INVALID);
 
        dbus_message_set_no_reply(msg, TRUE);
@@ -205,7 +206,7 @@ int ttsdc_send_error_message(int pid, int uid, int uttid, int reason, char* err_
        if (!dbus_connection_send(g_conn_sender, msg, NULL)) {
                SLOG(LOG_ERROR, get_tag(), "[Dbus ERROR] <<<< error message : Out Of Memory !");
        } else {
-               SLOG(LOG_DEBUG, get_tag(), "<<<< Send error message : uid(%d), reason(%s), uttid(%d), err_msg(%d)",
+               SLOG(LOG_DEBUG, get_tag(), "<<<< Send error message : uid(%d), reason(%s), uttid(%d), err_msg(%s)",
                         uid, __ttsd_get_error_code(reason), uttid, (NULL == err_msg) ? "NULL" : err_msg);
                dbus_connection_flush(g_conn_sender);
        }
index d5c6291..d440129 100644 (file)
@@ -50,7 +50,8 @@ typedef enum {
        TTSD_ERROR_ENGINE_NOT_FOUND             = TIZEN_ERROR_TTS | 0x03,       /**< No available engine */
        TTSD_ERROR_OPERATION_FAILED             = TIZEN_ERROR_TTS | 0x04,       /**< Operation failed */
        TTSD_ERROR_AUDIO_POLICY_BLOCKED         = TIZEN_ERROR_TTS | 0x05,       /**< Audio policy blocked */
-       TTSD_ERROR_NOT_SUPPORTED_FEATURE        = TIZEN_ERROR_TTS | 0x06        /**< Not supported feature of current engine*/
+       TTSD_ERROR_NOT_SUPPORTED_FEATURE        = TIZEN_ERROR_TTS | 0x06,       /**< Not supported feature of current engine*/
+       TTSD_ERROR_SERVICE_RESET                = TIZEN_ERROR_TTS | 0x07        /**< Service reset */
 } ttsd_error_e;
 
 typedef enum {
index f3343cc..4addebd 100644 (file)
@@ -407,9 +407,38 @@ void __screen_reader_changed_cb(bool value)
 /*
 * Server APIs
 */
+static bool __send_reset_signal(int pid, int uid, app_state_e state, void* user_data)
+{
+       ttsdc_send_error_message(pid, uid, -1, TTSD_ERROR_SERVICE_RESET, "TTS service reset");
+       return true;
+}
+
+static void __sig_handler(int signo)
+{
+       /* restore signal handler */
+       signal(signo, SIG_DFL);
+
+       /* Send error signal via foreach clients */
+       ttsd_data_foreach_clients(__send_reset_signal, NULL);
+
+       /* invoke signal again */
+       raise(signo);
+}
+
+static void __register_sig_handler()
+{
+       signal(SIGSEGV, __sig_handler);
+       signal(SIGABRT, __sig_handler);
+       signal(SIGTERM, __sig_handler);
+       signal(SIGINT, __sig_handler);
+       signal(SIGQUIT, __sig_handler);
+}
 
 int ttsd_initialize()
 {
+       /* Register signal handler */
+       __register_sig_handler();
+       
        if (ttsd_config_initialize(__config_changed_cb)) {
                SLOG(LOG_ERROR, get_tag(), "[Server WARNING] Fail to initialize config.");
        }