Worked on failure severities, message system, program abort decision

This commit is contained in:
Thomas Schmitt 2007-10-16 21:09:36 +00:00
parent 35c95322f1
commit 37969ff37f
4 changed files with 238 additions and 111 deletions

View File

@ -13,6 +13,13 @@ or
test/xorriso.c test/xorrisoburn.c \
-lpthread -lreadline -lburn -lisofs -lisoburn
or
cc -g -DXorriso_with_regeX -DXorriso_with_readlinE \
-Wall -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE \
-c \
test/xorriso.c test/xorrisoburn.c
*/
/* Command line oriented batch and dialog tool which creates, loads,
@ -217,10 +224,13 @@ int Sfile_prepend_path(char *prefix, char path[SfileadrL], int flag)
l= strlen(path)+strlen(prefix)+1;
if(l>=SfileadrL) {
/* >>> */
fprintf(stderr,
"--- Combination of wd and relative address too long (%d > %d)\n",
#ifdef Not_yeT
/* >>> ??? how to transport messages to xorriso ? */
sprintf(xorriso->info_text,
"Combination of wd and relative address too long (%d > %d)",
l,SfileadrL-1);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
#endif
return(-1);
}
@ -1762,7 +1772,10 @@ 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;
strcpy(m->abort_on_severity,"SORRY");
strcpy(m->abort_on_text,"FATAL");
Xorriso__text_to_sev(m->abort_on_text, &m->abort_on_severity, 0);
m->problem_status= 0;
m->problem_status_text[0]= 0;
#ifdef Xorriso_with_regeX
m->re= NULL;
/* >>> ??? how to initialize m->match[0] ? */
@ -2798,8 +2811,8 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
is_default= (strcmp(xorriso->abort_on_severity,"SORRY")==0);
sprintf(line,"-abort_on %s\n",xorriso->abort_on_severity);
is_default= (strcmp(xorriso->abort_on_text,"FATAL")==0);
sprintf(line,"-abort_on %s\n",xorriso->abort_on_text);
if(!(is_default && no_defaults))
Xorriso_status_result(xorriso,filter,fp,flag&2);
@ -2917,27 +2930,90 @@ int Xorriso__end_idx(int argc, char **argv, int idx, int flag)
}
int Xorriso_get_problem_status(struct XorrisO *xorriso, char severity[80],
int flag)
{
strcpy(severity, xorriso->problem_status_text);
return(xorriso->problem_status);
}
int Xorriso_set_problem_status(struct XorrisO *xorriso, char *severity,
int flag)
{
char *sev_text= "FATAL";
int sev, ret;
ret= Xorriso__text_to_sev(severity, &sev, 0);
if(ret<=0)
return(0);
xorriso->problem_status= sev;
strcpy(xorriso->problem_status_text, sev_text);
return(1);
}
/* Note: It is ok to submit xorriso->info_text as msg_text here. */
int Xorriso_msgs_submit(struct XorrisO *xorriso,
int error_code, char msg_text[], int os_errno,
char severity[], int flag)
{
int ret, lt, li, sev, i;
char *sev_text= "FATAL", prefix[80];
/* Set problem status */
ret= Xorriso__text_to_sev(severity, &sev, 0);
if(ret<=0)
Xorriso__text_to_sev(sev_text, &sev, 0);
else
sev_text= severity;
if(xorriso->problem_status<sev) {
xorriso->problem_status= sev;
strcpy(xorriso->problem_status_text, sev_text);
}
/* Report problem event */
sprintf(prefix,"xorriso : %s : ", sev_text);
li= strlen(prefix);
lt= strlen(msg_text);
if(lt>sizeof(xorriso->info_text)-li-2)
lt= sizeof(xorriso->info_text)-li-2;
if(msg_text==xorriso->info_text) {
for(i= lt; i>=0; i--)
msg_text[i+li]= msg_text[i];
for(i=0; i<li; i++)
msg_text[i]= prefix[i];
} else {
strcpy(xorriso->info_text, prefix);
strncpy(xorriso->info_text+li, msg_text, lt);
}
xorriso->info_text[li+lt]= '\n';
xorriso->info_text[li+lt+1]= 0;
Xorriso_info(xorriso,0);
if(os_errno>0) {
/* >>> report errno and strerror */;
/* (errno > 0 ? strerror(errno) : "unknown error"), errno); */
}
return(1);
}
/* ---------------------------- Options API ------------------------ */
/* Option -abort_on */
int Xorriso_option_abort_on(struct XorrisO *xorriso, char *severity, int flag)
{
int i;
static char svt[][20]= {"NEVER", "ABORT", "FATAL", "SORRY", "WARNING", "HINT",
"NOTE", "UPDATE", "DEBUG", "ALL", ""};
int ret, sev;
for(i= 0; svt[i][0]!=0; i++)
if(strcmp(svt[i],severity)==0)
break;
if(svt[i][0]==0) {
/* >>> unknown severity class */;
return(0);
}
if(Sfile_str(xorriso->abort_on_severity,severity,0)<=0)
ret= Xorriso__text_to_sev(severity, &sev, 0);
if(ret<=0)
return(ret);
if(Sfile_str(xorriso->abort_on_text,severity,0)<=0)
return(-1);
xorriso->abort_on_severity= sev;
return(1);
}
@ -3048,8 +3124,8 @@ int Xorriso_option_cdi(struct XorrisO *xorriso, char *iso_rr_path, int flag)
if(ret<=0) {
sprintf(xorriso->info_text,
"-cdi: not found or not a directory :\n%s\n",iso_rr_path);
Xorriso_info(xorriso,0);
"-cdi: not found or not a directory :\n%s",iso_rr_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(Sfile_str(xorriso->wdi,iso_rr_path,0)<=0)
@ -3182,9 +3258,8 @@ int Xorriso_option_commit(struct XorrisO *xorriso, int flag)
char newdev[SfileadrL];
if(!xorriso->volset_change_pending) {
/* >>> */
fprintf(stderr, "--- No image modifications pending on -commit\n");
sprintf(xorriso->info_text,"-commit: No image modifications pending");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
return(2);
}
@ -3306,10 +3381,9 @@ int Xorriso_option_eject(struct XorrisO *xorriso, char *which, int flag)
drive2= xorriso->outdev;
}
if(drive1== xorriso->indev && xorriso->volset_change_pending) {
/* >>> */
fprintf(stderr, "--- Image changes pending. -commit or -rollback first\n");
sprintf(xorriso->info_text,
"-eject: Image changes pending. -commit or -rollback first");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
@ -3382,9 +3456,9 @@ int Xorriso_option_fs(struct XorrisO *xorriso, char *size, int flag)
num= Scanf_io_size(size, 0);
if(num < 4096 || num > 1024.0 * 1024.0 * 1024.0) {
/* >>> wrong size */;
sprintf(xorriso->info_text, "-fs: wrong size %.f (allowed: %.f - %.f)",
num, 4096.0, 1024.0 * 1024.0 * 1024.0);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
xorriso->fs= num / 2048.0;
@ -3411,9 +3485,8 @@ int Xorriso_option_gid(struct XorrisO *xorriso, char *gid, int flag)
}
grp= getgrnam(gid);
if(grp==NULL) {
/* >>> unknown group */;
sprintf(xorriso->info_text, "-gid: Not a known group: '%s'", gid);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
xorriso->global_gid= grp->gr_gid;
@ -4123,9 +4196,9 @@ dvd_speed:;
}
if(num> 2.0e9) {
/* >>> too large */;
sprintf(xorriso->info_text,
"-speed: Value too large or not recognizable: '%s'", speed);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
xorriso->speed= num;
@ -4198,9 +4271,8 @@ int Xorriso_option_uid(struct XorrisO *xorriso, char *uid, int flag)
pwd= getpwnam(uid);
if(pwd==NULL) {
/* >>> unknown user */;
sprintf(xorriso->info_text, "-gid: Not a known user: '%s'", uid);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
xorriso->global_uid= pwd->pw_uid;
@ -4250,7 +4322,7 @@ int Xorriso_interpreter(struct XorrisO *xorriso,
int argc, char **argv, int *idx, int flag)
/*
return:
<=0 error , 1 = success , ( 2 = nothing found ) , 3 = end program run
<=0 error , 1 = success , 2 = problem event ignored , 3 = end program run
*/
/*
bit0= recursion
@ -4268,10 +4340,11 @@ return:
if(xorriso->result_page_length<0)
xorriso->result_page_length= -xorriso->result_page_length;
}
xorriso->request_to_abort= 0;
xorriso->prepended_wd= 0;
next_command:;
xorriso->prepended_wd= 0;
xorriso->request_to_abort= 0;
Xorriso_set_problem_status(xorriso, "", 0);
cmd= argv[*idx];
(*idx)++;
@ -4568,11 +4641,22 @@ next_command:;
/* >>> ??? pathspecs for option -add */;
fprintf(stderr, "--- Ignored : %s\n", cmd);
sprintf(xorriso->info_text, "Ignored argument : '%s'", cmd);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "WARNING", 0);
}
if(ret<=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;
}
if(*idx<argc)
goto next_command;
@ -4621,6 +4705,9 @@ int Xorriso_execute_option(struct XorrisO *xorriso, char *line, int flag)
xorriso->error_count);
Xorriso_info(xorriso,!(flag&(1<<16)));
}
/* ??? >>> print elapsed time tdiff ? */;
if((flag&(1<<17)) && !xorriso->bar_is_fresh) {
sprintf(xorriso->info_text,"============================\n");
Xorriso_info(xorriso,0);
@ -4746,6 +4833,15 @@ int Xorriso_read_rc(struct XorrisO *xorriso, int flag)
int main(int argc, char **argv)
{
#else
int Xorriso_main(int argc, char **argv)
{
#endif /* Xorriso_with_maiN */
int ret,i;
struct XorrisO *xorriso= NULL;
@ -4805,5 +4901,3 @@ end_sucessfully:;
exit(0);
}
#endif /* Xorriso_with_maiN */

View File

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

View File

@ -32,6 +32,9 @@
capabilities via the method invented by Andy Polyakov for growisofs */
#include <libisoburn/libisoburn.h>
/* The official xorriso options API. "No shortcuts" */
#include "xorriso.h"
/* The inner description of XorrisO */
#include "xorriso_private.h"
@ -47,33 +50,40 @@ int Xorriso_startup_libraries(struct XorrisO *xorriso, int flag)
int ret;
char *handler_prefix= NULL;
/* >>> rather send this to msg system of xorriso */;
fprintf(stderr, "Starting up libraries ...\n");
sprintf(xorriso->info_text, "Starting up libraries ...\n");
Xorriso_info(xorriso, 0);
handler_prefix= calloc(strlen(xorriso->progname)+3+1, 1);
if(handler_prefix==NULL) {
/* >>> rather send this to msg system of xorriso */;
fprintf(stderr, "--- Cannot allocate memory for initializing libraries\n");
sprintf(xorriso->info_text,
"Cannot allocate memory for initializing libraries");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(-1);
}
ret= isoburn_initialize();
if(ret==0) {
/* >>> rather send this to msg system of xorriso */;
fprintf(stderr, "--- Cannot initialize libraries\n");
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text, "Cannot initialize libraries");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
free(handler_prefix);
return(0);
}
/* >>> need option for controlling this in XorrisO */
/* >>> change from printing to queuing */
iso_msgs_set_severities("NEVER", "DEBUG", "libisofs : ");
burn_msgs_set_severities("NEVER", "DEBUG", "libburn : ");
/* ??? >>> do we want united queues ? */
/* burn_set_messenger(iso_get_messenger()); */
sprintf(handler_prefix, "%s : ", xorriso->progname);
burn_set_signal_handling(handler_prefix, NULL, 0);
fprintf(stderr,"Library startup done.\n");
sprintf(xorriso->info_text, "Library startup done.\n");
Xorriso_info(xorriso, 0);
free(handler_prefix);
return(1);
}
@ -93,7 +103,9 @@ int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
if((flag&3)!=3) {
fprintf(stderr,">>> XORRISOBURN: Xorriso_aquire_drive bit0+bit1 not set\n");
sprintf(xorriso->info_text,
"XORRISOBURN program error : Xorriso_aquire_drive bit0+bit1 not set");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(0);
}
ret= Xorriso_give_up_drive(xorriso, flag&3);
@ -102,7 +114,11 @@ int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
ret= isoburn_drive_scan_and_grab(&dinfo, adr, 1);
if(ret<=0) {
fprintf(stderr,"--- Cannot aquire drive '%s'\n", adr);
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text,"Cannot aquire drive '%s'", adr);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
if(flag&2)
@ -120,10 +136,8 @@ int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
/* >>> show drive and media status */;
if(state != BURN_DISC_BLANK && state != BURN_DISC_APPENDABLE) {
/* >>> rather send this to msg system of xorriso */;
fprintf(stderr, "Unsuitable disc status\n");
sprintf(xorriso->info_text, "Unsuitable disc status");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
ret= 0; goto ex;
}
/* fill read opts */
@ -136,9 +150,10 @@ int Xorriso_aquire_drive(struct XorrisO *xorriso, char *adr, int flag)
if(isoburn_read_volset(drive, &ropts, &volset) <= 0) {
/* >>> rather send this to msg system of xorriso */;
fprintf(stderr, "Can't read volset\n");
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text,"Caninot read ISO image volset");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
ret= 0; goto ex;
}
xorriso->in_volset_handle= volset;
@ -204,10 +219,8 @@ int Xorriso_write_growing(struct XorrisO *xorriso, int flag)
dinfo= (struct burn_drive_info *) xorriso->in_drive_handle;
if(dinfo==NULL) {
/* >>> */
fprintf(stderr, "--- No drive aquired\n");
sprintf(xorriso->info_text,"No drive aquired on attempt to write");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
drive= dinfo[0].drive;
@ -236,18 +249,20 @@ int Xorriso_write_growing(struct XorrisO *xorriso, int flag)
if (isoburn_prepare_disc(drive, &disc, &sopts) <= 0) {
/* >>> */
fprintf(stderr, "--- Cannot prepare disc\n");
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text,"Cannot prepare disc");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
burn_options= burn_write_opts_new(drive);
if(burn_options==NULL) {
/* >>> */
fprintf(stderr, "--- Cannot allocate option set\n");
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text,"Cannot allocate option set");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
burn_write_opts_set_simulate(burn_options, !!xorriso->do_dummy);
@ -286,16 +301,14 @@ int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
usleep(100002);
while(burn_drive_get_status(drive, &progress) != BURN_DRIVE_IDLE) {
/* >>> make this output go into xorriso info channel */;
printf("Writing: sector %d of %d",
sprintf(xorriso->info_text, "Writing: sector %d of %d",
progress.sector, progress.sectors);
ret= isoburn_get_fifo_status(drive, &size, &free_bytes, &status_text);
if(ret>0 )
printf(" [fifo %s, %2d%% fill]", status_text,
sprintf(xorriso->info_text+strlen(xorriso->info_text),
" [fifo %s, %2d%% fill]", status_text,
(int) (100.0-100.0*((double) free_bytes)/(double) size));
printf("\n");
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0);
for(i= 0; i<10; i++) {
@ -321,14 +334,16 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
if(xorriso->in_volset_handle==NULL) {
/* >>> */
fprintf(stderr, "--- No volset is loaded.\n");
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text,"No volset is loaded.");
if(xorriso->indev[0]==0)
fprintf(stderr, "--- No -dev or -indev is selected.\n");
sprintf(xorriso->info_text," No -dev or -indev is selected.");
else
fprintf(stderr, "--- Possible program error with drive '%s'\n",
sprintf(xorriso->info_text," Possible program error with drive '%s'.",
xorriso->indev);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
strncpy(path, img_path, sizeof(path)-1);
@ -339,20 +354,22 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
if(lstat(disk_path, &stbuf) == -1) {
/* >>> */
fprintf(stderr, "--- Cannot determine attributes of '%s' : %s (%d)\n",
disk_path, (errno > 0 ? strerror(errno) : "unknown error"), errno);
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text,
"Cannot determine attributes of source file '%s'",disk_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "SORRY", 0);
return(0);
}
if(S_ISDIR(stbuf.st_mode))
is_dir= 1;
else if(!(S_ISREG(stbuf.st_mode) || S_ISLNK(stbuf.st_mode))) {
/* >>> */
fprintf(stderr, "--- File object '%s' is of non-supported file type\n",
disk_path);
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text,
"Source file '%s' is of non-supported file type", disk_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
} else {
l= strlen(img_path);
@ -360,22 +377,21 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
if(img_path[l-1]=='/')
l= 0;
if(l==0) {
/* >>> */
fprintf(stderr,
"--- Source '%s' is not a directory. Target '%s' would be.\n",
sprintf(xorriso->info_text,
"Source '%s' is not a directory. Target '%s' would be.",
disk_path, img_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
}
}
dir= iso_volume_get_root(volume);
if(dir==NULL) {
/* >>> */
fprintf(stderr, "--- While grafting '%s' : no root node available\n",
img_path);
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text,
"While grafting '%s' : no root node available", img_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0);
return(0);
}
for(npt= apt; !done; apt= npt+1) {
@ -402,11 +418,10 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
}
/* >>> */
fprintf(stderr,
"--- While grafting '%s' : '%s' exists and is not a directory\n",
sprintf(xorriso->info_text,
"While grafting '%s' : '%s' exists and is not a directory",
img_path, path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
dir= (struct iso_tree_node_dir *) node;
@ -414,10 +429,11 @@ int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
dir= iso_tree_add_dir(dir, apt);
if(dir==NULL) {
/* >>> */
fprintf(stderr, "--- While grafting '%s' : could not insert '%s'\n",
img_path, path);
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text,
"While grafting '%s' : could not insert '%s'", img_path, path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
}
@ -429,10 +445,12 @@ attach_source:;
node= iso_tree_add_node(dir, disk_path);
if(node == NULL) {
/* >>> */
fprintf(stderr, "While grafting '%s'='%s' : libisofs_errno = %d\n",
img_path, disk_path, libisofs_errno);
/* >>> fetch all messages from library message queue first */
sprintf(xorriso->info_text,
"While grafting '%s'='%s' : libisofs_errno = %d",
img_path, disk_path, libisofs_errno);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "SORRY", 0);
return(0);
}
iso_tree_node_set_name(node, apt);
@ -440,10 +458,24 @@ attach_source:;
} else
*npt= '/';
}
fprintf(stderr, "NOTE: added %s '%s'='%s'\n", (is_dir ? "directory" : "node"),
sprintf(xorriso->info_text,
"Added %s '%s'='%s'", (is_dir ? "directory" : "node"),
img_path, disk_path);
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "NOTE", 0);
xorriso->volset_change_pending= 1;
return(1);
}
int Xorriso__text_to_sev(char *severity_name, int *severity_number, int flag)
{
int ret= 1;
if(severity_name[0]==0)
*severity_number= 0;
else
ret= burn_text_to_sev(severity_name, severity_number, 0);
return(ret);
}

View File

@ -31,6 +31,7 @@ int Xorriso_pacifier_loop(struct XorrisO *xorriso, struct burn_drive *drive,
int Xorriso_graft_in(struct XorrisO *xorriso, char *disk_path, char *img_path,
int flag);
int Xorriso__text_to_sev(char *severity_name, int *severity_number,int flag);
#endif /* Xorrisoburn_includeD */