1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-09 13:30:26 +02:00

'system*' can no longer close file descriptor 2.

Fixes <https://bugs.gnu.org/55596>.
Reported by Hugo Nobrega <hugonobrega@ic.ufrj.br>
and Jack Hill <jackhill@jackhill.us>.

* libguile/posix.c (start_child): Close OUT only if it's greater than 2.
* test-suite/tests/posix.test ("system*")["exit code for nonexistent file"]
["https://bugs.gnu.org/55596"]: New tests.
This commit is contained in:
Ludovic Courtès 2022-08-05 12:35:36 +02:00
parent 01e960edea
commit 56b1ea9002
2 changed files with 17 additions and 4 deletions

View file

@ -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)
{

View file

@ -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