Commit a6ca5aef1cc56796aece9fb7f1238d10b5e73b17

Thomas de Grivel 2024-09-20T21:29:10

fix system

diff --git a/ikc3/.ikc3_history b/ikc3/.ikc3_history
index b753c8f..f0d64fa 100644
--- a/ikc3/.ikc3_history
+++ b/ikc3/.ikc3_history
@@ -1,4 +1,3 @@
-to_lisp(quote a = ? <- 1 ; 2)
 a = ?
 Facts.with_tags(Facts.env_facts(), KC3, :operator, a, fn (fact) { puts(a); 1 })
 to_lisp(quote a = ? <- 1 ; 2)
@@ -97,3 +96,4 @@ a
 a = cow 1
 a <- 2
 a
+system(["ls"])
diff --git a/libkc3/kc3.c b/libkc3/kc3.c
index 8b41044..cb9e67d 100644
--- a/libkc3/kc3.c
+++ b/libkc3/kc3.c
@@ -479,11 +479,13 @@ s_str * kc3_system (const s_list * const *list, s_str *dest)
   }
   if (! pid)
     kc3_system_pipe_exec(pipe_fd[1], argv, list);
+  close(pipe_fd[1]);
   if (! fd_read_until_eof(pipe_fd[0], &tmp)) {
     err_puts("kc3_system: fd_read_until_eof");
     assert(! "kc3_system: fd_read_until_eof");
     goto clean;
   }
+  close(pipe_fd[0]);
   if (waitpid(pid, &status, 0) < 0) {
     e = errno;
     err_write_1("kc3_system: waitpid: ");
@@ -512,6 +514,7 @@ void kc3_system_pipe_exec (s32 pipe_w, char **argv,
     assert(! "kc3_system: dup2(pipe_w, 1)");
     _exit(1);
   }
+  close(pipe_w);
   if (dup2(1, 2) < 0) {
     e = errno;
     err_write_1("kc3_system: dup2(1, 2): ");