From 47ce7c6f9b647fe174ab550ff5a893799a6676cc Mon Sep 17 00:00:00 2001 From: Thomas Schmitt Date: Tue, 9 Mar 2010 06:52:24 +0000 Subject: [PATCH] Adapted xorriso signal handling to new libburn advise --- libisoburn/trunk/xorriso/xorriso.c | 19 +++++ libisoburn/trunk/xorriso/xorriso.h | 14 ++++ libisoburn/trunk/xorriso/xorriso_private.h | 6 +- libisoburn/trunk/xorriso/xorriso_timestamp.h | 2 +- libisoburn/trunk/xorriso/xorrisoburn.c | 84 ++++++++++++++++---- 5 files changed, 106 insertions(+), 19 deletions(-) diff --git a/libisoburn/trunk/xorriso/xorriso.c b/libisoburn/trunk/xorriso/xorriso.c index 211d78d5..9c991a68 100644 --- a/libisoburn/trunk/xorriso/xorriso.c +++ b/libisoburn/trunk/xorriso/xorriso.c @@ -166,6 +166,10 @@ or #include "xorrisoburn.h" +/* See Xorriso__preset_signal_behavior() */ +static int Xorriso_signal_behavioR= 1; + + /* ------------------------------------------------------------------------ */ @@ -5033,6 +5037,21 @@ int Xorriso_destroy(struct XorrisO **xorriso, int flag) } +int Xorriso__preset_signal_behavior(int behavior, int flag) +{ + if(behavior < 0 || behavior > 1) + return(0); + Xorriso_signal_behavioR= behavior; + return(1); +} + + +int Xorriso__get_signal_behavior(int flag) +{ + return(Xorriso_signal_behavioR); +} + + int Xorriso_dialog_input(struct XorrisO *xorriso, char line[], int linesize, int flag) /* diff --git a/libisoburn/trunk/xorriso/xorriso.h b/libisoburn/trunk/xorriso/xorriso.h index 11a503a3..c4d98ead 100644 --- a/libisoburn/trunk/xorriso/xorriso.h +++ b/libisoburn/trunk/xorriso/xorriso.h @@ -39,6 +39,20 @@ char *Xorriso__get_version_text(int flag); char *Xorriso__get_patch_level_text(int flag); +/* Choose how Xorriso_startup_libraries() and the XorrisO object shall + prepare for eventual signals. + @param behavior Default is behavior 1. + 0= no own signal handling. The main application has to do + that. Do not start burn runs without any handling ! + 1= use libburn signal handler. Most time with action + 0. During writing, formatting, blanking: 0x30. + Only usable with a single xorriso object. + @param flag unused yet, submit 0 + @return <= 0 is error, >0 is success +*/ +int Xorriso__preset_signal_behavior(int behavior, int flag); + + /* Mandatory call: Create a new xorriso object and tell it the program name to be used with messages and for decision of special behavior. diff --git a/libisoburn/trunk/xorriso/xorriso_private.h b/libisoburn/trunk/xorriso/xorriso_private.h index 1b1edd26..846d3c67 100644 --- a/libisoburn/trunk/xorriso/xorriso_private.h +++ b/libisoburn/trunk/xorriso/xorriso_private.h @@ -50,10 +50,6 @@ struct SectorbitmaP; /* Distiniction between valid and invalid sectors */ /* maximum number of history lines to be reported with -status:long_history */ #define Xorriso_status_history_maX 100 -/* <<< ??? */ -/* try to catch signals and ignore them during abort handling */ -#define Xorriso_abort_handler_defaulT (1|(2<<4)) - /** The list of startup file names */ #define Xorriso_rc_nuM 4 @@ -475,6 +471,8 @@ struct XorrisO { /* the global context of xorriso */ }; +int Xorriso__get_signal_behavior(int flag); + int Xorriso_prepare_regex(struct XorrisO *xorriso, char *adr, int flag); int Xorriso_result(struct XorrisO *xorriso, int flag); diff --git a/libisoburn/trunk/xorriso/xorriso_timestamp.h b/libisoburn/trunk/xorriso/xorriso_timestamp.h index 754afdee..b9928cbc 100644 --- a/libisoburn/trunk/xorriso/xorriso_timestamp.h +++ b/libisoburn/trunk/xorriso/xorriso_timestamp.h @@ -1 +1 @@ -#define Xorriso_timestamP "2010.03.09.065117" +#define Xorriso_timestamP "2010.03.09.065408" diff --git a/libisoburn/trunk/xorriso/xorrisoburn.c b/libisoburn/trunk/xorriso/xorrisoburn.c index 9349f3ca..1da08523 100644 --- a/libisoburn/trunk/xorriso/xorrisoburn.c +++ b/libisoburn/trunk/xorriso/xorrisoburn.c @@ -144,6 +144,25 @@ static const char *un0(const char *text) } +int Xorriso_abort(struct XorrisO *xorriso, int flag) +{ + int ret; + + ret= burn_abort(4440, burn_abort_pacifier, "xorriso : "); + if(ret<=0) { + fprintf(stderr, + "\nxorriso : ABORT : Cannot cancel burn session and release drive.\n"); + return(0); + } + fprintf(stderr, + "xorriso : ABORT : Drive is released and library is shut down now.\n"); + fprintf(stderr, + "xorriso : ABORT : Program done. Even if you do not see a shell prompt.\n"); + fprintf(stderr, "\n"); + exit(1); +} + + int Xorriso_destroy_node_array(struct XorrisO *xorriso, int flag) { int i; @@ -537,11 +556,31 @@ int Xorriso_search_di_range(struct XorrisO *xorriso, IsoNode *node, /* ------------------------------------------------------------------------ */ +/* @param flag bit0= asynchronous handling (else catch thread, wait, and exit) +*/ +int Xorriso_set_signal_handling(struct XorrisO *xorriso, int flag) +{ + char *handler_prefix= NULL; + + if(Xorriso__get_signal_behavior(0) != 1) + return(2); + handler_prefix= calloc(strlen(xorriso->progname)+3+1, 1); + if(handler_prefix==NULL) { + sprintf(xorriso->info_text, + "Cannot allocate memory for for setting signal handler"); + Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0); + return(-1); + } + sprintf(handler_prefix, "%s : ", xorriso->progname); + burn_set_signal_handling(handler_prefix, NULL, (flag & 1) * 0x30); + free(handler_prefix); + return(1); +} + int Xorriso_startup_libraries(struct XorrisO *xorriso, int flag) { int ret, major, minor, micro; - char *handler_prefix= NULL; char *queue_sev, *print_sev, reason[1024]; struct iso_zisofs_ctrl zisofs_ctrl= {0, 6, 15}; @@ -587,13 +626,6 @@ LIBISOBURN_MISCONFIGURATION_ = 0; /* End of ugly compile time test (scroll up for explanation) */ - handler_prefix= calloc(strlen(xorriso->progname)+3+1, 1); - if(handler_prefix==NULL) { - sprintf(xorriso->info_text, - "Cannot allocate memory for initializing libraries"); - Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0); - return(-1); - } reason[0]= 0; ret= isoburn_initialize(reason, 0); if(ret==0) { @@ -602,7 +634,6 @@ LIBISOBURN_MISCONFIGURATION_ = 0; sprintf(xorriso->info_text+strlen(xorriso->info_text), ". Reason given:\n%s", reason); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FATAL", 0); - free(handler_prefix); return(0); } ret= isoburn_is_compatible(isoburn_header_version_major, @@ -640,8 +671,9 @@ LIBISOBURN_MISCONFIGURATION_ = 0; isoburn_set_msgs_submit(Xorriso_msgs_submit_void, (void *) xorriso, (3<<2) | 128 , 0); - sprintf(handler_prefix, "%s : ", xorriso->progname); - burn_set_signal_handling(handler_prefix, NULL, 0); + ret= Xorriso_set_signal_handling(xorriso, 0); + if(ret <= 0) + return(ret); ret = iso_zisofs_get_params(&zisofs_ctrl, 0); if (ret == 1) { @@ -658,7 +690,6 @@ LIBISOBURN_MISCONFIGURATION_ = 0; strcpy(xorriso->info_text, "Using "); strncat(xorriso->info_text, burn_scsi_transport_id(0), 1024); Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0); - free(handler_prefix); return(1); } @@ -2041,11 +2072,17 @@ int Xorriso_write_session(struct XorrisO *xorriso, int flag) if(ret <= 0) goto ex; + /* Important: do not return until burn_is_aborting() was checked */ + Xorriso_set_signal_handling(xorriso, 1); + xorriso->run_state= 1; /* Indicate that burning has started */ isoburn_disc_write(burn_options, disc); burn_write_opts_free(burn_options); ret= Xorriso_pacifier_loop(xorriso, drive, pacifier_speed << 4); + if(burn_is_aborting(0)) + Xorriso_abort(xorriso, 0); /* Never comes back */ + Xorriso_set_signal_handling(xorriso, 0); if(ret<=0) goto ex; if(!isoburn_drive_wrote_well(drive)) { @@ -2116,6 +2153,8 @@ int Xorriso_check_burn_abort(struct XorrisO *xorriso, int flag) struct burn_drive_info *dinfo; struct burn_drive *drive; + if(burn_is_aborting(0)) + return(2); if(xorriso->run_state!=1) return(0); ret= Xorriso_eval_problem_status(xorriso, 1, 1); @@ -5762,6 +5801,9 @@ int Xorriso_blank_media(struct XorrisO *xorriso, int flag) mode_names[flag&3]); Xorriso_info(xorriso,0); + /* Important: do not return until burn_is_aborting() was checked */ + Xorriso_set_signal_handling(xorriso, 1); + if(do_deformat) burn_disc_erase(drive, (flag&1)); else @@ -5778,7 +5820,9 @@ int Xorriso_blank_media(struct XorrisO *xorriso, int flag) usleep(1000000); } Xorriso_process_msg_queues(xorriso,0); - + if(burn_is_aborting(0)) + Xorriso_abort(xorriso, 0); /* Never comes back */ + Xorriso_set_signal_handling(xorriso, 0); if(burn_drive_wrote_well(drive)) { sprintf(xorriso->info_text, "Blanking done\n"); Xorriso_info(xorriso,0); @@ -5915,6 +5959,10 @@ int Xorriso_format_media(struct XorrisO *xorriso, off_t in_size, int flag) Xorriso_info(xorriso, 0); if(flag & 2) size= in_size; + + /* Important: do not return until burn_is_aborting() was checked */ + Xorriso_set_signal_handling(xorriso, 1); + burn_disc_format(drive, size, mode_flag); start_time= time(0); @@ -5928,8 +5976,10 @@ int Xorriso_format_media(struct XorrisO *xorriso, off_t in_size, int flag) Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "UPDATE", 0); usleep(1000000); } - Xorriso_process_msg_queues(xorriso,0); + if(burn_is_aborting(0)) + Xorriso_abort(xorriso, 0); /* Never comes back */ + Xorriso_set_signal_handling(xorriso, 0); if(burn_drive_wrote_well(drive)) { sprintf(xorriso->info_text, "Formatting done\n"); @@ -9144,10 +9194,16 @@ int Xorriso_burn_track(struct XorrisO *xorriso, off_t write_start_address, if(ret<=0) goto ex; + /* Important: do not return until burn_is_aborting() was checked */ + Xorriso_set_signal_handling(xorriso, 1); + xorriso->run_state= 1; /* Indicate that burning has started */ burn_disc_write(burn_options, disc); ret= Xorriso_pacifier_loop(xorriso, drive, 2 | (is_cd << 4) | (is_bd << 5)); + if(burn_is_aborting(0)) + Xorriso_abort(xorriso, 0); /* Never comes back */ + Xorriso_set_signal_handling(xorriso, 0); if(ret<=0) goto ex; if(!burn_drive_wrote_well(drive)) {