Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
- Use vfork/execl instead of system for the System.systemCall implementation on Linux
  - This does not sometimes spin in an endless loop using bootstrapped omc


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7608 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Jan 1, 2011
1 parent 1c39d06 commit 3908403
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Compiler/runtime/systemimpl.c
Expand Up @@ -451,7 +451,29 @@ int SystemImpl__systemCall(const char* str)
}

fflush(NULL); /* flush output so the testsuite is deterministic */
#if defined(__MINGW32__) || defined(_MSC_VER)
status = system(str);
#else
pid_t pID = vfork();
if (pID == 0) { // child
execl("/bin/sh", "/bin/sh", "-c", str, NULL);
if (debug) {
fprintf(stderr, "System.systemCall: execl failed %s\n", strerror(errno));
fflush(NULL);
}
_exit(1);
} else if (pID < 0) {
const char *tokens[2] = {str,strerror(errno)};
c_add_message(-1,"SCRIPTING","ERROR","system(%s) failed: %s",tokens,2);
return -1;
} else {

if (waitpid(pID, &status, 0) == -1) {
const char *tokens[2] = {str,strerror(errno)};
c_add_message(-1,"SCRIPTING","ERROR","system(%s) failed: %s",tokens,2);
}
}
#endif
fflush(NULL); /* flush output so the testsuite is deterministic */

if (debug) {
Expand Down

0 comments on commit 3908403

Please sign in to comment.