Skip to content
Snippets Groups Projects

[internal #0] error handling fix in f_EPTF_Base_executeShell

Merged József Gyürüsi requested to merge base_execCmd_fix into master
1 file
+ 21
4
Compare changes
  • Side-by-side
  • Inline
@@ -209,7 +209,8 @@ INTEGER EPTF__CLL__Base__Functions::f__EPTF__Base__executeShell(const CHARSTRING
// execute
if(execvp(argv[0],argv) < 0) {
fprintf(stderr,"f_EPTF_Base_executeShell: Failed to start the %s",(const char*)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);
}
@@ -219,7 +220,8 @@ INTEGER EPTF__CLL__Base__Functions::f__EPTF__Base__executeShell(const CHARSTRING
// execute
if(execvp(argv[0],argv) < 0) {
fprintf(stderr,"f_EPTF_Base_executeShell: Failed to start the %s",(const char*)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);
}
@@ -229,12 +231,27 @@ INTEGER EPTF__CLL__Base__Functions::f__EPTF__Base__executeShell(const CHARSTRING
// 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);
}
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