From ef00209018c4690dd864b2309ae9a2faa15945c5 Mon Sep 17 00:00:00 2001 From: ValKmjolnir Date: Wed, 12 Jun 2024 22:08:02 +0800 Subject: [PATCH] :bug: fix compilation error on macOS --- src/natives/subprocess.cpp | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/src/natives/subprocess.cpp b/src/natives/subprocess.cpp index 91a63a5..6ef5f81 100644 --- a/src/natives/subprocess.cpp +++ b/src/natives/subprocess.cpp @@ -9,12 +9,16 @@ #ifndef _MSC_VER #include +#endif + +#ifndef WIN32 #include #endif #include #include #include +#include namespace nasal { @@ -113,17 +117,6 @@ var builtin_subprocess_fork(context* ctx, gc* ngc) { } 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 auto pid = fork(); if (pid < 0) { @@ -131,7 +124,7 @@ var builtin_subprocess_fork(context* ctx, gc* ngc) { } // child process if (pid==0) { - execve("nasal", argv, env); + execve(argv[0], argv, environ); _exit(-1); } @@ -140,10 +133,7 @@ var builtin_subprocess_fork(context* ctx, gc* ngc) { delete argv[i]; } delete[] argv; - for(usize i = 0; env[i]; ++i) { - delete env[i]; - } - delete[] env; + return var::num(pid); #endif