mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-11-21 16:37:20 +01:00
Removed commented code. Also call stop() in SubProcessUnix's destructor.
This commit is contained in:
parent
a0a84c4987
commit
4a6868b79d
@ -239,98 +239,7 @@ SubProcessUnix::SubProcessUnix() : SubProcess() {
|
||||
_process_fp = NULL;
|
||||
}
|
||||
SubProcessUnix::~SubProcessUnix() {
|
||||
stop();
|
||||
}
|
||||
|
||||
/*
|
||||
Error SubProcessUnix::execute(const String &p_path, const List<String> &p_arguments, bool p_blocking, ProcessID *r_child_id, String *r_pipe, int *r_exitcode, bool read_stderr, Mutex *p_pipe_mutex, bool p_open_console) {
|
||||
#ifdef __EMSCRIPTEN__
|
||||
// Don't compile this code at all to avoid undefined references.
|
||||
// Actual virtual call goes to OS_JavaScript.
|
||||
ERR_FAIL_V(ERR_BUG);
|
||||
#else
|
||||
if (p_blocking && r_pipe) {
|
||||
String argss;
|
||||
argss = "\"" + p_path + "\"";
|
||||
|
||||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
argss += String(" \"") + p_arguments[i] + "\"";
|
||||
}
|
||||
|
||||
if (read_stderr) {
|
||||
argss += " 2>&1"; // Read stderr too
|
||||
} else {
|
||||
argss += " 2>/dev/null"; //silence stderr
|
||||
}
|
||||
FILE *f = popen(argss.utf8().get_data(), "r");
|
||||
|
||||
ERR_FAIL_COND_V_MSG(!f, ERR_CANT_OPEN, "Cannot pipe stream from process running with following arguments '" + argss + "'.");
|
||||
|
||||
char buf[65535];
|
||||
|
||||
while (fgets(buf, 65535, f)) {
|
||||
if (p_pipe_mutex) {
|
||||
p_pipe_mutex->lock();
|
||||
}
|
||||
(*r_pipe) += String::utf8(buf);
|
||||
if (p_pipe_mutex) {
|
||||
p_pipe_mutex->unlock();
|
||||
}
|
||||
}
|
||||
int rv = pclose(f);
|
||||
if (r_exitcode) {
|
||||
*r_exitcode = WEXITSTATUS(rv);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
pid_t pid = fork();
|
||||
ERR_FAIL_COND_V(pid < 0, ERR_CANT_FORK);
|
||||
|
||||
if (pid == 0) {
|
||||
// is child
|
||||
|
||||
if (!p_blocking) {
|
||||
// For non blocking calls, create a new session-ID so parent won't wait for it.
|
||||
// This ensures the process won't go zombie at end.
|
||||
setsid();
|
||||
}
|
||||
|
||||
Vector<CharString> cs;
|
||||
cs.push_back(p_path.utf8());
|
||||
for (int i = 0; i < p_arguments.size(); i++) {
|
||||
cs.push_back(p_arguments[i].utf8());
|
||||
}
|
||||
|
||||
Vector<char *> args;
|
||||
for (int i = 0; i < cs.size(); i++) {
|
||||
args.push_back((char *)cs[i].get_data());
|
||||
}
|
||||
args.push_back(0);
|
||||
|
||||
execvp(p_path.utf8().get_data(), &args[0]);
|
||||
// still alive? something failed..
|
||||
fprintf(stderr, "**ERROR** SubProcessUnix::execute - Could not create child process while executing: %s\n", p_path.utf8().get_data());
|
||||
raise(SIGKILL);
|
||||
}
|
||||
|
||||
if (p_blocking) {
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
if (r_exitcode) {
|
||||
*r_exitcode = WIFEXITED(status) ? WEXITSTATUS(status) : status;
|
||||
}
|
||||
|
||||
} else {
|
||||
if (r_child_id) {
|
||||
*r_child_id = pid;
|
||||
}
|
||||
}
|
||||
|
||||
return OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
#endif //posix_enabled
|
||||
|
Loading…
Reference in New Issue
Block a user