Fix mtp exit
[platform/core/connectivity/mtp-responder.git] / src / mtp_init.c
index 2f749a1..02a7b1b 100755 (executable)
@@ -67,7 +67,7 @@ static void __mtp_exit(void)
        long cur_time;
 
        DBG("## Terminate all threads");
-       if (g_eh_thrd) {
+       if (g_eh_thrd && g_eh_thrd != pthread_self()) {
                _eh_send_event_req_to_eh_thread(EVENT_USB_REMOVED, 0, 0, NULL);
                if (_util_thread_join(g_eh_thrd, NULL) == FALSE)
                        ERR("_util_thread_join() Fail");
@@ -84,6 +84,9 @@ static void __mtp_exit(void)
 
        g_main_loop_quit(g_mainloop);
 
+       if (g_eh_thrd == pthread_self())
+               _util_thread_exit("Event handler stopped itself");
+
        return;
 }
 
@@ -505,5 +508,7 @@ int main(int argc, char *argv[])
        _eh_deregister_notification_callbacks();
        media_content_disconnect();
 
+       DBG("######### MTP TERMINATED #########");
+
        return MTP_ERROR_NONE;
 }