diff --git a/libisoburn/trunk/xorriso/xorriso.c b/libisoburn/trunk/xorriso/xorriso.c index 494c4a1a..f841b780 100644 --- a/libisoburn/trunk/xorriso/xorriso.c +++ b/libisoburn/trunk/xorriso/xorriso.c @@ -964,179 +964,6 @@ bit15= with bit1 or bit2: close depicted log file } -int Exec_cmd(char *prog, char *cmd, char *simple_arg, char **argv, - char errmsg[SfileadrL], int flag) -/* - bit0= package mode (!bit0 of Write_to_channel()) -*/ -{ - int wait_status,is_dead= 0,pipes_open= 0,ret,channel_no; - int stdout_pipe[2],stderr_pipe[2],fds[2],fdidx[3]; - char **exec_argv,*simple_argv[3],buffer[256]; - pid_t pid,dead_pid; - static int debug= 0; - - errmsg[0]= 0; - if(debug) - fprintf(stderr,"Exec_cmd():fork\n"); - - /* create pipes */ - if(pipe(stdout_pipe)==-1) { -cannot_make_pipe:; - sprintf(errmsg,"%s : cannot create two pipes\n reason given: %s\n", - prog,strerror(errno)); - return(-1); - } - if(pipe(stderr_pipe)==-1) { - close(stdout_pipe[0]); - close(stdout_pipe[1]); - goto cannot_make_pipe; - } - pipes_open= 1; - - pid= fork(); - if(pid==-1) { - sprintf(errmsg,"%s : cannot fork a new process\n reason given: %s\n", - prog,strerror(errno)); - {ret= -1; goto father_ex;} - } else if(pid>0) { /* original process */ - if(debug) - fprintf(stderr,"Exec_cmd():father\n"); - /* close unused pipe ends so we register EOF by the child process */ - close(stdout_pipe[1]); - close(stderr_pipe[1]); - fds[0]= stdout_pipe[0]; - fds[1]= stderr_pipe[0]; - is_dead= 0; - while(1) { - if((fds[0]==-1 && fds[1]==-1)) { /* not before both pipes have closed */ - dead_pid= wait3(&wait_status,WNOHANG,NULL); - if(dead_pid==pid) { - is_dead= 1; - break; - } else if(dead_pid<0) { - sprintf(errmsg, - "%s : error while waiting for end of sub process\n %s\n", - prog,strerror(errno)); - {ret= -1; goto father_ex;} - } - } - - /* check for input at both pipes */; - ret= Sfile_select(fds,2,fdidx,100000,1|8); - if(ret<=0 || fdidx[0]<0 || fdidx[0]>1) - continue; - ret= read(fds[fdidx[0]],buffer,sizeof(buffer)-3); - if(ret<0) { - sprintf(errmsg,"--- error %d on read from %s pipe : %s\n", - errno,(fdidx[0]?"stdout":"stderr"), - (errno>0?strerror(errno):"-unknown error-")); - {ret= -1; goto father_ex;} - } - if(ret==0) { - fds[fdidx[0]]= -1; - continue; - } - buffer[ret]= 0; - channel_no= fdidx[0]+1; - ret= Write_to_channel(buffer,channel_no,!(flag&1)); - if(ret<=0) { - sprintf(errmsg,"--- error %d on write to %s : %s\n", - errno,(fdidx[0]?"stdout":"stderr"), - (errno>0?strerror(errno):"-unknown error-")); - {ret= -1; goto father_ex;} - } - } - ret= 127; - if(WIFEXITED(wait_status)) - ret= WEXITSTATUS(wait_status); -father_ex:; - if(pipes_open) { - close(stdout_pipe[0]); - close(stderr_pipe[0]); - } - return(ret); - } - - if(debug) - fprintf(stderr,"Exec_cmd():child\n"); - - /* Connect stdout and stderr to the appropriate ends of the pipes. */ - close(1); - ret= dup(stdout_pipe[1]); - if(ret==-1) { -cannot_dup_pipe:; - sprintf(errmsg, - "%s : cannot redirect standard i/o to pipes\n reason given: %s\n", - prog,strerror(errno)); - Write_to_channel(errmsg,2,!(flag&1)); - exit(1); - } - close(2); - ret= dup(stderr_pipe[1]); - if(ret==-1) - goto cannot_dup_pipe; - /* close pipes so we register EOF by the father process */ - close(stdout_pipe[0]); - close(stdout_pipe[1]); - close(stderr_pipe[0]); - close(stderr_pipe[1]); - - /* switch process to desired program */ - if(simple_arg!=NULL) { - simple_argv[0]= cmd; - simple_argv[1]= simple_arg; - simple_argv[2]= NULL; - exec_argv= simple_argv; - } else { - exec_argv= argv; - } - if(debug) { int i; - fprintf(stderr,"debug: cmd='%s'\n",cmd); - for(i=0;exec_argv[i]!=NULL;i++) - fprintf(stderr,"debug: argv[%d]='%s'\n",i,exec_argv[i]); - } - if(strchr(cmd,'/')!=NULL) - execv(cmd,exec_argv); - else - execvp(cmd,exec_argv); - sprintf(errmsg,"%s : cannot start program %s\n reason given: %s\n", - prog,cmd,strerror(errno)); - Write_to_channel(errmsg,2,!(flag&1)); - exit(127); -} - - -int Exec_cmd_line(char *prog, char *cmd_line, - int extra_argc, char **extra_argv, char *errmsg, int flag) -/* - bit0= packade mode (!bit0 of Write_to_channel()) -*/ -{ - int ret,cmd_argc= 0,i,w; - char **cmd_argv= NULL,**argv= NULL; - - ret= Sfile_make_argv("",cmd_line,&cmd_argc,&cmd_argv,1); - if(ret<=0) - {ret= -1; goto ex;} - argv= TSOB_FELD(char *,cmd_argc+extra_argc+1); - if(argv==NULL) - {ret= -1; goto ex;} - w= 0; - for(i=0;iSfileadrL) { - 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, "FAILURE", 0); - } - for(pass=0;pass<2;pass++) { - is_done= 0; - widx= 0; - for(spt= cmd;!is_done;spt= cpt+1) { - for(cpt= spt;*cpt!=0 && *cpt!=':' && *cpt!=' ';cpt++); - if(*cpt==0) - is_done= 1; - if(pass==0) { - argc++; - } else { - *cpt= 0; - if(Sregex_string(&(argv[widx]),spt,0)<=0) - {ret= -1; goto ex;} - widx++; - } - } - if(pass==0) { - if(argc==0) - {ret= 2; goto ex;} - argv= TSOB_FELD(char *,argc+1); - if(argv==NULL) - {ret= -1; goto ex;} - for(widx= 0;widxprogname,cmd,NULL,argv,errmsg, - !!(xorriso->packet_output)); - if(ret<0) - goto ex; - if(ret>0) { - for(widx=0; widxinfo_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, "FAILURE", 1); - {ret= 0; goto ex;} - } - ret= 1; -ex: - if(argv!=NULL) { - for(widx=0;widx