Removed some unused code

This commit is contained in:
Thomas Schmitt 2008-02-06 18:36:44 +00:00
parent 514dfb3433
commit d532630fbc
2 changed files with 1 additions and 238 deletions

View File

@ -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;i<cmd_argc;i++)
argv[w++]= cmd_argv[i];
for(i=0;i<extra_argc;i++)
argv[w++]= extra_argv[i];
argv[w]= NULL;
ret= Exec_cmd(prog,argv[0],NULL,argv,errmsg,flag&1);
ex:;
if(argv!=NULL)
free((char *) argv);
Sfile_make_argv("",cmd_line,&cmd_argc,&cmd_argv,2);
return(ret);
}
int Strcmp(const void *pt1, const void *pt2) int Strcmp(const void *pt1, const void *pt2)
{ {
return(strcmp(*((char **) pt1), *((char **) pt2))); return(strcmp(*((char **) pt1), *((char **) pt2)));
@ -4161,70 +3988,6 @@ int Xorriso_status(struct XorrisO *xorriso, char *filter, FILE *fp, int flag)
} }
int Xorriso_exec(struct XorrisO *xorriso, char *cmd, int flag)
{
char *spt,*cpt,**argv= NULL,errmsg[2*SfileadrL];
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, "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;widx<argc+1;widx++)
argv[widx]= NULL;
}
}
ret= Exec_cmd(xorriso->progname,cmd,NULL,argv,errmsg,
!!(xorriso->packet_output));
if(ret<0)
goto ex;
if(ret>0) {
for(widx=0; widx<cmd_l; widx++)
if(cmd[widx]==0)
cmd[widx]= ' ';
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, "FAILURE", 1);
{ret= 0; goto ex;}
}
ret= 1;
ex:
if(argv!=NULL) {
for(widx=0;widx<argc;widx++)
Sregex_string(&(argv[widx]),NULL,0);
free((char *) argv);
}
return(ret);
}
/* @param flag bit2= this is a disk_pattern /* @param flag bit2= this is a disk_pattern
@return <=0 failure , 1 pattern ok , 2 pattern needed prepended wd */ @return <=0 failure , 1 pattern ok , 2 pattern needed prepended wd */
int Xorriso_prepare_expansion_pattern(struct XorrisO *xorriso, char *pattern, int Xorriso_prepare_expansion_pattern(struct XorrisO *xorriso, char *pattern,

View File

@ -1 +1 @@
#define Xorriso_timestamP "2008.02.06.183423" #define Xorriso_timestamP "2008.02.06.183557"