Fix env not gathered and not passed to child processes

This commit is contained in:
Krzosa Karol
2026-02-07 14:28:16 +01:00
parent 17f4306fc3
commit 84fa04e1db
3 changed files with 23 additions and 6 deletions

View File

@@ -250,8 +250,10 @@ Process SpawnProcess(ExecArgs args) {
char *exe = Copy(scratch, args.exe).data; char *exe = Copy(scratch, args.exe).data;
For (args.env) { For (args.env) {
Add(&env, Copy(scratch, it).data); Add(&env, it.data);
} }
Add(&env, (char *)"\0");
int stdout_desc[2] = {}; int stdout_desc[2] = {};
int stdin_desc[2] = {}; int stdin_desc[2] = {};
@@ -403,7 +405,7 @@ void CloseStdin(Process *process) {
} }
#else #else
Process SpawnProcess(String command_line, String working_dir, String write_stdin, Array<String> enviroment) { return {}; } Process SpawnProcess(ExecArgs args) { return {}; }
bool IsValid(Process *process) { return false; } bool IsValid(Process *process) { return false; }
void KillProcess(Process *process) { } void KillProcess(Process *process) { }
String PollStdout(Allocator allocator, Process *process, bool force_read) { return {}; } String PollStdout(Allocator allocator, Process *process, bool force_read) { return {}; }

View File

@@ -1,4 +1,6 @@
/* /*
- [ ] BRO, the caret teleports on linux when I press the arrow for too long
- [ ] Cleanups - [ ] Cleanups
- [ ] How to enable framerate to be unlimited and not break scrolling? - [ ] How to enable framerate to be unlimited and not break scrolling?
- [x] When dragging a file into the editor, would be nice if the file opened in the window user dropped the file into. Not the active window. - [x] When dragging a file into the editor, would be nice if the file opened in the window user dropped the file into. Not the active window.
@@ -10,6 +12,10 @@
- [ ] Directory tree doesn't make much sense! Maybe just consolidate into one folder? create nice names - the raddbg idea didn't pan out well here - [ ] Directory tree doesn't make much sense! Maybe just consolidate into one folder? create nice names - the raddbg idea didn't pan out well here
- [ ] Test BlockArena correctnsess - random allocations, writes and undos, try to crash - [ ] Test BlockArena correctnsess - random allocations, writes and undos, try to crash
- [ ] General parser / data description thing
- [ ] Rewrite other parsers using this
- [ ] Rewrite Env handling (to not be OS specific)
- New error mechanism - we were losing errors when ReportError was called multiple times, I still want that but I don't want to lose errors, so turn it into a summary list of errors - New error mechanism - we were losing errors when ReportError was called multiple times, I still want that but I don't want to lose errors, so turn it into a summary list of errors
- [ ] BeginLog EndLog, and then show all logs as a list in the UI thing - [ ] BeginLog EndLog, and then show all logs as a list in the UI thing
- [ ] Undo kinds (to enable history in fuzzy buffers) - [ ] Undo kinds (to enable history in fuzzy buffers)
@@ -887,7 +893,7 @@ void MainLoop() {
int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
#else #else
extern char **environ; extern char **environ;
int main(int argc, char **argv) int main(int argc, char **argv, char **envp)
#endif #endif
{ {
#if OS_WINDOWS #if OS_WINDOWS
@@ -912,7 +918,7 @@ int main(int argc, char **argv)
SDL_free(sdl_config_path.data); SDL_free(sdl_config_path.data);
} }
#if OS_WINDOWS #if OS_WINDOWS
{ {
wchar_t *p = GetEnvironmentStringsW(); wchar_t *p = GetEnvironmentStringsW();
for (;p && p[0];) { for (;p && p[0];) {
@@ -924,8 +930,16 @@ int main(int argc, char **argv)
// FreeEnvironmentStringsW(p); // I get a trap here? why? // FreeEnvironmentStringsW(p); // I get a trap here? why?
} }
#else #else
for (int i = 0; environ[i]; i += 1) { char **env = envp;
Add(&ProcessEnviroment, Copy(Perm, environ[i])); if (!env || !env[0]) {
env = environ;
}
if (env && env[0]) {
for (int i = 0; env[i]; i += 1) {
Add(&ProcessEnviroment, Copy(Perm, env[i]));
}
} else {
ReportErrorf("No environment variables found (envp/environ empty)");
} }
#endif #endif

View File

@@ -530,6 +530,7 @@ BSet Open(Window *window, String path, ResolveOpenMeta meta, bool set_active = t
CenterView(window->id); CenterView(window->id);
} else if (o.kind == OpenKind_Exec) { } else if (o.kind == OpenKind_Exec) {
ExecArgs args = {};// ShellArgs(scratch, LogView->id, o.path, GetPrimaryDirectory()); ExecArgs args = {};// ShellArgs(scratch, LogView->id, o.path, GetPrimaryDirectory());
args.env = ProcessEnviroment;
args.poll_process = 1; args.poll_process = 1;
args.output_view = LogView->id; args.output_view = LogView->id;
args.cwd = GetPrimaryDirectory(); args.cwd = GetPrimaryDirectory();