diff --git a/xorriso/text_io.c b/xorriso/text_io.c index bb7c77ce..c0e33a2b 100644 --- a/xorriso/text_io.c +++ b/xorriso/text_io.c @@ -888,8 +888,9 @@ static int Xorriso_write_to_msglist(struct XorrisO *xorriso, struct Xorriso_lsT *msglist; ret= Xorriso_lock_outlists(xorriso, 0); - if(ret > 0) - locked= 1; + if(ret <= 0) + goto ex; + locked= 1; msglist= *xorriso_msglist; ret= Xorriso_lst_append_binary(&msglist, text, strlen(text) + 1, 0); if(ret <= 0) { @@ -1174,9 +1175,12 @@ int Xorriso_push_outlists(struct XorrisO *xorriso, int *stack_handle, int ret, locked= 0; ret= Xorriso_lock_outlists(xorriso, 0); - if(ret > 0) - locked= 1; + if(ret <= 0) + goto ex; + locked= 1; if(xorriso->msglist_stackfill + 1 >= Xorriso_max_outlist_stacK) { + Xorriso_unlock_outlists(xorriso, 0); + locked= 0; Xorriso_msgs_submit(xorriso, 0, "Overflow of message output redirection stack", 0, "FATAL", 0); ret= -1; goto ex; @@ -1215,12 +1219,15 @@ int Xorriso_fetch_outlists(struct XorrisO *xorriso, int stack_handle, flag|= 3; ret= Xorriso_lock_outlists(xorriso, 0); - if(ret > 0) - locked= 1; + if(ret <= 0) + goto ex; + locked= 1; if(stack_handle == -1) stack_handle= xorriso->msglist_stackfill - 1; if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill) { + Xorriso_unlock_outlists(xorriso, 0); + locked= 0; Xorriso_msgs_submit(xorriso, 0, "Program error: Wrong message output redirection stack handle", 0, "FATAL", 0); @@ -1304,12 +1311,15 @@ int Xorriso_pull_outlists(struct XorrisO *xorriso, int stack_handle, int i, ret, locked= 0; ret= Xorriso_lock_outlists(xorriso, 0); - if(ret > 0) - locked= 1; + if(ret <= 0) + goto ex; + locked= 1; if(stack_handle == -1) stack_handle= xorriso->msglist_stackfill - 1; if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill) { + Xorriso_unlock_outlists(xorriso, 0); + locked= 0; Xorriso_msgs_submit(xorriso, 0, "Program error: Wrong message output redirection stack handle", 0, "FATAL", 0); @@ -1442,7 +1452,7 @@ int Xorriso_process_msg_lists(struct XorrisO *xorriso, static void *Xorriso_msg_watcher(void *state_pt) { struct XorrisO *xorriso; - int ret, u_wait= 25000, line_count, sleep_thresh= 20; + int ret, u_wait= 25000, line_count, sleep_thresh= 20, lock_failure= 0; struct Xorriso_lsT *result_list= NULL, *info_list= NULL; static int debug_sev= 0; @@ -1464,8 +1474,12 @@ static void *Xorriso_msg_watcher(void *state_pt) if(xorriso->msg_watcher_state == 3) break; - Xorriso_obtain_lock(xorriso, &(xorriso->msgw_fetch_lock), - "message watcher fetch operation", 1); + ret= Xorriso_obtain_lock(xorriso, &(xorriso->msgw_fetch_lock), + "message watcher fetch operation", 1); + if(ret <= 0) { + lock_failure= 1; + break; + } xorriso->msgw_msg_pending= 1; ret= Xorriso_fetch_outlists(xorriso, -1, &result_list, &info_list, 3); if(ret > 0) { @@ -1495,7 +1509,8 @@ static void *Xorriso_msg_watcher(void *state_pt) } if(xorriso->msgw_info_handler != NULL && debug_sev < xorriso->report_about_severity && - debug_sev < xorriso->abort_on_severity) + debug_sev < xorriso->abort_on_severity && + !lock_failure) (*xorriso->msgw_info_handler)(xorriso, "xorriso : DEBUG : Concurrent message watcher ended\n"); xorriso->msg_watcher_state= 0; @@ -1631,8 +1646,15 @@ int Xorriso_stop_msg_watcher(struct XorrisO *xorriso, int flag) usleep(u_wait); } - Xorriso_obtain_lock(xorriso, &(xorriso->msgw_fetch_lock), - "message watcher fetch operation", 1); + ret= Xorriso_obtain_lock(xorriso, &(xorriso->msgw_fetch_lock), + "message watcher fetch operation", 1); + if(ret <= 0) { + Xorriso_msgs_submit(xorriso, 0, + "Cannot obtain mutex lock for managing concurrent message watcher", + ret, "FATAL", 0); + ret= -1; + goto ex; + } xorriso->msgw_msg_pending= 1; ret= Xorriso_pull_outlists(xorriso, xorriso->msgw_stack_handle, &result_list, &info_list, 0); diff --git a/xorriso/xorriso_timestamp.h b/xorriso/xorriso_timestamp.h index 03988e66..41ab77e9 100644 --- a/xorriso/xorriso_timestamp.h +++ b/xorriso/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2015.11.13.202241" +#define Xorriso_timestamP "2015.11.15.153822"