|
|
|
@ -906,19 +906,30 @@ int Xorriso_pull_outlists(struct XorrisO *xorriso, int stack_handle,
|
|
|
|
|
if(ret > 0)
|
|
|
|
|
locked= 1;
|
|
|
|
|
|
|
|
|
|
if(stack_handle == -1)
|
|
|
|
|
stack_handle= xorriso->msglist_stackfill - 1;
|
|
|
|
|
if(stack_handle < 0 || stack_handle >= xorriso->msglist_stackfill) {
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0,
|
|
|
|
|
"Program error: Wrong message output redirection stack handle",
|
|
|
|
|
0, "FATAL", 0);
|
|
|
|
|
ret= -1; goto ex;
|
|
|
|
|
}
|
|
|
|
|
*result_list= xorriso->result_msglists[stack_handle];
|
|
|
|
|
*info_list= xorriso->info_msglists[stack_handle];
|
|
|
|
|
for(i = stack_handle + 1; i < xorriso->msglist_stackfill - 1; i++) {
|
|
|
|
|
xorriso->result_msglists[i - 1]= xorriso->result_msglists[i];
|
|
|
|
|
xorriso->info_msglists[i - 1]= xorriso->info_msglists[i];
|
|
|
|
|
|
|
|
|
|
/* Concatenate all redirections above stack_handle */
|
|
|
|
|
*result_list= NULL;
|
|
|
|
|
*info_list= NULL;
|
|
|
|
|
for(i = stack_handle; i < xorriso->msglist_stackfill; i++) {
|
|
|
|
|
if(*result_list == NULL)
|
|
|
|
|
*result_list= xorriso->result_msglists[i];
|
|
|
|
|
else
|
|
|
|
|
Xorriso_lst_concat(*result_list, xorriso->result_msglists[i], 0);
|
|
|
|
|
if(*info_list == NULL)
|
|
|
|
|
*info_list= xorriso->info_msglists[i];
|
|
|
|
|
else
|
|
|
|
|
Xorriso_lst_concat(*info_list, xorriso->info_msglists[i], 0);
|
|
|
|
|
}
|
|
|
|
|
xorriso->msglist_stackfill--;
|
|
|
|
|
xorriso->msglist_stackfill= stack_handle;
|
|
|
|
|
|
|
|
|
|
ret= 1;
|
|
|
|
|
ex:;
|
|
|
|
|
if(locked)
|
|
|
|
@ -927,6 +938,260 @@ ex:;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_result_handler_stdout(struct XorrisO *xorriso, char *text)
|
|
|
|
|
{
|
|
|
|
|
printf("%s", text);
|
|
|
|
|
fflush(stdout);
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_info_handler_stderr(struct XorrisO *xorriso, char *text)
|
|
|
|
|
{
|
|
|
|
|
if(xorriso->stderr_fp != NULL) {
|
|
|
|
|
fprintf(xorriso->stderr_fp, "%s", text);
|
|
|
|
|
fflush(xorriso->stderr_fp);
|
|
|
|
|
} else {
|
|
|
|
|
fprintf(stderr, "%s", text);
|
|
|
|
|
fflush(stderr);
|
|
|
|
|
}
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_process_msg_lists(struct XorrisO *xorriso,
|
|
|
|
|
struct Xorriso_lsT *result_list,
|
|
|
|
|
struct Xorriso_lsT *info_list,
|
|
|
|
|
int *line_count, int flag)
|
|
|
|
|
{
|
|
|
|
|
struct Xorriso_lsT *lpt;
|
|
|
|
|
int ret;
|
|
|
|
|
int (*handler)(struct XorrisO *xorriso, char *text);
|
|
|
|
|
|
|
|
|
|
handler= xorriso->msgw_result_handler;
|
|
|
|
|
if(handler == NULL)
|
|
|
|
|
handler= Xorriso_result_handler_stdout;
|
|
|
|
|
for(lpt= result_list; lpt != NULL; lpt= lpt->next) {
|
|
|
|
|
(*line_count)++;
|
|
|
|
|
ret= (*handler)(xorriso, Xorriso_lst_get_text(lpt, 0));
|
|
|
|
|
if(ret < 0)
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
handler= xorriso->msgw_info_handler;
|
|
|
|
|
if(handler == NULL)
|
|
|
|
|
handler= Xorriso_info_handler_stderr;
|
|
|
|
|
for(lpt= info_list; lpt != NULL; lpt= lpt->next) {
|
|
|
|
|
(*line_count)++;
|
|
|
|
|
ret= (*handler)(xorriso, Xorriso_lst_get_text(lpt, 0));
|
|
|
|
|
if(ret < 0)
|
|
|
|
|
return(-1);
|
|
|
|
|
}
|
|
|
|
|
return(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void *Xorriso_msg_watcher(void *state_pt)
|
|
|
|
|
{
|
|
|
|
|
struct XorrisO *xorriso;
|
|
|
|
|
int ret, u_wait= 10000, line_count, sleep_thresh= 20;
|
|
|
|
|
struct Xorriso_lsT *result_list= NULL, *info_list= NULL;
|
|
|
|
|
static int debug_sev= 0;
|
|
|
|
|
|
|
|
|
|
xorriso= (struct XorrisO *) state_pt;
|
|
|
|
|
|
|
|
|
|
if(debug_sev == 0)
|
|
|
|
|
Xorriso__text_to_sev("DEBUG", &debug_sev, 0);
|
|
|
|
|
|
|
|
|
|
xorriso->msg_watcher_state= 2;
|
|
|
|
|
if(xorriso->msgw_info_handler != NULL &&
|
|
|
|
|
debug_sev < xorriso->report_about_severity &&
|
|
|
|
|
debug_sev < xorriso->abort_on_severity)
|
|
|
|
|
(*xorriso->msgw_info_handler)(xorriso,
|
|
|
|
|
"xorriso : DEBUG : Concurrent message watcher started\n");
|
|
|
|
|
while(1) {
|
|
|
|
|
line_count= 0;
|
|
|
|
|
|
|
|
|
|
/* Watch out for end request in xorriso */
|
|
|
|
|
if(xorriso->msg_watcher_state == 3)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
ret= Xorriso_fetch_outlists(xorriso, -1, &result_list, &info_list, 3);
|
|
|
|
|
if(ret < 0)
|
|
|
|
|
break;
|
|
|
|
|
if(ret > 0) {
|
|
|
|
|
/* Process fetched lines */
|
|
|
|
|
ret= Xorriso_process_msg_lists(xorriso, result_list, info_list,
|
|
|
|
|
&line_count, 0);
|
|
|
|
|
Xorriso_lst_destroy_all(&result_list, 0);
|
|
|
|
|
Xorriso_lst_destroy_all(&info_list, 0);
|
|
|
|
|
if(ret < 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(line_count < sleep_thresh)
|
|
|
|
|
usleep(u_wait);
|
|
|
|
|
}
|
|
|
|
|
if(xorriso->msgw_info_handler != NULL &&
|
|
|
|
|
debug_sev < xorriso->report_about_severity &&
|
|
|
|
|
debug_sev < xorriso->abort_on_severity)
|
|
|
|
|
(*xorriso->msgw_info_handler)(xorriso,
|
|
|
|
|
"xorriso : DEBUG : Concurrent message watcher ended\n");
|
|
|
|
|
xorriso->msg_watcher_state= 0;
|
|
|
|
|
return(NULL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_start_msg_watcher(struct XorrisO *xorriso,
|
|
|
|
|
int (*result_handler)(struct XorrisO *xorriso, char *text),
|
|
|
|
|
int (*info_handler)(struct XorrisO *xorriso, char *text),
|
|
|
|
|
int flag)
|
|
|
|
|
{
|
|
|
|
|
int ret, u_wait= 1000, locked= 0, pushed= 0, uret, line_count= 0;
|
|
|
|
|
struct Xorriso_lsT *result_list= NULL, *info_list= NULL;
|
|
|
|
|
pthread_attr_t attr;
|
|
|
|
|
pthread_attr_t *attr_pt = NULL;
|
|
|
|
|
pthread_t thread;
|
|
|
|
|
|
|
|
|
|
ret= pthread_mutex_lock(&(xorriso->msg_watcher_lock));
|
|
|
|
|
if(ret != 0) {
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0,
|
|
|
|
|
"Cannot aquire mutex lock for managing concurrent message watcher",
|
|
|
|
|
ret, "FATAL", 0);
|
|
|
|
|
ret= -1; goto ex;
|
|
|
|
|
}
|
|
|
|
|
locked= 1;
|
|
|
|
|
|
|
|
|
|
/* Check for running watcher */
|
|
|
|
|
if(xorriso->msg_watcher_state > 0) {
|
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
|
"There is already a concurrent message watcher running");
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
|
|
|
|
|
ret= 0; goto ex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret= Xorriso_push_outlists(xorriso, &(xorriso->msgw_stack_handle), 3);
|
|
|
|
|
if(ret <= 0)
|
|
|
|
|
goto ex;
|
|
|
|
|
pushed= 1;
|
|
|
|
|
|
|
|
|
|
/* Register watcher */
|
|
|
|
|
xorriso->msgw_result_handler= result_handler;
|
|
|
|
|
xorriso->msgw_info_handler= info_handler;
|
|
|
|
|
xorriso->msg_watcher_state= 1;
|
|
|
|
|
|
|
|
|
|
/* Start thread */
|
|
|
|
|
pthread_attr_init(&attr);
|
|
|
|
|
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
|
|
|
|
|
attr_pt= &attr;
|
|
|
|
|
ret= pthread_create(&thread, attr_pt, Xorriso_msg_watcher, xorriso);
|
|
|
|
|
if(ret != 0) {
|
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
|
"Cannot create thread for concurrent message watcher");
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FAILURE", 0);
|
|
|
|
|
ret= 0; goto ex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Wait until watcher has indicated start */
|
|
|
|
|
while(xorriso->msg_watcher_state == 1) {
|
|
|
|
|
|
|
|
|
|
/* >>> have a timeout ? */;
|
|
|
|
|
|
|
|
|
|
usleep(u_wait);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret= 1;
|
|
|
|
|
ex:;
|
|
|
|
|
if(ret <= 0 && pushed) {
|
|
|
|
|
uret= Xorriso_pull_outlists(xorriso, xorriso->msgw_stack_handle,
|
|
|
|
|
&result_list, &info_list, 0);
|
|
|
|
|
if(uret > 0) {
|
|
|
|
|
xorriso->msgw_result_handler= NULL;
|
|
|
|
|
xorriso->msgw_info_handler= NULL;
|
|
|
|
|
Xorriso_process_msg_lists(xorriso, result_list, info_list,
|
|
|
|
|
&line_count, 0);
|
|
|
|
|
Xorriso_lst_destroy_all(&result_list, 0);
|
|
|
|
|
Xorriso_lst_destroy_all(&info_list, 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(locked) {
|
|
|
|
|
uret= pthread_mutex_unlock(&(xorriso->msg_watcher_lock));
|
|
|
|
|
if(uret != 0) {
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0,
|
|
|
|
|
"Cannot release mutex lock for managing concurrent message watcher",
|
|
|
|
|
uret, "FATAL", 0);
|
|
|
|
|
ret= -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* @param flag bit0= do not complain loudly if no wather is active
|
|
|
|
|
*/
|
|
|
|
|
int Xorriso_stop_msg_watcher(struct XorrisO *xorriso, int flag)
|
|
|
|
|
{
|
|
|
|
|
int ret, u_wait= 1000, locked= 0, uret, line_count= 0;
|
|
|
|
|
struct Xorriso_lsT *result_list= NULL, *info_list= NULL;
|
|
|
|
|
|
|
|
|
|
if((flag & 1) && xorriso->msg_watcher_state != 2)
|
|
|
|
|
/* Roughly tolerate non-running watcher */
|
|
|
|
|
{ret= 0; goto ex;}
|
|
|
|
|
|
|
|
|
|
ret= pthread_mutex_lock(&(xorriso->msg_watcher_lock));
|
|
|
|
|
if(ret != 0) {
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0,
|
|
|
|
|
"Cannot aquire mutex lock for managing concurrent message watcher",
|
|
|
|
|
ret, "FATAL", 0);
|
|
|
|
|
ret= -1; goto ex;
|
|
|
|
|
}
|
|
|
|
|
locked= 1;
|
|
|
|
|
|
|
|
|
|
/* Check for running watcher */
|
|
|
|
|
if(xorriso->msg_watcher_state != 2) {
|
|
|
|
|
sprintf(xorriso->info_text,
|
|
|
|
|
"There is no concurrent message watcher running");
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
|
|
|
|
|
ret= 0; goto ex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Inform watcher of desire to stop it */
|
|
|
|
|
xorriso->msg_watcher_state= 3;
|
|
|
|
|
|
|
|
|
|
/* Wait until watcher has indicated its end */
|
|
|
|
|
while(xorriso->msg_watcher_state != 0) {
|
|
|
|
|
|
|
|
|
|
/* >>> have a timeout ? */;
|
|
|
|
|
|
|
|
|
|
usleep(u_wait);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret= Xorriso_pull_outlists(xorriso, xorriso->msgw_stack_handle,
|
|
|
|
|
&result_list, &info_list, 0);
|
|
|
|
|
if(ret > 0) {
|
|
|
|
|
Xorriso_process_msg_lists(xorriso, result_list, info_list,
|
|
|
|
|
&line_count, 0);
|
|
|
|
|
Xorriso_lst_destroy_all(&result_list, 0);
|
|
|
|
|
Xorriso_lst_destroy_all(&info_list, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
xorriso->msgw_result_handler= NULL;
|
|
|
|
|
xorriso->msgw_info_handler= NULL;
|
|
|
|
|
|
|
|
|
|
ret= 1;
|
|
|
|
|
ex:;
|
|
|
|
|
if(locked) {
|
|
|
|
|
uret= pthread_mutex_unlock(&(xorriso->msg_watcher_lock));
|
|
|
|
|
if(uret != 0) {
|
|
|
|
|
Xorriso_msgs_submit(xorriso, 0,
|
|
|
|
|
"Cannot release mutex lock for managing concurrent message watcher",
|
|
|
|
|
uret, "FATAL", 0);
|
|
|
|
|
ret= -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return(ret);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int Xorriso_result(struct XorrisO *xorriso, int flag)
|
|
|
|
|
/*
|
|
|
|
|
bit0= no considerations or computations or dialog. Just put out.
|
|
|
|
|