fixup! Fix hanging on pthread_cond_destroy during cancellation of thread by broadcast... 83/229883/4 accepted/tizen_6.0_unified accepted/tizen_6.0_unified_hotfix tizen_6.0 tizen_6.0_hotfix accepted/tizen/6.0/unified/20201030.122545 accepted/tizen/6.0/unified/hotfix/20201103.004849 accepted/tizen/6.0/unified/hotfix/20201103.052228 accepted/tizen/6.5/unified/20211028.100049 accepted/tizen/unified/20200408.131520 submit/tizen/20200407.090338 submit/tizen_6.0/20201029.205102 submit/tizen_6.0_hotfix/20201102.192502 submit/tizen_6.0_hotfix/20201103.114802 submit/tizen_6.5/20211028.161801 tizen_6.0.m2_release tizen_6.5.m2_release
authorSeungbae Shin <seungbae.shin@samsung.com>
Mon, 6 Apr 2020 07:44:13 +0000 (16:44 +0900)
committerSeungbae Shin <seungbae.shin@samsung.com>
Tue, 7 Apr 2020 03:25:32 +0000 (12:25 +0900)
+ fix minor build warnings due to strncpy

[Version] 0.0.21
[Issue Type] Bug

Change-Id: I5db46a4effabb6c9d4dd5d1538ab9141886549e7

packaging/capi-media-sound-pool.spec
src/stream_cb_manager.c
test/proxy/src/proxy.c
test/sound_pool_test.c

index 82fd888..445faff 100644 (file)
@@ -1,5 +1,5 @@
 Name:       capi-media-sound-pool
-Version:    0.0.20
+Version:    0.0.21
 Summary:    Tizen Sound Pool module
 Release:    0
 Group:      Multimedia/Framework
index 886e70d..3bf22d5 100644 (file)
@@ -23,7 +23,6 @@
 #include "internal/stream_cb_manager.h"
 
 static gpointer __sound_pool_callback_isolator(gpointer user_data);
-static void __thread_cancel_cleanup();
 static void __queue_destroy_item(gpointer data);
 
 static void __queue_destroy_item(gpointer data)
@@ -35,22 +34,6 @@ static void __queue_destroy_item(gpointer data)
        SP_DEBUG_FLEAVE();
 }
 
-static void __thread_cancel_cleanup(void *user_data)
-{
-       SP_DEBUG_FENTER();
-
-       stream_cb_manager_t *cbmgr = (stream_cb_manager_t *)user_data;
-       g_async_queue_unref(cbmgr->isolator_callback_queue);
-
-       pthread_cond_broadcast(&cbmgr->isolator_data_cond);
-       pthread_cond_destroy(&cbmgr->isolator_data_cond);
-       pthread_mutex_destroy(&cbmgr->isolator_data_mutex);
-
-       SP_SAFE_GFREE(cbmgr);
-
-       SP_DEBUG_FLEAVE();
-}
-
 sound_pool_error_e _stream_cb_manager_process_pending_events(stream_cb_manager_t *cbmgr)
 {
        SP_DEBUG_FENTER();
@@ -91,24 +74,19 @@ sound_pool_error_e _stream_cb_manager_signal_completed_events(stream_cb_manager_
 static gpointer __sound_pool_callback_isolator(gpointer user_data)
 {
        SP_DEBUG_FENTER();
-       int err = pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL);
-       if (err != 0)
-               SP_INFO("Can't setup cancel type for isolation thread with error [%d].", err);
-       err = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
-       if (err != 0)
-               SP_INFO("Can't setup cancel state for isolation thread with error [%d].", err);
        SP_RETVM_IF(!user_data, NULL, "User data is NULL. Terminate callback thread");
 
        stream_cb_manager_t *cbmgr = (stream_cb_manager_t *)user_data;
-       pthread_cleanup_push(__thread_cancel_cleanup,  user_data);
        pthread_mutex_lock(&cbmgr->isolator_data_mutex);
-       gboolean runing = cbmgr->isolator_loop_run;
-       pthread_mutex_unlock(&cbmgr->isolator_data_mutex);
 
-       while (runing) {
-               pthread_mutex_lock(&cbmgr->isolator_data_mutex);
-               while (!cbmgr->isolator_state_changed)
+       while (cbmgr->isolator_loop_run) {
+               while (!cbmgr->isolator_state_changed) {
                        pthread_cond_wait(&cbmgr->isolator_data_cond, &cbmgr->isolator_data_mutex);
+                       if (!cbmgr->isolator_loop_run) {
+                               SP_INFO("terminating loop");
+                               goto exit;
+                       }
+               }
                pthread_mutex_unlock(&cbmgr->isolator_data_mutex);
 
                /* Iterate streams have been pushed to the queue and call for each
@@ -126,15 +104,14 @@ static gpointer __sound_pool_callback_isolator(gpointer user_data)
                        }
                        SP_SAFE_GFREE(event_data);
                }
+
                /* Signal indicating isolator callback thread completed the events */
                _stream_cb_manager_signal_completed_events(cbmgr);
-
                pthread_mutex_lock(&cbmgr->isolator_data_mutex);
-               runing = cbmgr->isolator_loop_run;
-               pthread_mutex_unlock(&cbmgr->isolator_data_mutex);
        }
 
-       pthread_cleanup_pop(0);
+exit:
+       pthread_mutex_unlock(&cbmgr->isolator_data_mutex);
        SP_DEBUG_FLEAVE();
        return NULL;
 }
@@ -226,38 +203,25 @@ sound_pool_error_e _stream_cb_manager_destroy(stream_cb_manager_t *cbmgr)
 
        /* Wait for completing the isolator callback thread events */
        _stream_cb_manager_process_pending_events(cbmgr);
-       err = pthread_kill(thread, 0);
-       if (0 == err) {
-               err = pthread_cancel(thread);
-               if (0 != err) {
-                       SP_ERROR("Error while cancelling of isolation thread[%d].", err);
-                       ret = SOUND_POOL_ERROR_INVALID_OPERATION;
-                       GOTO_FAIL("", creturn);
-               }
-       } else {
-               SP_ERROR("Invalid isolation thread[%d].", err);
-               ret = SOUND_POOL_ERROR_INVALID_OPERATION;
-               GOTO_FAIL("", creturn);
-       }
+
+       /* stop thread and wait join */
+       pthread_mutex_lock(&cbmgr->isolator_data_mutex);
+       cbmgr->isolator_loop_run = FALSE;
+       pthread_cond_signal(&cbmgr->isolator_data_cond);
+       pthread_mutex_unlock(&cbmgr->isolator_data_mutex);
 
        err = pthread_join(thread, &return_val);
-       if (0 != err)
+       if (0 != err) {
                SP_ERROR("Error while joining of isolation thread[%d].", err);
-       if (return_val == PTHREAD_CANCELED)
-               SP_INFO("Isolation thread canceled.");
-       else {
-               ret = SOUND_POOL_ERROR_NONE;
-               GOTO_FAIL("Routine joining of isolation thread.", creturn);
+               ret = SOUND_POOL_ERROR_INVALID_OPERATION;
        }
 
-       SP_DEBUG_FLEAVE();
-       return ret;
-
-creturn:
        g_async_queue_unref(cbmgr->isolator_callback_queue);
-       pthread_mutex_destroy(&cbmgr->isolator_data_mutex);
        pthread_cond_destroy(&cbmgr->isolator_data_cond);
+       pthread_mutex_destroy(&cbmgr->isolator_data_mutex);
+
        SP_SAFE_GFREE(cbmgr);
+
        SP_DEBUG_FLEAVE();
        return ret;
 }
index d681ccf..8e12559 100644 (file)
@@ -679,8 +679,11 @@ static int __proxy_sound_pool_load_source_from_file(const char *pars)
                _logger_log_warn("Pool with specified identifier is NULL");
 
        /* If tag wasn't specified by the user, we will use file path as a tag */
-       if (tag[0] == '\0')
+       if (tag[0] == '\0') {
                strncpy(tag, fname, MAX_PATH_LEN - 1);
+               tag[MAX_PATH_LEN - 1] = '\0';
+       }
+
 
        _logger_log_info(CMD_LOAD_SOURCE " command was called");
        _logger_log_info("Loading source to the pool with %zu identifier from %s file. "
index 92a42b7..28ecf47 100644 (file)
@@ -22,6 +22,7 @@
 #include <termios.h>
 #include <unistd.h>
 #include <getopt.h>
+#include <stdlib.h>
 
 #define KEY_CODE_ESCAPE      27
 #define KEY_CODE_BACKSPACE   127
@@ -151,6 +152,8 @@ size_t auto_fill(const char *cmd_start, char fill_hint[MAX_COMMAND_LINE_LEN])
        else
                strncpy(fill_hint, auto_fill, MAX_COMMAND_LINE_LEN - 1);
 
+       fill_hint[MAX_COMMAND_LINE_LEN - 1] = '\0';
+
        return fill_found;
 }