🐛 fix compilation error on macOS

This commit is contained in:
ValKmjolnir 2024-06-12 22:08:02 +08:00
parent bf9f0d6338
commit ef00209018
1 changed files with 6 additions and 16 deletions

View File

@ -9,12 +9,16 @@
#ifndef _MSC_VER #ifndef _MSC_VER
#include <unistd.h> #include <unistd.h>
#endif
#ifndef WIN32
#include <sys/wait.h> #include <sys/wait.h>
#endif #endif
#include <cstdio> #include <cstdio>
#include <cstdlib> #include <cstdlib>
#include <vector> #include <vector>
#include <csignal>
namespace nasal { namespace nasal {
@ -113,17 +117,6 @@ var builtin_subprocess_fork(context* ctx, gc* ngc) {
} }
argv[cmd.vec().elems.size()] = nullptr; argv[cmd.vec().elems.size()] = nullptr;
// use the same env of parent process
char** env = nullptr;
if (getenv("PATH")) {
env = new char*[2];
env[0] = strdup((std::string("PATH=") + getenv("PATH")).c_str());
env[1] = nullptr;
} else {
env = new char*[1];
env[0] = nullptr;
}
// create child process // create child process
auto pid = fork(); auto pid = fork();
if (pid < 0) { if (pid < 0) {
@ -131,7 +124,7 @@ var builtin_subprocess_fork(context* ctx, gc* ngc) {
} }
// child process // child process
if (pid==0) { if (pid==0) {
execve("nasal", argv, env); execve(argv[0], argv, environ);
_exit(-1); _exit(-1);
} }
@ -140,10 +133,7 @@ var builtin_subprocess_fork(context* ctx, gc* ngc) {
delete argv[i]; delete argv[i];
} }
delete[] argv; delete[] argv;
for(usize i = 0; env[i]; ++i) {
delete env[i];
}
delete[] env;
return var::num(pid); return var::num(pid);
#endif #endif