diff --git a/log_manager/log_manager.cc b/log_manager/log_manager.cc index 8092e3a1a..bdb43d187 100644 --- a/log_manager/log_manager.cc +++ b/log_manager/log_manager.cc @@ -358,7 +358,7 @@ static bool logmanager_init_nomutex( } /** Initialize and start filewriter thread */ - fw->fwr_thread = skygw_thread_init(strdup("filewriter thr"), + fw->fwr_thread = skygw_thread_init("filewriter thr", thr_filewriter_fun, (void *)fw); diff --git a/log_manager/test/testlog.c b/log_manager/test/testlog.c index a308cd55f..981c9a8cf 100644 --- a/log_manager/test/testlog.c +++ b/log_manager/test/testlog.c @@ -153,7 +153,7 @@ int main(int argc, char* argv[]) #if defined(TEST1) mes = skygw_message_init(); - mtx = simple_mutex_init(NULL, strdup("testmtx")); + mtx = simple_mutex_init(NULL, "testmtx"); /** Test starts */ fprintf(stderr, "\nStarting test #1 \n"); diff --git a/utils/skygw_utils.cc b/utils/skygw_utils.cc index 5e54545f8..dfdd3510b 100644 --- a/utils/skygw_utils.cc +++ b/utils/skygw_utils.cc @@ -322,9 +322,7 @@ mlist_t* mlist_init( list->mlist_name = name; } /** Create mutex, return NULL if fails. */ - if (simple_mutex_init( - &list->mlist_mutex, - strdup("writebuf mutex")) == NULL) + if (simple_mutex_init(&list->mlist_mutex, "writebuf mutex") == NULL) { ss_dfprintf(stderr, "* Creating rwlock for mlist failed\n"); mlist_free_memory(list, name); @@ -977,20 +975,21 @@ void slist_done( * @node Initialize thread data structure * * Parameters: - * @param void - - * + * @param name copy is taken and stored to thread structure * * @param sth_thrfun - * * - * @return + * @param data thread data pointer + * + * @return thread pointer or NULL in case of failure * * * @details (write detailed description here) * */ skygw_thread_t* skygw_thread_init( - char* name, + const char* name, void* (*sth_thrfun)(void* data), void* data) { @@ -1006,8 +1005,8 @@ skygw_thread_t* skygw_thread_init( th->sth_chk_tail = CHK_NUM_THREAD; th->sth_parent = pthread_self(); ss_debug(th->sth_state = THR_INIT;) - th->sth_name = name; - th->sth_mutex = simple_mutex_init(NULL, strdup(name)); + th->sth_name = strndup(name, PATH_MAX); + th->sth_mutex = simple_mutex_init(NULL, name); if (th->sth_mutex == NULL) { thread_free_memory(th, th->sth_name); @@ -1214,10 +1213,13 @@ void release_lock( * @node Create a simple_mutex structure which encapsulates pthread_mutex. * * Parameters: - * @param name - - * + * @param mutexptr if mutex is initialized within caller's memory, this is + * the address for it. If mutex is flat, there is value, otherwise it is NULL. * - * @return + * @param name name of mutex, passed argument is copied and pointer is stored + * to mutex struct. + * + * @return simple_mutex pointer or NULL in case of failure. * * * @details If mutex is flat, sm_enabled can be read if the memory is not freed. @@ -1228,7 +1230,7 @@ void release_lock( */ simple_mutex_t* simple_mutex_init( simple_mutex_t* mutexptr, - char* name) + const char* name) { int err; simple_mutex_t* sm; @@ -1245,7 +1247,7 @@ simple_mutex_t* simple_mutex_init( sm->sm_chk_top = CHK_NUM_SIMPLE_MUTEX; sm->sm_chk_tail = CHK_NUM_SIMPLE_MUTEX; #endif - sm->sm_name = name; + sm->sm_name = strndup(name, PATH_MAX); /** Create pthread mutex */ err = pthread_mutex_init(&sm->sm_mutex, NULL); diff --git a/utils/skygw_utils.h b/utils/skygw_utils.h index 4868fb511..992f169d2 100644 --- a/utils/skygw_utils.h +++ b/utils/skygw_utils.h @@ -117,7 +117,7 @@ bool mlist_cursor_step_ahead(mlist_cursor_t* c); /** Skygw thread routines */ skygw_thread_t* skygw_thread_init( - char* name, + const char* name, void* (*sth_thrfun)(void* data), void* data); void skygw_thread_done(skygw_thread_t* th); @@ -159,7 +159,7 @@ EXTERN_C_BLOCK_BEGIN void acquire_lock(int* l); void release_lock(int* l); -simple_mutex_t* simple_mutex_init(simple_mutex_t* mutexptr, char* name); +simple_mutex_t* simple_mutex_init(simple_mutex_t* mutexptr, const char* name); int simple_mutex_done(simple_mutex_t* sm); int simple_mutex_lock(simple_mutex_t* sm, bool block); int simple_mutex_unlock(simple_mutex_t* sm);