Skip to content
Snippets Groups Projects

[internal #0] fixing f_EPTF_Base_executeShell to use sh/bash/tcsh to start the command

Merged József Gyürüsi requested to merge jgyrsi/titan.Libraries.CLL:master into master
1 unresolved thread
Files
32
@@ -202,28 +202,56 @@ INTEGER EPTF__CLL__Base__Functions::f__EPTF__Base__executeShell(const CHARSTRING
}
argv[argc++] = (char*)NULL; // no additional args
*/
argv[0]=strdup("tcsh");
argv[0]=strdup("bash");
argv[1]=strdup("-c");
argv[2]=strdup(cmd);
argv[3]=NULL;
// execute
if(execvp(argv[0],argv) < 0) {
// failed to start the command with bash
// do not print anything to stderr here! Command may be successful with starting it with tcsh or sh
fflush(stdout);
fflush(stderr);
}
// this is not reached: if execvp is successful
// if bash fails, try tcsh
argv[0]=strdup("tcsh");
// execute
if(execvp(argv[0],argv) < 0) {
// failed to start the command with tcsh
// do not print anything to stderr here! Command may be successful with starting it with sh
fflush(stdout);
fflush(stderr);
}
// this is not reached: if execvp is successful
// if tcsh fails, try sh
argv[0]=strdup("sh");
// execute
if(execvp(argv[0],argv) < 0) {
// failed to start the command with sh
// do not print anything to stderr here! Error is printed below.
fflush(stdout);
fflush(stderr);
}
// generate error exit code with the false command (do not just call exit(1): it will close the used file descriptors which will also be closed on main thread)
// print error message here:
fprintf(stderr,"f_EPTF_Base_executeShell: Failed to start the command %s",(const char*)cmd);
fflush(stderr);
argv[0]="false";
argv[1]=NULL;
if(execvp(argv[0],argv)< 0) {
// this should be never reached
// if reached, there will be file descriptor closing errors and program may hang!
fprintf(stderr,"f_EPTF_Base_executeShell: Failed to start the %s",(const char*)argv[0]);
fflush(stdout);
fflush(stderr);
/*
argv[0]="tcsh";
argv[1]="-c";
argv[2]=(char*)(const char*)(CHARSTRING("exit ")+int2str(errno));
argv[3]=NULL;
if(execvp(argv[0],argv)< 0) {
fprintf(stderr,"f_EPTF_Base_executeShell: Failed to start the %s",(const char*)argv[0]);
}
*/
}
TTCN_Logger::log(TTCN_Logger::TTCN_DEBUG,"EXECVP FINISHED:");
// this is never reached: 2nd execvp is always successful
// this is never reached: last execvp is always successful
exit(1); // exit the child thread
} else { // Parent process
TTCN_Logger::log(TTCN_Logger::TTCN_DEBUG,"f_EPTF_Base_executeShell: %s launched with PID: %i",(const char*)pl__command, processPid);
Loading