summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--libguile/posix.c5
-rw-r--r--test-suite/tests/posix.test16
2 files changed, 17 insertions, 4 deletions
diff --git a/libguile/posix.c b/libguile/posix.c
index 3ab12b99e..f4ca72d3e 100644
--- a/libguile/posix.c
+++ b/libguile/posix.c
@@ -1,4 +1,4 @@
-/* Copyright 1995-2014,2016-2019,2021
+/* Copyright 1995-2014, 2016-2019, 2021-2022
Free Software Foundation, Inc.
This file is part of Guile.
@@ -1371,7 +1371,8 @@ start_child (const char *exec_file, char **exec_argv,
if (err == 1)
err = renumber_file_descriptor (err, err);
do dup2 (out, 1); while (errno == EINTR);
- close (out);
+ if (out > 2)
+ close (out);
}
if (err > 2)
{
diff --git a/test-suite/tests/posix.test b/test-suite/tests/posix.test
index 1e552d16f..500dbb94a 100644
--- a/test-suite/tests/posix.test
+++ b/test-suite/tests/posix.test
@@ -1,6 +1,6 @@
;;;; posix.test --- Test suite for Guile POSIX functions. -*- scheme -*-
;;;;
-;;;; Copyright 2003-2004,2006-2007,2010,2012,2015,2017-2019,2021
+;;;; Copyright 2003-2004, 2006-2007, 2010, 2012, 2015, 2017-2019, 2021-2022
;;;; Free Software Foundation, Inc.
;;;;
;;;; This library is free software; you can redistribute it and/or
@@ -241,7 +241,19 @@
;; `system*' would remain alive after an `execvp' failure.
(let ((me (getpid)))
(and (not (zero? (system* "something-that-does-not-exist")))
- (= me (getpid))))))
+ (= me (getpid)))))
+
+ (pass-if-equal "exit code for nonexistent file"
+ 127 ;aka. EX_NOTFOUND
+ (status:exit-val (system* "something-that-does-not-exist")))
+
+ (pass-if-equal "https://bugs.gnu.org/55596"
+ 127
+ ;; The parameterization below used to cause 'start_child' to close
+ ;; fd 2 in the child process, which in turn would cause it to
+ ;; segfault, leading to a wrong exit code.
+ (parameterize ((current-output-port (current-error-port)))
+ (status:exit-val (system* "something-that-does-not-exist")))))
;;
;; crypt