fx.diagnostics: add linux support for starting processes

This commit is contained in:
2026-06-13 14:48:19 +01:00
parent 10cfb05287
commit 8237fae60f
4 changed files with 540 additions and 13 deletions
+18 -8
View File
@@ -84,7 +84,6 @@ static fx_status process_start(struct fx_process_p *proc)
if (proc->proc_redirect_stdout) {
fx_iostream_unref(out_r);
fd = fx_iostream_steal_os_handle(out_w);
fprintf(stderr, "dup2(%d, %d)\n", fd, 1);
dup2(fd, 1);
close(fd);
}
@@ -92,17 +91,28 @@ static fx_status process_start(struct fx_process_p *proc)
if (proc->proc_redirect_stderr) {
fx_iostream_unref(err_r);
fd = fx_iostream_steal_os_handle(err_w);
fprintf(stderr, "dup2(%d, %d)\n", fd, 2);
dup2(fd, 2);
close(fd);
}
const char *args[] = {
"cowsay",
NULL,
};
printf("exec '%s'\n", fx_string_get_cstr(proc->proc_exec_path));
execv(fx_string_get_cstr(proc->proc_exec_path), (char *const *)args);
const char **argv = NULL;
size_t argc = 0;
if (proc->proc_args) {
argc = fx_array_get_size(proc->proc_args);
}
if (argc) {
argv = calloc(argc + 1, sizeof(char *));
for (size_t i = 0; i < argc; i++) {
const fx_value *arg_value
= fx_array_get_ref(proc->proc_args, i);
fx_value_get_cstr(arg_value, &argv[i]);
}
}
execv(fx_string_get_cstr(proc->proc_exec_path), (char *const *)argv);
exit(127);
cleanup: