New command -concat
This commit is contained in:
@ -96,7 +96,7 @@ int Xorriso_opt_args(struct XorrisO *xorriso, char *cmd,
|
||||
else
|
||||
do_expand= (xorriso->do_iso_rr_pattern==1 && !(flag&4)) || (flag & 512);
|
||||
if(flag&256) {
|
||||
if(*optv<argv || *optv>=argv+argc)
|
||||
if(*optv < argv || (*optv >= argv + argc && argc > 0))
|
||||
Sfile_destroy_argv(optc, optv, 0);
|
||||
return(1);
|
||||
}
|
||||
@ -563,7 +563,7 @@ int Xorriso_count_args(struct XorrisO *xorriso, int argc, char **argv,
|
||||
"check_md5","check_md5_r","check_media","check_media_defaults",
|
||||
"chgrp","chgrpi","chgrp_r","chgrp_ri","chmod","chmodi",
|
||||
"chmod_r","chmod_ri","chown","chowni","chown_r","chown_ri",
|
||||
"compare_l","cp_clone","cp_rax","cp_rx","cpr","cpri", "cpax","cpx",
|
||||
"compare_l","concat","cp_clone","cp_rax","cp_rx","cpr","cpri","cpax","cpx",
|
||||
"du","dui","dus","dusi","dux","dusx","external_filter","extract_l",
|
||||
"file_size_limit","find","findi","finds","findx",
|
||||
"getfacl","getfacli","getfacl_r","getfacl_ri",
|
||||
@ -717,7 +717,7 @@ int Xorriso_cmd_sorting_rank(struct XorrisO *xorriso,
|
||||
|
||||
"* osirrox ISO-to-disk restore options:",
|
||||
"osirrox", "extract", "extract_single", "extract_l", "extract_cut",
|
||||
"cpx", "cpax", "cp_rx", "cp_rax", "paste_in",
|
||||
"cpx", "cpax", "cp_rx", "cp_rax", "paste_in", "concat",
|
||||
"mount",
|
||||
|
||||
"* Settings for result writing:",
|
||||
@ -1164,6 +1164,9 @@ next_command:;
|
||||
(*idx)++;
|
||||
Xorriso_option_compliance(xorriso, arg1, 0);
|
||||
|
||||
} else if(strcmp(cmd,"concat") == 0) {
|
||||
ret= Xorriso_option_concat(xorriso, argc, argv, idx, 0);
|
||||
|
||||
} else if(strcmp(cmd,"copyright_file")==0) {
|
||||
(*idx)++;
|
||||
Xorriso_option_copyright_file(xorriso, arg1, 0);
|
||||
@ -2739,16 +2742,67 @@ int Xorriso_check_temp_mem_limit(struct XorrisO *xorriso, off_t mem, int flag)
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_wait_child_end(struct XorrisO *xorriso, pid_t child_pid,
|
||||
int *status, int flag)
|
||||
{
|
||||
int ret;
|
||||
|
||||
do {
|
||||
/* try to read and print the reply */;
|
||||
ret= waitpid(child_pid, status, WNOHANG);
|
||||
if(ret == -1) {
|
||||
if(errno != EINTR)
|
||||
return(0);
|
||||
} else if(ret == 0) {
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while(1);
|
||||
|
||||
/* >>> interpret *status */;
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
int Xorriso_make_argv_with_null(struct XorrisO *xorriso,
|
||||
int in_argc, char **in_argv,
|
||||
int *argc, char ***argv, int flag)
|
||||
{
|
||||
int i, ret= 0;
|
||||
|
||||
*argv= NULL;
|
||||
Xorriso_alloc_meM(*argv, char *, in_argc + 1);
|
||||
for(i= 0; i < in_argc; i++) {
|
||||
Xorriso_alloc_meM((*argv)[i], char, strlen(in_argv[i]) + 1);
|
||||
strcpy((*argv)[i], in_argv[i]);
|
||||
*argc= i + 1;
|
||||
}
|
||||
(*argv)[in_argc]= NULL;
|
||||
ret= 1;
|
||||
ex:;
|
||||
if(ret <= 0)
|
||||
Sfile_destroy_argv(argc, argv, 0);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@param flag bit0= use env_path to find the desired program
|
||||
bit1= use in_argv rather than parsing cmd to words
|
||||
bit2= -reserved-
|
||||
bit3= demand absolute cmd path
|
||||
return:
|
||||
<=0 : error
|
||||
1 : done
|
||||
*/
|
||||
int Xorriso_execv(struct XorrisO *xorriso, char *cmd, char *env_path,
|
||||
int Xorriso_execv(struct XorrisO *xorriso, char *cmd,
|
||||
int in_argc, char **in_argv, char *env_path,
|
||||
int *stdin_pipe, int *stdout_pipe, pid_t *forked_pid,
|
||||
int *status, int flag)
|
||||
{
|
||||
int ret, argc= 0;
|
||||
int ret, argc= 0, has_slash;
|
||||
char **argv= NULL, *pathlist= NULL, *cpt, *npt, *prog= NULL;
|
||||
pid_t child_pid;
|
||||
struct stat stbuf;
|
||||
@ -2757,14 +2811,26 @@ int Xorriso_execv(struct XorrisO *xorriso, char *cmd, char *env_path,
|
||||
|
||||
wait3(NULL,WNOHANG,NULL); /* just to remove any old dead child */
|
||||
|
||||
ret= Sfile_make_argv("", cmd, &argc, &argv, 1|4|128);
|
||||
if(flag & 2) {
|
||||
ret= Xorriso_make_argv_with_null(xorriso, in_argc, in_argv,
|
||||
&argc, &argv, 0);
|
||||
} else {
|
||||
ret= Sfile_make_argv("", cmd, &argc, &argv, 1|4|128);
|
||||
}
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
if(argc < 1)
|
||||
{ret= 0; goto ex;}
|
||||
|
||||
strcpy(prog, argv[0]);
|
||||
if((flag & 1) && strchr(argv[0], '/') == NULL) {
|
||||
has_slash= (strchr(argv[0], '/') != NULL);
|
||||
if((flag & 8) && !has_slash) {
|
||||
sprintf(xorriso->info_text, "External program path contains no '/': ");
|
||||
Text_shellsafe(argv[0], xorriso->info_text, 1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "FAILURE", 0);
|
||||
ret= 0; goto ex;
|
||||
}
|
||||
if((flag & 1) && has_slash) {
|
||||
if(env_path == NULL)
|
||||
env_path= "/bin:/sbin";
|
||||
else if(env_path[0] == 0)
|
||||
@ -2801,9 +2867,21 @@ int Xorriso_execv(struct XorrisO *xorriso, char *cmd, char *env_path,
|
||||
sprintf(xorriso->info_text, "Executing external program ");
|
||||
Text_shellsafe(prog, xorriso->info_text, 1);
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, 0, "DEBUG", 0);
|
||||
|
||||
Xorriso_destroy(&xorriso, 0); /* reduce memory foot print */
|
||||
|
||||
if(stdin_pipe != NULL) {
|
||||
close(0);
|
||||
if(dup2(stdin_pipe[0], 0) == -1)
|
||||
{ perror("dup2(,0)"); exit(1); }
|
||||
close(stdin_pipe[1]); /* unused */
|
||||
}
|
||||
if(stdout_pipe != NULL) {
|
||||
close(1);
|
||||
if(dup2(stdout_pipe[1], 1) == -1)
|
||||
{ perror("dup2(,1)"); exit(1); }
|
||||
close(stdout_pipe[0]); /* unused */
|
||||
}
|
||||
|
||||
execv(prog, argv); /* should never come back */
|
||||
fprintf(stderr,"--- execution of shell command failed:\n");
|
||||
fprintf(stderr," %s\n",cmd);
|
||||
@ -2812,33 +2890,22 @@ int Xorriso_execv(struct XorrisO *xorriso, char *cmd, char *env_path,
|
||||
|
||||
|
||||
/* this is the original process waiting for child to exit */
|
||||
do {
|
||||
/* try to read and print the reply */;
|
||||
ret= waitpid(child_pid,status,WNOHANG);
|
||||
if(ret==-1) {
|
||||
if(errno!=EINTR)
|
||||
ret= 0; goto ex;
|
||||
} else if(ret==0) {
|
||||
|
||||
#ifdef NIX
|
||||
if(stdin_pipe != NULL)
|
||||
close(stdin_pipe[0]); /* unused */
|
||||
if(stdout_pipe != NULL)
|
||||
close(stdout_pipe[1]); /* unused */
|
||||
if(stdin_pipe != NULL || stdout_pipe != NULL) {
|
||||
/* Pipes need to be fed by the caller who later calls Xorriso_wait_child_end
|
||||
with *forked_pid as child_pid.
|
||||
*/
|
||||
*forked_pid= child_pid;
|
||||
{ret= 1; goto ex;}
|
||||
}
|
||||
|
||||
/* >>> An interrupt key would be nice. */
|
||||
|
||||
if((flag&4)) {
|
||||
ret= Asqueue_event_is_pending(agent->queue,0,0);
|
||||
if(ret>0) {
|
||||
Asagent_stderr(agent,"--- shell command interrupted",1);
|
||||
kill(child_pid,SIGTERM);
|
||||
ret= 2; goto ex;
|
||||
}
|
||||
}
|
||||
#endif /* NIX */
|
||||
|
||||
continue;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
} while(1);
|
||||
ret= Xorriso_wait_child_end(xorriso, child_pid, status, 0);
|
||||
if(ret <= 0)
|
||||
goto ex;
|
||||
ret= 1;
|
||||
ex:
|
||||
Sfile_make_argv("", "", &argc, &argv, 2);
|
||||
@ -2848,6 +2915,43 @@ ex:
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= use env_path to find the desired program
|
||||
bit1= use in_argv rather than parsing cmd to words
|
||||
bit2= "r" rather than "w"
|
||||
bit3= demand absolute cmd path
|
||||
bit4= override any restriction on external filters
|
||||
*/
|
||||
int Xorriso_pipe_open(struct XorrisO *xorriso, char *purpose, char *cmd,
|
||||
int in_argc, char **in_argv, char *env_path,
|
||||
int *fd, pid_t *forked_pid, int flag)
|
||||
{
|
||||
int fp_pipe[2], *stdin_pipe= NULL, *stdout_pipe= NULL, status, ret;
|
||||
|
||||
*fd= -1;
|
||||
|
||||
if(!(flag & 16)) {
|
||||
ret= Xorriso_external_filter_banned(xorriso, purpose, 0);
|
||||
if(ret)
|
||||
return(0);
|
||||
}
|
||||
if(pipe(fp_pipe) != 0) {
|
||||
sprintf(xorriso->info_text, "Cannot create pipe(2) object");
|
||||
Xorriso_msgs_submit(xorriso, 0, xorriso->info_text, errno, "FATAL", 0);
|
||||
return(0);
|
||||
}
|
||||
if(flag & 4) {
|
||||
stdout_pipe= fp_pipe;
|
||||
*fd= fp_pipe[0];
|
||||
} else {
|
||||
stdin_pipe= fp_pipe;
|
||||
*fd= fp_pipe[1];
|
||||
}
|
||||
ret= Xorriso_execv(xorriso, cmd, in_argc, in_argv, env_path,
|
||||
stdin_pipe, stdout_pipe, forked_pid, &status, flag & 11);
|
||||
return(ret);
|
||||
}
|
||||
|
||||
|
||||
/* @param flag bit0= path is a command parameter
|
||||
*/
|
||||
int Xorriso_path_is_excluded(struct XorrisO *xorriso, char *path, int flag)
|
||||
|
Reference in New Issue
Block a user