Worked on failure severities, message system, program abort decision

This commit is contained in:
Thomas Schmitt 2007-10-17 13:00:58 +00:00
parent c9db94896d
commit 9c87a830bb
5 changed files with 206 additions and 68 deletions

View File

@ -1772,6 +1772,7 @@ int Xorriso_new(struct XorrisO ** xorriso,char *progname, int flag)
for(i=0; i<4; i++)
m->logfile[i][0]= 0;
m->status_history_max= Xorriso_status_history_maX;
m->library_msg_direct_print= 0;
strcpy(m->abort_on_text,"FATAL");
Xorriso__text_to_sev(m->abort_on_text, &m->abort_on_severity, 0);
m->problem_status= 0;
@ -2316,9 +2317,9 @@ int Xorriso_prepare_regex(struct XorrisO *xorriso, char *adr, int flag)
if(xorriso->search_mode==2 ||
(xorriso->search_mode==3 && xorriso->structured_search==0)) {
no_regex_available:;
sprintf(xorriso->info_text,"%s : regular expressions not implemented\n",
sprintf(xorriso->info_text,"%s : regular expressions not implemented",
xorriso->progname);
Xorriso_info(xorriso,0);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
@ -2328,8 +2329,8 @@ no_regex_available:;
if(xorriso->search_mode==3 || xorriso->search_mode==4) {
l= strlen(adr)+strlen(xorriso->wdi)+1;
if(l*2+2>sizeof(xorriso->reg_expr) || l*2+2>sizeof(adr_part)) {
sprintf(xorriso->info_text,"%s : search text too long\n",xorriso->progname);
Xorriso_info(xorriso,0);
sprintf(xorriso->info_text,"Search pattern too long");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
}
@ -2426,8 +2427,8 @@ no_regex_available:;
#else /* Xorriso_with_regeX */
if(!warned_of_regex) {
sprintf(xorriso->info_text,
"=== Note: no wildcards get recognized besides single '*'\n");
Xorriso_info(xorriso,0);
"No wildcards get recognized besides single '*'");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING",0);
warned_of_regex= 1;
}
if(Sregex_string(&(xorriso->re_constants[xorriso->re_fill]),adr_part,0)
@ -2445,9 +2446,8 @@ next_adr_part:;
cpt++;
}
if(bonked) {
sprintf(xorriso->info_text,
"=== Note: Your '..' bonked at the root directory.\n");
Xorriso_info(xorriso,0);
sprintf(xorriso->info_text, "Your '..' bonked at the root directory.");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING",0);
}
Xorriso__bourne_to_reg(adr_start,xorriso->reg_expr,0); /* just for show */
@ -2485,14 +2485,15 @@ next_adr_part:;
return(-1);
if(regcomp(&(xorriso->re[0]),xorriso->reg_expr,0)!=0) {
cannot_compile:;
sprintf(xorriso->info_text,
"%s : cannot compile regular expression : %s\n",
xorriso->progname,xorriso->reg_expr);
Xorriso_info(xorriso,0);
sprintf(xorriso->info_text, "Cannot compile regular expression : %s",
xorriso->reg_expr);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY",0);
return(0);
}
#else /* Xorriso_with_regeX */
sprintf(xorriso->info_text,
"No wildcards get recognized besides single '*'");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING",0);
Xorriso_info(xorriso,0);
if(Sregex_string(&(xorriso->re_constants[0]),adr,0)<=0)
return(-1);
@ -2866,6 +2867,12 @@ int Xorriso_exec(struct XorrisO *xorriso, char *cmd, int flag)
int is_done= 0,argc= 0,widx= 0,cmd_l,pass,ret;
cmd_l= strlen(cmd);
if(cmd_l>SfileadrL) {
sprintf(xorriso->info_text,
"Command for external process too long : %d (max %d)",
cmd_l, SfileadrL);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
}
for(pass=0;pass<2;pass++) {
is_done= 0;
widx= 0;
@ -2900,12 +2907,11 @@ int Xorriso_exec(struct XorrisO *xorriso, char *cmd, int flag)
for(widx=0; widx<cmd_l; widx++)
if(cmd[widx]==0)
cmd[widx]= ' ';
sprintf(xorriso->info_text,"--- failed : %s\n",cmd);
Xorriso_info(xorriso,0);
if(errmsg[0]!=0) {
sprintf(xorriso->info_text,"--- message: %s\n",errmsg);
Xorriso_info(xorriso,1);
}
sprintf(xorriso->info_text,"External process failed : %s",cmd);
if(errmsg[0]!=0)
sprintf(xorriso->info_text+strlen(xorriso->info_text),
"message: %s\n",errmsg);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 1);
{ret= 0; goto ex;}
}
ret= 1;
@ -2954,6 +2960,10 @@ int Xorriso_set_problem_status(struct XorrisO *xorriso, char *severity,
/* Note: It is ok to submit xorriso->info_text as msg_text here. */
/* flag:
bit0= for Xorriso_info() : use pager (as with result)
bit1= for Xorriso_info() : permission to suppress output
*/
int Xorriso_msgs_submit(struct XorrisO *xorriso,
int error_code, char msg_text[], int os_errno,
char severity[], int flag)
@ -2973,6 +2983,9 @@ int Xorriso_msgs_submit(struct XorrisO *xorriso,
}
/* Report problem event */
/* >>> need option with threshhold for message reporting */
sprintf(prefix,"xorriso : %s : ", sev_text);
li= strlen(prefix);
lt= strlen(msg_text);
@ -2989,17 +3002,48 @@ int Xorriso_msgs_submit(struct XorrisO *xorriso,
}
xorriso->info_text[li+lt]= '\n';
xorriso->info_text[li+lt+1]= 0;
Xorriso_info(xorriso,0);
Xorriso_info(xorriso,flag&3);
if(os_errno>0) {
/* >>> report errno and strerror */;
/* (errno > 0 ? strerror(errno) : "unknown error"), errno); */
sprintf(xorriso->info_text, "xorriso : system: %s (%d)\n",
strerror(os_errno), os_errno);
Xorriso_info(xorriso,flag&3);
}
return(1);
}
int Xorriso_eval_problem_status(struct XorrisO *xorriso, int ret, int flag)
{
static int sev= 0;
if(sev==0)
Xorriso__text_to_sev("SORRY", &sev, 0);
Xorriso_process_msg_queues(xorriso, 0);
if(ret>0 && xorriso->problem_status <= 0)
return(1);
if(xorriso->problem_status < xorriso->abort_on_severity &&
xorriso->problem_status > 0) {
if(xorriso->problem_status >= sev) {
sprintf(xorriso->info_text,
"xorriso : NOTE : Tolerated problem event of severity '%s'\n",
xorriso->problem_status_text);
Xorriso_info(xorriso, 0);/* submit not as problem event */
}
ret= 2;
} else if(xorriso->problem_status > 0) {
sprintf(xorriso->info_text,
"xorriso : ABORT : -abort_on '%s' encountered '%s'",
xorriso->abort_on_text, xorriso->problem_status_text);
Xorriso_info(xorriso, 0);/* submit not as problem event */
ret= -1;
} else if(ret>0)
ret= 1;
return(ret);
}
/* ---------------------------- Options API ------------------------ */
@ -3104,9 +3148,9 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
int ret, l;
if (strlen(iso_rr_path)>sizeof(xorriso->wdi)) {
sprintf(xorriso->info_text,"%s: -cdi: iso_rr_path too long (%d > %d)\n",
xorriso->progname, strlen(iso_rr_path), sizeof(xorriso->wdi)-1);
Xorriso_info(xorriso,0);
sprintf(xorriso->info_text,"-cdi: iso_rr_path too long (%d > %d)",
strlen(iso_rr_path), sizeof(xorriso->wdi)-1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
sprintf(xorriso->info_text,"previous working directory:\n");
@ -3148,9 +3192,9 @@ int Xorriso_option_cdx(struct XorrisO *xorriso, char *disk_path, int flag)
int ret, l;
if (strlen(disk_path)>sizeof(xorriso->wdx)) {
sprintf(xorriso->info_text,"%s: -cdx: disk_path too long (%d > %d)\n",
xorriso->progname, strlen(disk_path), sizeof(xorriso->wdx)-1);
Xorriso_info(xorriso,0);
sprintf(xorriso->info_text,"-cdx: disk_path too long (%d > %d)",
strlen(disk_path), sizeof(xorriso->wdx)-1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
sprintf(xorriso->info_text,"previous working directory on hard disk:\n");
@ -3166,13 +3210,14 @@ int Xorriso_option_cdx(struct XorrisO *xorriso, char *disk_path, int flag)
ret= 1;
ret= Sfile_type(disk_path,1|4|8);
if(ret<0) {
sprintf(xorriso->info_text,"-cdx: file not found :\n%s\n",disk_path);
sprintf(xorriso->info_text,"-cdx: file not found :\n%s",disk_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(ret!=2) {
sprintf(xorriso->info_text,
"-cdx: file is not a directory :\n%s\n",disk_path);
Xorriso_info(xorriso,0);
"-cdx: file is not a directory :\n%s",disk_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(Sfile_str(xorriso->wdx,disk_path,0)<=0)
@ -3800,8 +3845,8 @@ int Xorriso_option_logfile(struct XorrisO *xorriso, char *channel,
if(channel[0]==0) {
logfile_wrong_form:;
sprintf(xorriso->info_text,"--- Wrong form. Correct would be: -logfile \".\"|\"R\"|\"I\"|\"M\" file_address\n");
Xorriso_info(xorriso,0);
sprintf(xorriso->info_text,"Wrong form. Correct would be: -logfile \".\"|\"R\"|\"I\"|\"M\" file_address");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
hflag= 2;
@ -3820,10 +3865,8 @@ logfile_wrong_form:;
xorriso->logfile[channel_no][0]= 0;
ret= Write_to_channel(fileadr,channel_no,hflag);
if(ret<=0) {
sprintf(xorriso->info_text,
"--- Cannot open logfile: %s\n %s\n",
fileadr,(errno>0?strerror(errno):"-unknown error-"));
Xorriso_info(xorriso,0);
sprintf(xorriso->info_text, "Cannot open logfile: %s", fileadr);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
} else if(!(hflag&(1<<15)))
if(Sfile_str(xorriso->logfile[channel_no], fileadr, 0)<=0)
return(-1);
@ -3906,8 +3949,8 @@ return:
char **argv= NULL;
if(adr[0]==0) {
sprintf(xorriso->info_text,"--- Empty file name with -options_from_file\n");
Xorriso_info(xorriso,0);
sprintf(xorriso->info_text,"Empty file name given with -options_from_file");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
Text_shellsafe(adr,shellsafe,0);
@ -3956,9 +3999,9 @@ ex:;
fclose(fp);
if(ret<=0) {
sprintf(xorriso->info_text,
"--- error triggered by line %d of file:\n %s\n",
linecount,shellsafe);
Xorriso_info(xorriso,1);
"error triggered by line %d of file:\n %s\n",
linecount,shellsafe);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 1);
}
return(ret);
}
@ -3977,9 +4020,9 @@ int Xorriso_option_page(struct XorrisO *xorriso, int len, int width, int flag)
{
if(len<0 || width<=0) {
sprintf(xorriso->info_text,
"--- Improper numeric value of arguments of -page: %d %d\n",
"Improper numeric value of arguments of -page: %d %d",
len, width);
Xorriso_info(xorriso,1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
xorriso->result_page_length= len;
@ -4032,9 +4075,9 @@ int Xorriso_option_prog(struct XorrisO *xorriso, char *name, int flag)
{
if(strlen(name)>=sizeof(xorriso->progname)) {
sprintf(xorriso->info_text,
"--- Name too long with option -prog (%d > %d)\n",
strlen(name), sizeof(xorriso->progname)-1);
Xorriso_info(xorriso,1);
"Name too long with option -prog (%d > %d)",
strlen(name), sizeof(xorriso->progname)-1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(Sfile_str(xorriso->progname,name,0)<=0)
@ -4634,7 +4677,7 @@ next_command:;
"=== Input line beginning with '-' is not a known option\n");
sprintf(xorriso->info_text+strlen(xorriso->info_text),
"=== '%s'\n",cmd);
Xorriso_info(xorriso,0);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
{ret= 0; goto ex;}
} else {
@ -4644,19 +4687,11 @@ next_command:;
sprintf(xorriso->info_text, "Ignored argument : '%s'", cmd);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
}
if(ret<=0) {
if(xorriso->problem_status < xorriso->abort_on_severity &&
xorriso->problem_status > 0) {
sprintf(xorriso->info_text,
"xorriso: NOTE : Tolerated problem event of severity '%s'",
xorriso->problem_status_text);
Xorriso_info(xorriso, 0);/* submit as info output, not as problem event */
ret= 2;
} else if(xorriso->problem_status > 0) {
ret= -1; goto ex;
} else
goto ex;
}
ret= Xorriso_eval_problem_status(xorriso, ret, 0);
if(ret<0)
return(ret);
if(*idx<argc)
goto next_command;
@ -4873,6 +4908,7 @@ int Xorriso_main(int argc, char **argv)
ret= Xorriso_startup_libraries(xorriso, 0);
if(ret<=0)
exit(4);
Xorriso_process_msg_queues(xorriso, 0);
/* Interpret startup file */
if(!xorriso->no_rc) {
@ -4897,6 +4933,7 @@ int Xorriso_main(int argc, char **argv)
exit(6);
}
end_sucessfully:;
Xorriso_process_msg_queues(xorriso, 0);
Xorriso_destroy(&xorriso,0);
exit(0);
}

View File

@ -16,8 +16,107 @@
struct XorrisO;
/* --------------------- Problem Status and Message API ------------------- */
/** Submit a problem message to the xorriso problem reporting and handling
system. This will eventually increase problem status rank, which may
at certain stages in the program be pardoned and reset to 0.
The pardon is governed by Xorriso_option_abort_on() and by the anger
of the affected program part. If no pardon has been given, then the problem
status reaches the caller of option functions.
Problem status should be inquired by Xorriso_eval_problem_status() and be
reset before next option execution by Xorriso_set_problem_status().
The problem status itself does not cause the failure of option functions.
But in case of failures for other reasons, a remnant overly severe problem
status can cause overly harsh program reactions.
@param xorriso The environment handle
@param error_code The unique error code of your message.
Submit 0 if you do not have reserved error codes within
the libburnia project.
@param msg_text Not more than 8196 characters of message text.
A final newline character gets appended automatically.
@param os_errno Eventual errno related to the message. Submit 0 if
the message is not related to a operating system error.
@param severity One of "ABORT", "FATAL", "SORRY", "WARNING", "HINT",
"NOTE", "UPDATE", "DEBUG". Defaults to "FATAL".
@param flag Bitfield for control purposes
bit0= use pager (as with result)
bit1= permission to suppress output
@return 1 if message was delivered, <=0 if failure
*/
int Xorriso_msgs_submit(struct XorrisO *xorriso,
int error_code, char msg_text[], int os_errno,
char severity[], int flag);
/** Evaluate an advise whether to abort or whether to go on with option
processing. This should be called after any option function was processed.
It updates the problem status by processing the library message queues
and then it uses this status and the submitted return value ot the
option function to evaluate the situation.
@param xorriso The environment handle
@param ret The return value of the prviously called option function
@param flag Unused yet. Submit 0.
@return Gives the advice:
2= pardon was given, go on
1= no problem, go on
0= function failed but xorriso would not abort, go on
<0= do abort
*/
int Xorriso_eval_problem_status(struct XorrisO *xorriso, int ret, int flag);
/** Set the current problem status of the xorriso handle.
@param xorriso The environment handle
@param severity A severity text. Empty text resets to "No Problem".
@param flag Unused yet. Submit 0.
@return <=0 failure (e.g. wrong severity text), 1 success.
*/
int Xorriso_set_problem_status(struct XorrisO *xorriso, char *severity,
int flag);
/* The next two functions are part of Xorriso_eval_problem_status().
You may use them to build an own advisor function or to drain the
library message queues more frequently.
*/
/** Obtain the current problem status of the xorriso handle.
@param xorriso The environment handle
@param severity The severity text matching the current problem status
@param flag Unused yet. Submit 0.
@return The severity rank number. 0= no problem occured.
*/
int Xorriso_get_problem_status(struct XorrisO *xorriso, char severity[80],
int flag);
/** Forward any pending messages from the library message queues to the
xorriso message system which puts out on info channel. This registers
the severity of the library events like the severity of a message submitted
via Xorriso_msgs_submit().
xorriso sets the message queues of the libraries to queuing "ALL".
So it is essential that they get
@param xorriso The environment handle
@param flag Unused yet. Submit 0.
@return 1 on success, <=0 if failure
*/
int Xorriso_process_msg_queues(struct XorrisO *xorriso, int flag);
/* ---------------------------- Options API ------------------------ */
/* See man 1 xorriso for explanation of the particular options */
/*
Before each call to an option function, there should happen:
Xorriso_set_problem_status() with empty severity text.
After each call to an option function, there should happen:
Xorriso_eval_problem_status()
One should follow its eventual advice to abort.
*/
/* Option -abort_on */
int Xorriso_option_abort_on(struct XorrisO *xorriso, char *severity, int flag);

View File

@ -123,8 +123,11 @@ struct XorrisO { /* the global context of xorriso */
int status_history_max; /* for -status long_history */
/* >>> put -abort_on severity parameters here <<< */
char abort_on_severity[20];
int library_msg_direct_print;
char abort_on_text[20];
int abort_on_severity; /* A severity rank number as threshold */
int problem_status; /* Severity rank number. 0= no abort condition present */
char problem_status_text[20];
/* temporary search facilities */
#ifdef Xorriso_with_regeX
@ -142,7 +145,7 @@ struct XorrisO { /* the global context of xorriso */
int is_dialog;
int bar_is_fresh;
char pending_option[SfileadrL]; /* eventual option entered at page prompt */
int request_to_abort;
int request_to_abort; /* abort a single operation like -ls, not the program */
double idle_time;
int re_failed_at; /* mismatch position with structured_search */
int prepended_wd;

View File

@ -1 +1 @@
#define Xorriso_timestamP "2007.10.16.210911"
#define Xorriso_timestamP "2007.10.17.130041"

View File

@ -33,6 +33,5 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
int Xorriso__text_to_sev(char *severity_name, int *severity_number,int flag);
#endif /* Xorrisoburn_includeD */