Adapted xorriso signal handling to new libburn advise

This commit is contained in:
2010-03-09 06:52:24 +00:00
parent 2eec5bf40a
commit b76161a698
5 changed files with 106 additions and 19 deletions

View File

@@ -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)) {