Received: (at 33965) by debbugs.gnu.org; 7 Jan 2019 01:47:44 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sun Jan 06 20:47:44 2019 Received: from localhost ([127.0.0.1]:47488 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1ggK12-0008Gz-C8 for submit <at> debbugs.gnu.org; Sun, 06 Jan 2019 20:47:44 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:36386) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <eggert@HIDDEN>) id 1ggK0z-0008Gm-Nx for 33965 <at> debbugs.gnu.org; Sun, 06 Jan 2019 20:47:43 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 20C59160F77; Sun, 6 Jan 2019 17:47:36 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id rHeX63v--FhB; Sun, 6 Jan 2019 17:47:35 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 21980160F84; Sun, 6 Jan 2019 17:47:35 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id cofySn1O7GBc; Sun, 6 Jan 2019 17:47:35 -0800 (PST) Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id E7BFA160747; Sun, 6 Jan 2019 17:47:34 -0800 (PST) Subject: Re: handling of closed file descriptors To: Bruno Haible <bruno@HIDDEN> References: <6639990.yRvKeTYcJc@omega> <2095398.ToFATaR5yE@omega> <e44b73f3-60dc-11cb-1187-5a5b76816881@HIDDEN> <2029673.eREQEScGAn@omega> From: Paul Eggert <eggert@HIDDEN> Organization: UCLA Computer Science Department Message-ID: <568450be-5ebc-b52b-f824-696aa9dc782d@HIDDEN> Date: Sun, 6 Jan 2019 17:47:34 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <2029673.eREQEScGAn@omega> Content-Type: multipart/mixed; boundary="------------B073A92927AA86D4E38598FF" Content-Language: en-US X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 33965 Cc: 33965 <at> debbugs.gnu.org, bug-gnulib@HIDDEN X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) This is a multi-part message in MIME format. --------------B073A92927AA86D4E38598FF Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Thanks for the xstdopen module; it simplifies diffutils and I installed the attached patches there for it. --------------B073A92927AA86D4E38598FF Content-Type: text/x-patch; name="0001-build-update-gnulib-submodule-to-latest.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-build-update-gnulib-submodule-to-latest.patch" From 86ece0ee216910bce0dbceb60b98190bf8f93702 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@HIDDEN> Date: Sun, 6 Jan 2019 17:15:06 -0800 Subject: [PATCH 1/2] build: update gnulib submodule to latest --- gnulib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnulib b/gnulib index 10652b5..8089c00 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit 10652b56fe5b76370187a06296168cff9cffb730 +Subproject commit 8089c00979a5b089cff592c6b91420e595657167 -- 2.17.1 --------------B073A92927AA86D4E38598FF Content-Type: text/x-patch; name="0002-diff-use-xstdopen-not-stdopen.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-diff-use-xstdopen-not-stdopen.patch" From db6d5f7240c8a743aebb3def80b3e3fabf05f0c1 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@HIDDEN> Date: Sun, 6 Jan 2019 17:22:37 -0800 Subject: [PATCH 2/2] diff: use xstdopen, not stdopen * bootstrap.conf (gnulib_modules): * src/cmp.c, src/diff.c, src/diff3.c, src/sdiff.c (main): Use xstdopen, not stdopen. --- bootstrap.conf | 2 +- src/cmp.c | 6 ++---- src/diff.c | 6 ++---- src/diff3.c | 6 ++---- src/sdiff.c | 6 ++---- 5 files changed, 9 insertions(+), 17 deletions(-) diff --git a/bootstrap.conf b/bootstrap.conf index 0c9fbfe..4671349 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -67,7 +67,6 @@ stat stat-macros stat-time stdint -stdopen strcase strftime strptime @@ -85,6 +84,7 @@ wcwidth xalloc xfreopen xreadlink +xstdopen xstrtoumax xvasprintf ' diff --git a/src/cmp.c b/src/cmp.c index 811d039..ce2bdb5 100644 --- a/src/cmp.c +++ b/src/cmp.c @@ -31,11 +31,11 @@ #include <hard-locale.h> #include <inttostr.h> #include <progname.h> -#include <stdopen.h> #include <unlocked-io.h> #include <version-etc.h> #include <xalloc.h> #include <binary-io.h> +#include <xstdopen.h> #include <xstrtol.h> /* The official name of this program (e.g., no 'g' prefix). */ @@ -210,9 +210,7 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); c_stack_action (0); - int stdopen_errno = stdopen (); - if (stdopen_errno != 0) - error (EXIT_TROUBLE, stdopen_errno, _("standard file descriptors")); + xstdopen (); /* Parse command line options. */ diff --git a/src/diff.c b/src/diff.c index 541d912..e9c2b11 100644 --- a/src/diff.c +++ b/src/diff.c @@ -37,11 +37,11 @@ #include <progname.h> #include <sh-quote.h> #include <stat-time.h> -#include <stdopen.h> #include <timespec.h> #include <version-etc.h> #include <xalloc.h> #include <xreadlink.h> +#include <xstdopen.h> #include <binary-io.h> /* The official name of this program (e.g., no 'g' prefix). */ @@ -298,9 +298,7 @@ main (int argc, char **argv) re_set_syntax (RE_SYNTAX_GREP | RE_NO_POSIX_BACKTRACKING); excluded = new_exclude (); presume_output_tty = false; - int stdopen_errno = stdopen (); - if (stdopen_errno != 0) - error (EXIT_TROUBLE, stdopen_errno, _("standard file descriptors")); + xstdopen (); /* Decode the options. */ diff --git a/src/diff3.c b/src/diff3.c index 8ce1a3d..037df25 100644 --- a/src/diff3.c +++ b/src/diff3.c @@ -30,11 +30,11 @@ #include <file-type.h> #include <getopt.h> #include <progname.h> -#include <stdopen.h> #include <system-quote.h> #include <version-etc.h> #include <xalloc.h> #include <xfreopen.h> +#include <xstdopen.h> /* The official name of this program (e.g., no 'g' prefix). */ #define PROGRAM_NAME "diff3" @@ -273,9 +273,7 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); c_stack_action (0); - int stdopen_errno = stdopen (); - if (stdopen_errno != 0) - error (EXIT_TROUBLE, stdopen_errno, _("standard file descriptors")); + xstdopen (); while ((c = getopt_long (argc, argv, "aeimvx3AEL:TX", longopts, 0)) != -1) { diff --git a/src/sdiff.c b/src/sdiff.c index 605fd33..2ef83da 100644 --- a/src/sdiff.c +++ b/src/sdiff.c @@ -32,10 +32,10 @@ #include <file-type.h> #include <getopt.h> #include <progname.h> -#include <stdopen.h> #include <system-quote.h> #include <version-etc.h> #include <xalloc.h> +#include <xstdopen.h> /* The official name of this program (e.g., no 'g' prefix). */ #define PROGRAM_NAME "sdiff" @@ -456,9 +456,7 @@ main (int argc, char *argv[]) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); c_stack_action (cleanup); - int stdopen_errno = stdopen (); - if (stdopen_errno != 0) - error (EXIT_TROUBLE, stdopen_errno, _("standard file descriptors")); + xstdopen (); prog = getenv ("EDITOR"); if (prog) -- 2.17.1 --------------B073A92927AA86D4E38598FF--
bug-diffutils@HIDDEN
:bug#33965
; Package diffutils
.
Full text available.Received: (at 33965) by debbugs.gnu.org; 6 Jan 2019 04:07:04 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jan 05 23:07:04 2019 Received: from localhost ([127.0.0.1]:48195 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1gfziJ-0004Fi-Cq for submit <at> debbugs.gnu.org; Sat, 05 Jan 2019 23:07:04 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:60164) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <eggert@HIDDEN>) id 1gfziG-0004FB-Jg for 33965 <at> debbugs.gnu.org; Sat, 05 Jan 2019 23:07:02 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id BFDDF160F7A; Sat, 5 Jan 2019 20:06:54 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 3Y5CuZ_xeWQk; Sat, 5 Jan 2019 20:06:52 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 01BB4160F7D; Sat, 5 Jan 2019 20:06:52 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id xihQTv3G0ggy; Sat, 5 Jan 2019 20:06:51 -0800 (PST) Received: from [192.168.1.9] (cpe-23-242-74-103.socal.res.rr.com [23.242.74.103]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id A3D2E160F46; Sat, 5 Jan 2019 20:06:51 -0800 (PST) Subject: Re: bug#33965: handling of closed file descriptors To: Bruno Haible <bruno@HIDDEN> References: <6639990.yRvKeTYcJc@omega> <1742217.p5sQxCVaLy@omega> <d4d28d01-5433-4d39-a723-c41ae9edb1cb@HIDDEN> <2095398.ToFATaR5yE@omega> From: Paul Eggert <eggert@HIDDEN> Organization: UCLA Computer Science Department Message-ID: <e44b73f3-60dc-11cb-1187-5a5b76816881@HIDDEN> Date: Sat, 5 Jan 2019 20:06:51 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1 MIME-Version: 1.0 In-Reply-To: <2095398.ToFATaR5yE@omega> Content-Type: multipart/mixed; boundary="------------34E9D1D1F5454BCC79E8AA56" Content-Language: en-US X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 33965 Cc: 33965 <at> debbugs.gnu.org, bug-gnulib@HIDDEN, jim@HIDDEN X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) This is a multi-part message in MIME format. --------------34E9D1D1F5454BCC79E8AA56 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Bruno Haible wrote: >> The feature is not portable to POSIX >> platforms. Besides, I doubt whether anybody is using the feature anyway. > > OK, if you question the "feature" as a whole, Sorry, I was referring only to the never-used feature of diffutils, where "-" in a command-line argument stands for a missing file if stdin is closed (only in some cases, e.g., -N). I think nobody uses this feature or will miss it if it's removed, and anyway it can't work on some POSIX-conforming platforms. I put the feature into diffutils in many years ago, but it's now clear that the test case that is exercising it is a mistake and that the feature itself was mistaken. But to broaden this to the more-general issue of whether kernels should force stdin/stdout/stderr to be open after an exec: > I predict that this "simple change to the kernel" will not make it into > the majority of the operating systems in the next 10 years. (But you > could start lobbying for it among the OpenBSD people. They would be the > most likely to adopt it, I guess.) OpenBSD has already adopted it for setuid and setgid executables, as has FreeBSD, NetBSD, and SELinux. I imagine this feature is reasonably common elsewhere, at least for setuid (I haven't checked carefully). As far as I know only HP-UX does it for non-setuid/gid executables. > In the mean time, the remaining options I can see are: > > (a) Keep using the *-safer Gnulib modules. > > (b) Introduce a sanity_check_file_descriptors() function > ... > void > sanity_check_file_descriptors (void) > { > int fd; > for (fd = 0; fd <= 2; fd++) > if (fcntl (fd, F_GETFD, NULL) < 0 && errno == EBADF) > exit (125); > } > ... > (b) surely is simpler than (a). I suggest instead a third option (c) that was formerly used in Coreutils, which is that the program makes sure that stdin/stdout/stderr are open before doing anything that creates a file descriptor. As I understand it Coreutils moved away from that approach primarily because it was redundant if the (earlier) *-safer modules are also used. However, in hindsight perhaps Coreutils should have stopped using the *-safer modules and just used method (c); it's a lot simpler and less intrusive. I resurrected and refreshed that old Coreutils code and put it into a new Gnulib module stdopen, adjusted Gnulib's xfreopen module in a couple of minor ways (only diffutils uses xfreopen as far as I know) so that it no longer requires freopen-safer, and installed the first four attached patches into Gnulib. I then propagated this into diffutils and removed the unportable feature by installing the last three attached patches into diffutils. As a result of these changes, diffutils no longer uses the *-safer modules (it uses the new stdopen module instead), it no longer supports the unportable feature in question, and it no longer mishandles some obscure situations where stdin, stdout, or stderr are closed. --------------34E9D1D1F5454BCC79E8AA56 Content-Type: text/x-patch; name="0001-stdopen-copy-from-last-use-in-coreutils.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-stdopen-copy-from-last-use-in-coreutils.patch" From 14e1f1c39766bcb3fe4d6ec975ecac4058d11d98 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@HIDDEN> Date: Sat, 5 Jan 2019 11:02:51 -0800 Subject: [PATCH 1/4] stdopen: copy from last use in coreutils * lib/stdopen.c, lib/stdopen.h, m4/stdopen.m4: New files, taken from their last commit in coreutils 2007-07-23T12:35:58Z!jim@HIDDEN 71aa3ea88084d17bcb4fc1031ad7b66f8647115e. --- ChangeLog | 8 ++++++ lib/stdopen.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++++ lib/stdopen.h | 16 +++++++++++ m4/stdopen.m4 | 13 +++++++++ 4 files changed, 111 insertions(+) create mode 100644 lib/stdopen.c create mode 100644 lib/stdopen.h create mode 100644 m4/stdopen.m4 diff --git a/ChangeLog b/ChangeLog index d05cd8453..72d75ef26 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2019-01-05 Paul Eggert <eggert@HIDDEN> + + stdopen: copy from last use in coreutils + * lib/stdopen.c, lib/stdopen.h, m4/stdopen.m4: + New files, taken from their last commit in coreutils + 2007-07-23T12:35:58Z!jim@HIDDEN + 71aa3ea88084d17bcb4fc1031ad7b66f8647115e. + 2019-01-05 Bruno Haible <bruno@HIDDEN> argp: Don't pass an invalid argument to dgettext(). diff --git a/lib/stdopen.c b/lib/stdopen.c new file mode 100644 index 000000000..e9b554485 --- /dev/null +++ b/lib/stdopen.c @@ -0,0 +1,74 @@ +/* stdopen.c - ensure that the three standard file descriptors are in use + + Copyright (C) 2005, 2006 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see <http://www.gnu.org/licenses/>. */ + +/* Written by Paul Eggert and Jim Meyering. */ + +#include <config.h> + +#include "stdopen.h" + +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> + +/* Try to ensure that all of the standard file numbers (0, 1, 2) + are in use. Without this, each application would have to guard + every call to open, dup, fopen, etc. with tests to ensure they + don't use one of the special file numbers when opening a file. + Return false if at least one of the file descriptors is initially + closed and an attempt to reopen it fails. Otherwise, return true. */ +bool +stdopen (void) +{ + int fd; + bool ok = true; + + for (fd = 0; fd <= 2; fd++) + { + if (fcntl (fd, F_GETFD) < 0) + { + if (errno != EBADF) + ok = false; + else + { + static const int contrary_mode[] + = { O_WRONLY, O_RDONLY, O_RDONLY }; + int mode = contrary_mode[fd]; + int new_fd; + /* Open /dev/null with the contrary mode so that the typical + read (stdin) or write (stdout, stderr) operation will fail. + With descriptor 0, we can do even better on systems that + have /dev/full, by opening that write-only instead of + /dev/null. The only drawback is that a write-provoked + failure comes with a misleading errno value, ENOSPC. */ + if (mode == O_RDONLY + || (new_fd = open ("/dev/full", mode) != fd)) + new_fd = open ("/dev/null", mode); + if (new_fd != fd) + { + if (0 <= new_fd) + close (new_fd); + ok = false; + } + } + } + } + + return ok; +} diff --git a/lib/stdopen.h b/lib/stdopen.h new file mode 100644 index 000000000..d54e5f135 --- /dev/null +++ b/lib/stdopen.h @@ -0,0 +1,16 @@ +#ifndef STDOPEN_H +# define STDOPEN_H 1 + +# include <stdbool.h> + +# ifdef __cplusplus +extern "C" { +# endif + +bool stdopen (void); + +# ifdef __cplusplus +} +# endif + +#endif diff --git a/m4/stdopen.m4 b/m4/stdopen.m4 new file mode 100644 index 000000000..b18c22ddf --- /dev/null +++ b/m4/stdopen.m4 @@ -0,0 +1,13 @@ +#serial 1 +dnl Copyright (C) 2005 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_STDOPEN], +[ + AC_LIBSOURCES([stdopen.c, stdopen.h]) + AC_LIBOBJ([stdopen]) + + dnl Prerequisites. +]) -- 2.20.1 --------------34E9D1D1F5454BCC79E8AA56 Content-Type: text/x-patch; name="0002-stdopen-modernize-and-simplify.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-stdopen-modernize-and-simplify.patch" From a4015f0453aeb60cfa70dcdfbd78db62b3a79b62 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@HIDDEN> Date: Sat, 5 Jan 2019 18:02:32 -0800 Subject: [PATCH 2/4] stdopen: modernize and simplify * lib/stdopen.c: Update copyright date Do not include sys/types.h; no longer needed these days. (stdopen): Use C99-style decl in loop. Return int errno value, rather than just a bool. Do not worry about fd mismatches, since the caller cares only if 0, 1, 2 are occupied. * lib/stdopen.h: No need to include <stdbool.h>. * m4/stdopen.m4: Remove. * modules/stdopen: New file. --- ChangeLog | 10 ++++++++ lib/stdopen.c | 63 +++++++++++++++++++++---------------------------- lib/stdopen.h | 4 +--- m4/stdopen.m4 | 13 ---------- modules/stdopen | 24 +++++++++++++++++++ 5 files changed, 62 insertions(+), 52 deletions(-) delete mode 100644 m4/stdopen.m4 create mode 100644 modules/stdopen diff --git a/ChangeLog b/ChangeLog index 72d75ef26..16ad6f169 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2019-01-05 Paul Eggert <eggert@HIDDEN> + stdopen: modernize and simplify + * lib/stdopen.c: Update copyright date + Do not include sys/types.h; no longer needed these days. + (stdopen): Use C99-style decl in loop. Return int errno + value, rather than just a bool. Do not worry about fd mismatches, + since the caller cares only if 0, 1, 2 are occupied. + * lib/stdopen.h: No need to include <stdbool.h>. + * m4/stdopen.m4: Remove. + * modules/stdopen: New file. + stdopen: copy from last use in coreutils * lib/stdopen.c, lib/stdopen.h, m4/stdopen.m4: New files, taken from their last commit in coreutils diff --git a/lib/stdopen.c b/lib/stdopen.c index e9b554485..3903224e6 100644 --- a/lib/stdopen.c +++ b/lib/stdopen.c @@ -1,6 +1,6 @@ /* stdopen.c - ensure that the three standard file descriptors are in use - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005-2006, 2019 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,7 +21,6 @@ #include "stdopen.h" -#include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> @@ -31,44 +30,36 @@ are in use. Without this, each application would have to guard every call to open, dup, fopen, etc. with tests to ensure they don't use one of the special file numbers when opening a file. - Return false if at least one of the file descriptors is initially - closed and an attempt to reopen it fails. Otherwise, return true. */ -bool + Return zero if successful, an errno value if at least one of + the file descriptors is initially closed and could not be opened. */ + +int stdopen (void) { - int fd; - bool ok = true; - - for (fd = 0; fd <= 2; fd++) + for (int fd = STDIN_FILENO; fd <= STDERR_FILENO; fd++) { if (fcntl (fd, F_GETFD) < 0) - { - if (errno != EBADF) - ok = false; - else - { - static const int contrary_mode[] - = { O_WRONLY, O_RDONLY, O_RDONLY }; - int mode = contrary_mode[fd]; - int new_fd; - /* Open /dev/null with the contrary mode so that the typical - read (stdin) or write (stdout, stderr) operation will fail. - With descriptor 0, we can do even better on systems that - have /dev/full, by opening that write-only instead of - /dev/null. The only drawback is that a write-provoked - failure comes with a misleading errno value, ENOSPC. */ - if (mode == O_RDONLY - || (new_fd = open ("/dev/full", mode) != fd)) - new_fd = open ("/dev/null", mode); - if (new_fd != fd) - { - if (0 <= new_fd) - close (new_fd); - ok = false; - } - } - } + { + /* Open /dev/null with the contrary mode so that the typical + read (stdin) or write (stdout, stderr) operation will fail. + With descriptor 0, we can do even better on systems that + have /dev/full, by opening that write-only instead of + /dev/null. The only drawback is that a write-provoked + failure comes with a misleading errno value, ENOSPC. */ + int mode = fd == STDIN_FILENO ? O_WRONLY : O_RDONLY; + int full_fd = fd == STDIN_FILENO ? open ("/dev/full", mode) : -1; + int new_fd = full_fd < 0 ? open ("/dev/null", mode) : full_fd; + if (new_fd < 0) + return errno; + if (STDERR_FILENO < new_fd) + { + /* 0, 1, and 2 are already open somehow. + Our is not to reason why. */ + close (new_fd); + return 0; + } + } } - return ok; + return 0; } diff --git a/lib/stdopen.h b/lib/stdopen.h index d54e5f135..27901d397 100644 --- a/lib/stdopen.h +++ b/lib/stdopen.h @@ -1,13 +1,11 @@ #ifndef STDOPEN_H # define STDOPEN_H 1 -# include <stdbool.h> - # ifdef __cplusplus extern "C" { # endif -bool stdopen (void); +int stdopen (void); # ifdef __cplusplus } diff --git a/m4/stdopen.m4 b/m4/stdopen.m4 deleted file mode 100644 index b18c22ddf..000000000 --- a/m4/stdopen.m4 +++ /dev/null @@ -1,13 +0,0 @@ -#serial 1 -dnl Copyright (C) 2005 Free Software Foundation, Inc. -dnl This file is free software; the Free Software Foundation -dnl gives unlimited permission to copy and/or distribute it, -dnl with or without modifications, as long as this notice is preserved. - -AC_DEFUN([gl_STDOPEN], -[ - AC_LIBSOURCES([stdopen.c, stdopen.h]) - AC_LIBOBJ([stdopen]) - - dnl Prerequisites. -]) diff --git a/modules/stdopen b/modules/stdopen new file mode 100644 index 000000000..81de5765b --- /dev/null +++ b/modules/stdopen @@ -0,0 +1,24 @@ +Description: +Arrange for stdin/stdout/stderr to be open. + +Files: +lib/stdopen.c +lib/stdopen.h + +Depends-on: +fcntl +unistd + +configure.ac: + +Makefile.am: +lib_SOURCES += stdopen.c + +Include: +"stdopen.h" + +License: +GPL + +Maintainer: +all -- 2.20.1 --------------34E9D1D1F5454BCC79E8AA56 Content-Type: text/x-patch; name="0003-xfreopen-need-not-depend-on-freopen-safer.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0003-xfreopen-need-not-depend-on-freopen-safer.patch" From f9d6fc71e4ebc142410352253fb1db337f530bdf Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@HIDDEN> Date: Sat, 5 Jan 2019 18:03:10 -0800 Subject: [PATCH 3/4] xfreopen need not depend on freopen-safer * modules/xfreopen (Depends-on): Depend on freopen, not freopen-safer. --- ChangeLog | 4 ++++ modules/xfreopen | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 16ad6f169..a88a52083 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2019-01-05 Paul Eggert <eggert@HIDDEN> + xfreopen need not depend on freopen-safer + * modules/xfreopen (Depends-on): + Depend on freopen, not freopen-safer. + stdopen: modernize and simplify * lib/stdopen.c: Update copyright date Do not include sys/types.h; no longer needed these days. diff --git a/modules/xfreopen b/modules/xfreopen index dcc48e0ac..850446d7a 100644 --- a/modules/xfreopen +++ b/modules/xfreopen @@ -8,7 +8,7 @@ lib/xfreopen.h Depends-on: error exitfail -freopen-safer +freopen quote configure.ac: -- 2.20.1 --------------34E9D1D1F5454BCC79E8AA56 Content-Type: text/x-patch; name="0004-xfreopen-need-not-include-stdio-.h.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0004-xfreopen-need-not-include-stdio-.h.patch" From 10652b56fe5b76370187a06296168cff9cffb730 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@HIDDEN> Date: Sat, 5 Jan 2019 18:55:19 -0800 Subject: [PATCH 4/4] xfreopen need not include stdio--.h * lib/xfreopen.c: Do not include stdio--.h. --- ChangeLog | 3 +++ lib/xfreopen.c | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index a88a52083..73a86f29a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,8 @@ 2019-01-05 Paul Eggert <eggert@HIDDEN> + xfreopen need not include stdio--.h + * lib/xfreopen.c: Do not include stdio--.h. + xfreopen need not depend on freopen-safer * modules/xfreopen (Depends-on): Depend on freopen, not freopen-safer. diff --git a/lib/xfreopen.c b/lib/xfreopen.c index 32a38d444..46a7c92a5 100644 --- a/lib/xfreopen.c +++ b/lib/xfreopen.c @@ -21,7 +21,6 @@ #include "error.h" #include "exitfail.h" #include "quote.h" -#include "stdio--.h" #include "gettext.h" #define _(msgid) gettext (msgid) -- 2.20.1 --------------34E9D1D1F5454BCC79E8AA56 Content-Type: text/x-patch; name="0001-build-update-gnulib-submodule-to-latest.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0001-build-update-gnulib-submodule-to-latest.patch" From 1104d026514014808629f28f2e6c787bf3c520c4 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@HIDDEN> Date: Sat, 5 Jan 2019 18:05:33 -0800 Subject: [PATCH 1/3] build: update gnulib submodule to latest --- gnulib | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gnulib b/gnulib index 4652c7b..10652b5 160000 --- a/gnulib +++ b/gnulib @@ -1 +1 @@ -Subproject commit 4652c7bafa60332145f1e05a7de5f48e1bc56226 +Subproject commit 10652b56fe5b76370187a06296168cff9cffb730 -- 2.17.1 --------------34E9D1D1F5454BCC79E8AA56 Content-Type: text/x-patch; name="0002-diff-remove-unportable-diff-N-f-feature.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0002-diff-remove-unportable-diff-N-f-feature.patch" From 2c9d956aacdfddbb87334c985cd995d75102f789 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@HIDDEN> Date: Sat, 5 Jan 2019 19:20:11 -0800 Subject: [PATCH 2/3] =?UTF-8?q?diff:=20remove=20unportable=20=E2=80=98diff?= =?UTF-8?q?=20-N=20-=20f=20<&-=E2=80=99=20feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * NEWS: Mention this. * bootstrap.conf (gnulib_modules): Add stdopen. * doc/diffutils.texi (Comparing Directories): Do not document behavior if stdin is closed. * src/diff.c: Include stdopen.h. (main): Call stdopen early. (compare_files) [__hpux]: Remove recently-introduced special case for HP-UX exec with stdin closed. * tests/new-file: Remove tests of the removed feature. --- NEWS | 9 +++++++++ bootstrap.conf | 1 + doc/diffutils.texi | 3 +-- src/diff.c | 11 ++++------- tests/new-file | 14 -------------- 5 files changed, 15 insertions(+), 23 deletions(-) diff --git a/NEWS b/NEWS index d45d0fc..af675da 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,15 @@ GNU diffutils NEWS -*- outline -*- * Noteworthy changes in release ?.? (????-??-??) [?] +** Incompatible changes + + diff no longer treats a closed stdin as representing an absent file + in usage like 'diff --new-file - foo <&-'. This feature was rarely + if ever used and was not portable to POSIX platforms that reopen + stdin on exec, such as SELinux if the process underwent an AT_SECURE + transition, or HP-UX even if not setuid. + [bug#33965 introduced in 2.8] + * Noteworthy changes in release 3.7 (2018-12-31) [stable] diff --git a/bootstrap.conf b/bootstrap.conf index 48cadd4..0c9fbfe 100644 --- a/bootstrap.conf +++ b/bootstrap.conf @@ -67,6 +67,7 @@ stat stat-macros stat-time stdint +stdopen strcase strftime strptime diff --git a/doc/diffutils.texi b/doc/diffutils.texi index 42d3abd..3a780db 100644 --- a/doc/diffutils.texi +++ b/doc/diffutils.texi @@ -1796,8 +1796,7 @@ second position.) To do this, use the @option{--new-file} (@option{-N}) option. This option affects command-line arguments as well as files found via directory traversal; for example, @samp{diff -N a b} treats @file{a} as empty if @file{a} does not exist but -@file{b} does, and similarly @samp{diff -N - b} treats standard input -as empty if it is closed but @file{b} exists. +@file{b} does. If the older directory contains large files that are not in the newer directory, you can make the patch smaller by using the diff --git a/src/diff.c b/src/diff.c index 2ed3ae5..a5ec7f4 100644 --- a/src/diff.c +++ b/src/diff.c @@ -37,6 +37,7 @@ #include <progname.h> #include <sh-quote.h> #include <stat-time.h> +#include <stdopen.h> #include <timespec.h> #include <version-etc.h> #include <xalloc.h> @@ -297,6 +298,9 @@ main (int argc, char **argv) re_set_syntax (RE_SYNTAX_GREP | RE_NO_POSIX_BACKTRACKING); excluded = new_exclude (); presume_output_tty = false; + int stdopen_errno = stdopen (); + if (stdopen_errno != 0) + error (EXIT_TROUBLE, stdopen_errno, "standard file descriptors"); /* Decode the options. */ @@ -1172,13 +1176,6 @@ compare_files (struct comparison const *parent, cmp.file[f].desc = STDIN_FILENO; if (binary && ! isatty (STDIN_FILENO)) set_binary_mode (STDIN_FILENO, O_BINARY); -#ifdef __hpux - /* Recognize file descriptors closed by the parent on HP-UX. */ - int flags = fcntl (STDIN_FILENO, F_GETFL, NULL); - if (flags >= 0 && (flags & FD_CLOEXEC) != 0) - cmp.file[f].desc = ERRNO_ENCODE (EBADF); - else -#endif if (fstat (STDIN_FILENO, &cmp.file[f].stat) != 0) cmp.file[f].desc = ERRNO_ENCODE (errno); else diff --git a/tests/new-file b/tests/new-file index 4400051..e3a61da 100755 --- a/tests/new-file +++ b/tests/new-file @@ -10,12 +10,6 @@ echo a > a || fail=1 echo '0a1 > a' > exp || fail=1 -returns_ 1 diff -N - a <&- > out || fail=1 -compare exp out || fail=1 - -returns_ 1 diff --unidirectional-new-file - a <&- > out || fail=1 -compare exp out || fail=1 - returns_ 1 diff -N b - < a > out || fail=1 compare exp out || fail=1 @@ -25,14 +19,6 @@ compare exp out || fail=1 echo '1d0 < a' > exp || fail=1 -returns_ 1 diff -N a - <&- > out || fail=1 -compare exp out || fail=1 - -# With closed standard input, require an exit status of 2 -# and empty stdout. -returns_ 2 diff --unidirectional-new-file a - <&- > out || fail=1 -compare /dev/null out || fail=1 - returns_ 1 diff -N - b < a > out || fail=1 compare exp out || fail=1 -- 2.17.1 --------------34E9D1D1F5454BCC79E8AA56 Content-Type: text/x-patch; name="0003-diff-fix-cmp-diff3-sdiff-with-stdin-closed.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="0003-diff-fix-cmp-diff3-sdiff-with-stdin-closed.patch" From 601eceb57cfb87ded594701acc401277c53ff837 Mon Sep 17 00:00:00 2001 From: Paul Eggert <eggert@HIDDEN> Date: Sat, 5 Jan 2019 19:55:08 -0800 Subject: [PATCH 3/3] diff: fix cmp, diff3, sdiff with stdin closed * NEWS: Mention this. * src/cmp.c, src/diff3.c, src/sdiff.c: Include stdopen.h. (main): Call stdopen early. * src/cmp.c (main): Simplify now that we need not worry about stdin being closed. * src/diff.c (main): Translate stdopen diagnostic. --- NEWS | 8 ++++++++ src/cmp.c | 28 ++++++++++++++-------------- src/diff.c | 2 +- src/diff3.c | 4 ++++ src/sdiff.c | 4 ++++ 5 files changed, 31 insertions(+), 15 deletions(-) diff --git a/NEWS b/NEWS index af675da..9ab0748 100644 --- a/NEWS +++ b/NEWS @@ -11,6 +11,14 @@ GNU diffutils NEWS -*- outline -*- transition, or HP-UX even if not setuid. [bug#33965 introduced in 2.8] +** Bug fixes + + diff and related programs no longer get confused if stdin, stdout, + or stderr are closed. Previously, they sometimes opened files into + file descriptors 0, 1, or 2 and then mistakenly did I/O with them + that was intended for stdin, stdout, or stderr. + [bug#33965 present since "the beginning"] + * Noteworthy changes in release 3.7 (2018-12-31) [stable] diff --git a/src/cmp.c b/src/cmp.c index 53ff210..7bad6dd 100644 --- a/src/cmp.c +++ b/src/cmp.c @@ -31,6 +31,7 @@ #include <hard-locale.h> #include <inttostr.h> #include <progname.h> +#include <stdopen.h> #include <unlocked-io.h> #include <version-etc.h> #include <xalloc.h> @@ -199,7 +200,7 @@ GB 1,000,000,000, G 1,073,741,824, and so on for T, P, E, Z, Y."), int main (int argc, char **argv) { - int c, f, exit_status; + int c, exit_status; size_t words_per_buffer; exit_failure = EXIT_TROUBLE; @@ -209,6 +210,9 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); c_stack_action (0); + int stdopen_errno = stdopen (); + if (stdopen_errno != 0) + error (EXIT_TROUBLE, stdopen_errno, _("standard file descriptors")); /* Parse command line options. */ @@ -268,7 +272,7 @@ main (int argc, char **argv) file[0] = argv[optind++]; file[1] = optind < argc ? argv[optind++] : "-"; - for (f = 0; f < 2 && optind < argc; f++) + for (int f = 0; f < 2 && optind < argc; f++) { char *arg = argv[optind++]; specify_ignore_initial (f, &arg, 0); @@ -277,33 +281,29 @@ main (int argc, char **argv) if (optind < argc) try_help ("extra operand '%s'", argv[optind]); - for (f = 0; f < 2; f++) + for (int f = 0; f < 2; f++) { - /* If file[1] is "-", treat it first; this avoids a misdiagnostic if - stdin is closed and opening file[0] yields file descriptor 0. */ - int f1 = f ^ (STREQ (file[1], "-")); - /* Two files with the same name and offset are identical. But wait until we open the file once, for proper diagnostics. */ if (f && ignore_initial[0] == ignore_initial[1] && file_name_cmp (file[0], file[1]) == 0) return EXIT_SUCCESS; - if (STREQ (file[f1], "-")) + if (STREQ (file[f], "-")) { - file_desc[f1] = STDIN_FILENO; + file_desc[f] = STDIN_FILENO; if (O_BINARY && ! isatty (STDIN_FILENO)) set_binary_mode (STDIN_FILENO, O_BINARY); } else - file_desc[f1] = open (file[f1], O_RDONLY | O_BINARY, 0); + file_desc[f] = open (file[f], O_RDONLY | O_BINARY, 0); - if (file_desc[f1] < 0 || fstat (file_desc[f1], stat_buf + f1) != 0) + if (file_desc[f] < 0 || fstat (file_desc[f], stat_buf + f) != 0) { - if (file_desc[f1] < 0 && comparison_type == type_status) + if (file_desc[f] < 0 && comparison_type == type_status) exit (EXIT_TROUBLE); else - die (EXIT_TROUBLE, errno, "%s", file[f1]); + die (EXIT_TROUBLE, errno, "%s", file[f]); } } @@ -361,7 +361,7 @@ main (int argc, char **argv) exit_status = cmp (); - for (f = 0; f < 2; f++) + for (int f = 0; f < 2; f++) if (close (file_desc[f]) != 0) die (EXIT_TROUBLE, errno, "%s", file[f]); if (exit_status != EXIT_SUCCESS && comparison_type < type_no_stdout) diff --git a/src/diff.c b/src/diff.c index a5ec7f4..d54782c 100644 --- a/src/diff.c +++ b/src/diff.c @@ -300,7 +300,7 @@ main (int argc, char **argv) presume_output_tty = false; int stdopen_errno = stdopen (); if (stdopen_errno != 0) - error (EXIT_TROUBLE, stdopen_errno, "standard file descriptors"); + error (EXIT_TROUBLE, stdopen_errno, _("standard file descriptors")); /* Decode the options. */ diff --git a/src/diff3.c b/src/diff3.c index c7b2840..36bf4a6 100644 --- a/src/diff3.c +++ b/src/diff3.c @@ -30,6 +30,7 @@ #include <file-type.h> #include <getopt.h> #include <progname.h> +#include <stdopen.h> #include <system-quote.h> #include <version-etc.h> #include <xalloc.h> @@ -272,6 +273,9 @@ main (int argc, char **argv) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); c_stack_action (0); + int stdopen_errno = stdopen (); + if (stdopen_errno != 0) + error (EXIT_TROUBLE, stdopen_errno, _("standard file descriptors")); while ((c = getopt_long (argc, argv, "aeimvx3AEL:TX", longopts, 0)) != -1) { diff --git a/src/sdiff.c b/src/sdiff.c index 25ce3fe..bbbe16c 100644 --- a/src/sdiff.c +++ b/src/sdiff.c @@ -32,6 +32,7 @@ #include <file-type.h> #include <getopt.h> #include <progname.h> +#include <stdopen.h> #include <system-quote.h> #include <version-etc.h> #include <xalloc.h> @@ -455,6 +456,9 @@ main (int argc, char *argv[]) bindtextdomain (PACKAGE, LOCALEDIR); textdomain (PACKAGE); c_stack_action (cleanup); + int stdopen_errno = stdopen (); + if (stdopen_errno != 0) + error (EXIT_TROUBLE, stdopen_errno, _("standard file descriptors")); prog = getenv ("EDITOR"); if (prog) -- 2.17.1 --------------34E9D1D1F5454BCC79E8AA56--
bug-diffutils@HIDDEN
:bug#33965
; Package diffutils
.
Full text available.Received: (at 33965) by debbugs.gnu.org; 5 Jan 2019 09:44:35 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jan 05 04:44:35 2019 Received: from localhost ([127.0.0.1]:47245 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1gfiVP-0000ci-EV for submit <at> debbugs.gnu.org; Sat, 05 Jan 2019 04:44:35 -0500 Received: from mo4-p01-ob.smtp.rzone.de ([85.215.255.52]:35525) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <bruno@HIDDEN>) id 1gfiVM-0000cW-Qo for 33965 <at> debbugs.gnu.org; Sat, 05 Jan 2019 04:44:33 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1546681471; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=BliwxpfNtROna93LCjH0ZPiEMNfrDkGbPhJVfB2NHhI=; b=i3PvrxvOlCw/1rX9sEDhFLT/sqfHKoe7wRQq0IY7rVvGLU87YRc+a2gdSSJ7kYIEwg zsHDojYaMuNQvzvaECSYF1F8lYdmTguNEb5uUUSV+1nmRDar0YgT5j6zE1o0/uIJjNMA /AXCC808N65qDVl399RTyV0Y4R5XtTWw43DbpDXGeyvlpcJ1MdzvvcjfBK+jYllvCU50 yvI6rwDxfTmJsW4aZB3D/E1fPjqb0OSWRsRul0Km1JQs3aBW3eNnFy65+eIm0gltyL9b kjBbntDV4qY0L9FPahqz2LLp7Lxt3eJnV2HZk8dHO5OYWb5sQjEB2cd+q0JzE+mTTAjg xWRQ== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGKf2y/s=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 44.9 DYNA|AUTH) with ESMTPSA id v0a34ev059iI5mv (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Sat, 5 Jan 2019 10:44:18 +0100 (CET) From: Bruno Haible <bruno@HIDDEN> To: Paul Eggert <eggert@HIDDEN> Subject: Re: bug#33965: handling of closed file descriptors Date: Sat, 05 Jan 2019 10:44:17 +0100 Message-ID: <2095398.ToFATaR5yE@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <d4d28d01-5433-4d39-a723-c41ae9edb1cb@HIDDEN> References: <6639990.yRvKeTYcJc@omega> <1742217.p5sQxCVaLy@omega> <d4d28d01-5433-4d39-a723-c41ae9edb1cb@HIDDEN> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 33965 Cc: 33965 <at> debbugs.gnu.org, bug-gnulib@HIDDEN, jim@HIDDEN X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) [CCing bug-gnulib. This is a followup to https://debbugs.gnu.org/cgi/bugreport.cgi?bug=33965 ] Hi Paul, > The feature is not portable to POSIX > platforms. Besides, I doubt whether anybody is using the feature anyway. OK, if you question the "feature" as a whole, then I'd say: * Users don't *need* the "feature", in the sense that: - The normal way of invoking a program is by providing arguments and standard input/output streams. Users who want to invoke a program are not actively looking for this contorted way to invoke a program. - For most programs, equivalent functionality to the "feature" is available by passing an empty string, a reference to an empty file, or /dev/null as argument. If a program exists for which the equivalent functionality is not available through the normal way of invocation, the developers should better add it. * But it's a security risk that a program can be invoked in ways in which it was surely never tested. Anything can happen then - from overwriting precious files of the user to endless loops. * Therefore if you want to take out the "feature", you still have to think about how to mitigate the security risks. > Although the HP-UX solution to this problem may not be best, it's better > than the traditional behavior as it is a simple change to the kernel > that fixes the issue for all applications, as opposed to the > more-complicated dances we do in openat-safer and friends. Given - the prevalent "worse is better" attitude, - the "never break userland behaviour that programs may rely upon" principle of the Linux kernel community, - the fact that the glibc people looked at the problem and used the HP-UX solution only for setuid programs, I predict that this "simple change to the kernel" will not make it into the majority of the operating systems in the next 10 years. (But you could start lobbying for it among the OpenBSD people. They would be the most likely to adopt it, I guess.) In the mean time, the remaining options I can see are: (a) Keep using the *-safer Gnulib modules. (b) Introduce a sanity_check_file_descriptors() function that all programs can invoke right at the beginning of main(), and that exits with an exit code if it detects a closed fd. void sanity_check_file_descriptors (void) { int fd; for (fd = 0; fd <= 2; fd++) if (fcntl (fd, F_GETFD, NULL) < 0 && errno == EBADF) exit (125); } On platforms like HP-UX, this code would not cause an exit, but the exec() call has already provided substitutes for the closed fds; this mitigates the security risks. I would propose exit code 125, since 127 and 126 are already taken [1]. (b) surely is simpler than (a). Bruno [1] http://tldp.org/LDP/abs/html/exitcodes.html
bug-diffutils@HIDDEN
:bug#33965
; Package diffutils
.
Full text available.Received: (at 33965) by debbugs.gnu.org; 5 Jan 2019 09:41:30 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Sat Jan 05 04:41:30 2019 Received: from localhost ([127.0.0.1]:47241 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1gfiSQ-0000YA-0U for submit <at> debbugs.gnu.org; Sat, 05 Jan 2019 04:41:30 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.22]:18895) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <bruno@HIDDEN>) id 1gfiSN-0000Xz-6r for 33965 <at> debbugs.gnu.org; Sat, 05 Jan 2019 04:41:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1546681285; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=yRwiNJEBgxBTEMLPMs3FMTpZgs78C0PCFq/AdqOFj+g=; b=UJRp/M1nR5Rkjn5nHM+Dv0B4mbYfZyw932kGM0aRGkNHUYTY2djIFb8wzRq2N/cH+c Ey6LffW3AMMBV4m25SKZVQ4NWkQgO+I34hklE/15FtNmTMFlAW7nZFWkjbJ2ZYP/TYhe NDjrZQpJ1K6Jov9NBbpmUaZXNW45tK+02PBhzNm5f6NohsUYZwZtu2BKMbu/5tgKjp7T DBR5z9NPta0JBKCNR9ysYYx5Egvm8Khhrt+YD/4bKflP55qkOvDmj2HL7rt/P4Gl+iRD dEk/ZpHwtb0gTrXDlWIdZMG8TKlt8zWNXFdcTuPvLQgwYP2iFsKmN/hSYblFBzhX6meK hkiA== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGKf2y/s=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 44.9 DYNA|AUTH) with ESMTPSA id v0a34ev059fK5mW (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Sat, 5 Jan 2019 10:41:20 +0100 (CET) From: Bruno Haible <bruno@HIDDEN> To: Paul Eggert <eggert@HIDDEN> Subject: Re: [bug-diffutils] bug#33965: handling of closed file descriptors Date: Sat, 05 Jan 2019 10:41:20 +0100 Message-ID: <1637429.tjGFVHuugb@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <d4d28d01-5433-4d39-a723-c41ae9edb1cb@HIDDEN> References: <6639990.yRvKeTYcJc@omega> <1742217.p5sQxCVaLy@omega> <d4d28d01-5433-4d39-a723-c41ae9edb1cb@HIDDEN> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Score: -0.0 (/) X-Debbugs-Envelope-To: 33965 Cc: 33965 <at> debbugs.gnu.org, jim@HIDDEN X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) > > It is like saying that it would be OK for a program, when interrupted > > through Ctrl-Z and restarted through 'fg', to stop processing and exit > > with a message "read: Interrupted system call". ... > > POSIX allowed the kernel to return from a > > read() system call with errno = EINTR. But users don't want this. So it > > was seen as a bug in the program, and fixed. > > If by "users" you mean "programs that make system calls" By "users don't want this" I meant: Users don't want programs to terminate with an error message "read: Interrupted system call", just because they used the job control features of the shell. Bruno
bug-diffutils@HIDDEN
:bug#33965
; Package diffutils
.
Full text available.Received: (at 33965) by debbugs.gnu.org; 5 Jan 2019 00:33:00 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 04 19:33:00 2019 Received: from localhost ([127.0.0.1]:47131 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1gfZtc-0001eY-5j for submit <at> debbugs.gnu.org; Fri, 04 Jan 2019 19:33:00 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:57324) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <eggert@HIDDEN>) id 1gfZta-0001eI-Ak for 33965 <at> debbugs.gnu.org; Fri, 04 Jan 2019 19:32:59 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 1DF0B160F47; Fri, 4 Jan 2019 16:32:52 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id izH4715T2GGL; Fri, 4 Jan 2019 16:32:51 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 41AD5160F48; Fri, 4 Jan 2019 16:32:51 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id dUPc5aBw-bq7; Fri, 4 Jan 2019 16:32:51 -0800 (PST) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 252C9160F46; Fri, 4 Jan 2019 16:32:51 -0800 (PST) Subject: Re: [bug-diffutils] bug#33965: handling of closed file descriptors To: Bruno Haible <bruno@HIDDEN> References: <6639990.yRvKeTYcJc@omega> <CA+8g5KEe5CDHBKFqUgEUTV6saK2XDSn2_SVPQp_U53SRMABDWA@HIDDEN> <5640e0dc-e97f-fc77-0087-9dbc8c506dc5@HIDDEN> <1742217.p5sQxCVaLy@omega> From: Paul Eggert <eggert@HIDDEN> Openpgp: preference=signencrypt Autocrypt: addr=eggert@HIDDEN; prefer-encrypt=mutual; keydata= xsFNBEyAcmQBEADAAyH2xoTu7ppG5D3a8FMZEon74dCvc4+q1XA2J2tBy2pwaTqfhpxxdGA9 Jj50UJ3PD4bSUEgN8tLZ0san47l5XTAFLi2456ciSl5m8sKaHlGdt9XmAAtmXqeZVIYX/UFS 96fDzf4xhEmm/y7LbYEPQdUdxu47xA5KhTYp5bltF3WYDz1Ygd7gx07Auwp7iw7eNvnoDTAl KAl8KYDZzbDNCQGEbpY3efZIvPdeI+FWQN4W+kghy+P6au6PrIIhYraeua7XDdb2LS1en3Ss mE3QjqfRqI/A2ue8JMwsvXe/WK38Ezs6x74iTaqI3AFH6ilAhDqpMnd/msSESNFt76DiO1ZK QMr9amVPknjfPmJISqdhgB1DlEdw34sROf6V8mZw0xfqT6PKE46LcFefzs0kbg4GORf8vjG2 Sf1tk5eU8MBiyN/bZ03bKNjNYMpODDQQwuP84kYLkX2wBxxMAhBxwbDVZudzxDZJ1C2VXujC OJVxq2kljBM9ETYuUGqd75AW2LXrLw6+MuIsHFAYAgRr7+KcwDgBAfwhPBYX34nSSiHlmLC+ KaHLeCLF5ZI2vKm3HEeCTtlOg7xZEONgwzL+fdKo+D6SoC8RRxJKs8a3sVfI4t6CnrQzvJbB n6gxdgCu5i29J1QCYrCYvql2UyFPAK+do99/1jOXT4m2836j1wARAQABzSBQYXVsIEVnZ2Vy dCA8ZWdnZXJ0QGNzLnVjbGEuZWR1PsLBfgQTAQIAKAUCTIByZAIbAwUJEswDAAYLCQgHAwIG FQgCCQoLBBYCAwECHgECF4AACgkQ7ZfpDmKqfjRRGw/+Ij03dhYfYl/gXVRiuzV1gGrbHk+t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41ae9edb1cb@HIDDEN> Date: Fri, 4 Jan 2019 16:32:50 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <1742217.p5sQxCVaLy@omega> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 33965 Cc: 33965 <at> debbugs.gnu.org, jim@HIDDEN X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) On 1/4/19 3:30 PM, Bruno Haible wrote: > >> the test case assumes more about the shell's "<&-" >> construct than what POSIX requires. > It is like saying that it would be OK for a program, when interrupted > through Ctrl-Z and restarted through 'fg', to stop processing and exit > with a message "read: Interrupted system call". I don't see the analogy at all. Currently diffutils has a test shell script that is not portable POSIX code. Although we've worked around the problem with HP-UX by hacking on 'diff' itself, there are plausible POSIX platforms where our current hack will not work. It's not unreasonable to expect that test scripts should limit themselves to POSIX features so that they are as portable as reasonably possible. > POSIX allowed the kernel to return from a > read() system call with errno = EINTR. But users don't want this. So it > was seen as a bug in the program, and fixed. If by "users" you mean "programs that make system calls", then many users *do* want that. Certainly Emacs does, and I imagine many other programs do too. If you meant something else by "users" then I'm not sure I'm following the analogy. For the stdin-is-closed situation, the users and developers of many (I would say most) applications do not want 'open' to hijack stdin. Although the HP-UX solution to this problem may not be best, it's better than the traditional behavior as it is a simple change to the kernel that fixes the issue for all applications, as opposed to the more-complicated dances we do in openat-safer and friends. After thinking about this a bit more, the message that I'm getting from all this is that we should change diffutils to no longer rely on the "feature" that stdin is closed, and remove the test cases that attempt to test for this "feature". The feature is not portable to POSIX platforms. Besides, I doubt whether anybody is using the feature anyway. I put the feature in many years ago, so I can take the blame for introducing the misguided feature and the responsibility for taking it out.
bug-diffutils@HIDDEN
:bug#33965
; Package diffutils
.
Full text available.Received: (at 33965) by debbugs.gnu.org; 4 Jan 2019 23:30:50 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 04 18:30:49 2019 Received: from localhost ([127.0.0.1]:47116 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1gfYvR-0008Uf-JJ for submit <at> debbugs.gnu.org; Fri, 04 Jan 2019 18:30:49 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.218]:33126) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <bruno@HIDDEN>) id 1gfYvN-0008UQ-Mu for 33965 <at> debbugs.gnu.org; Fri, 04 Jan 2019 18:30:47 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1546644644; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=YKY71bg2K+aRo73JF+nqXalqTdfCWKnzxQR2orgt7zw=; b=LQvys7U8FFO6Z46IU7+bgokP4hDrXUiFHBq57kkQ/aPMiZuts+tnyYnSpVFw0lzFLn lkYTEQHUG0RTjWPHiqR48AMJUrC6f3eq1cNlC//GR1KefkTnuP0g0oSQfBZhV9i1gTUl gzN0zsesusSRb6sb17J161G6WPGjVG9DbLw/HPS8K0tfdOnXSmRulLl///C15BH+Jm4j pMZ0I1J+HYAWuwT5W+AbCJHjZYP71Pm6rGKNWXkxuBdHXFoFGINlPEhuOcXyun07QIxL Kg7hRnkvB5UGP60wNFQdddxsWKCVIhqO5++HAZMujEj+HIq4EfSPLDD2etCG17auTTqo HoBw== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGKf2y/s=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 44.9 DYNA|AUTH) with ESMTPSA id v0a34ev04NUe45p (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Sat, 5 Jan 2019 00:30:40 +0100 (CET) From: Bruno Haible <bruno@HIDDEN> To: Paul Eggert <eggert@HIDDEN> Subject: Re: [bug-diffutils] bug#33965: handling of closed file descriptors Date: Sat, 05 Jan 2019 00:30:39 +0100 Message-ID: <1742217.p5sQxCVaLy@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <5640e0dc-e97f-fc77-0087-9dbc8c506dc5@HIDDEN> References: <6639990.yRvKeTYcJc@omega> <CA+8g5KEe5CDHBKFqUgEUTV6saK2XDSn2_SVPQp_U53SRMABDWA@HIDDEN> <5640e0dc-e97f-fc77-0087-9dbc8c506dc5@HIDDEN> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-Spam-Score: -0.7 (/) X-Debbugs-Envelope-To: 33965 Cc: 33965 <at> debbugs.gnu.org, jim@HIDDEN X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.7 (-) Sorry, Paul, but I have to vehemently disagree here. You are mixing two different questions: (A) What is the best behaviour for a kernel? (B) What is the best behaviour for a program? About (A): > We should encourage platforms like HP-UX that try to work around the > trouble The question is: Is it better for a kernel to be minimalist, hence exec() does nothing special with the file descriptors? Or is it better for a kernel to avoid pitfalls for programs, by protecting the first 3 file descriptors? It is similar to the question: In the case of a signal delivery, should a read() or write() system call return with a partial result or EINTR, or should the kernel protect the programs from this knowledge and programming overhead? This question was extensively discussed under the title "worse is better", see https://www.jwz.org/doc/worse-is-better.html https://en.wikipedia.org/wiki/Worse_is_better I have no personal opinion on this question. About (B): > I'd rather think of this as a bug in the test case, not a bug in 'diff'. Here I disagree. * The majority of the uses of 'diff' and coreutils is through shell scripts. * <&- and >&- are POSIX-standardized syntaxes in shell scripts for a long time. * It is a goal to make the same shell script work the same way on different platforms. The user gains nothing if you tell them "your shell script works differently on Linux than on HP-UX because the kernel behaves slightly differently". * Therefore the gnulib modules dirent-safer fcntl-safer fopen-safer freopen-safer openat-safer pipe2-safer popen-safer stdlib-safer tmpfile-safer unistd-safer serve a good purpose. They make programs running on Linux and programs running on HP-UX behave more similarly, which is a good thing. > This is because the test case assumes more about the shell's "<&-" > construct than what POSIX requires. It is like saying that it would be OK for a program, when interrupted through Ctrl-Z and restarted through 'fg', to stop processing and exit with a message "read: Interrupted system call". That's indeed how some programs behaved around 1992: POSIX allowed the kernel to return from a read() system call with errno = EINTR. But users don't want this. So it was seen as a bug in the program, and fixed. Same here. Bruno
bug-diffutils@HIDDEN
:bug#33965
; Package diffutils
.
Full text available.Debbugs Internal Request <help-debbugs@HIDDEN>
to internal_control <at> debbugs.gnu.org
.
Full text available.Received: (at 33965) by debbugs.gnu.org; 4 Jan 2019 22:42:32 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 04 17:42:32 2019 Received: from localhost ([127.0.0.1]:47102 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1gfYAi-0005EO-2d for submit <at> debbugs.gnu.org; Fri, 04 Jan 2019 17:42:32 -0500 Received: from zimbra.cs.ucla.edu ([131.179.128.68]:39778) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <eggert@HIDDEN>) id 1gfYAf-0005E8-2k for 33965 <at> debbugs.gnu.org; Fri, 04 Jan 2019 17:42:30 -0500 Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id E7BAD160F5B; Fri, 4 Jan 2019 14:42:22 -0800 (PST) Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 4lGmXO5PkIEK; Fri, 4 Jan 2019 14:42:22 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id EBBAC160F5C; Fri, 4 Jan 2019 14:42:21 -0800 (PST) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id lhaMMLX6czO2; Fri, 4 Jan 2019 14:42:21 -0800 (PST) Received: from Penguin.CS.UCLA.EDU (Penguin.CS.UCLA.EDU [131.179.64.200]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id CB8C1160F57; Fri, 4 Jan 2019 14:42:21 -0800 (PST) From: Paul Eggert <eggert@HIDDEN> Subject: [bug-diffutils] bug#33965: bug#33965: handling of closed file descriptors To: 33965 <at> debbugs.gnu.org, jim@HIDDEN, bruno@HIDDEN References: <6639990.yRvKeTYcJc@omega> <CA+8g5KEe5CDHBKFqUgEUTV6saK2XDSn2_SVPQp_U53SRMABDWA@HIDDEN> Openpgp: preference=signencrypt Autocrypt: addr=eggert@HIDDEN; prefer-encrypt=mutual; keydata= xsFNBEyAcmQBEADAAyH2xoTu7ppG5D3a8FMZEon74dCvc4+q1XA2J2tBy2pwaTqfhpxxdGA9 Jj50UJ3PD4bSUEgN8tLZ0san47l5XTAFLi2456ciSl5m8sKaHlGdt9XmAAtmXqeZVIYX/UFS 96fDzf4xhEmm/y7LbYEPQdUdxu47xA5KhTYp5bltF3WYDz1Ygd7gx07Auwp7iw7eNvnoDTAl KAl8KYDZzbDNCQGEbpY3efZIvPdeI+FWQN4W+kghy+P6au6PrIIhYraeua7XDdb2LS1en3Ss mE3QjqfRqI/A2ue8JMwsvXe/WK38Ezs6x74iTaqI3AFH6ilAhDqpMnd/msSESNFt76DiO1ZK QMr9amVPknjfPmJISqdhgB1DlEdw34sROf6V8mZw0xfqT6PKE46LcFefzs0kbg4GORf8vjG2 Sf1tk5eU8MBiyN/bZ03bKNjNYMpODDQQwuP84kYLkX2wBxxMAhBxwbDVZudzxDZJ1C2VXujC OJVxq2kljBM9ETYuUGqd75AW2LXrLw6+MuIsHFAYAgRr7+KcwDgBAfwhPBYX34nSSiHlmLC+ KaHLeCLF5ZI2vKm3HEeCTtlOg7xZEONgwzL+fdKo+D6SoC8RRxJKs8a3sVfI4t6CnrQzvJbB n6gxdgCu5i29J1QCYrCYvql2UyFPAK+do99/1jOXT4m2836j1wARAQABzSBQYXVsIEVnZ2Vy dCA8ZWdnZXJ0QGNzLnVjbGEu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0 q5H/T6a7t5mPkbzSrOLSo4puj+IToNjYyYIDBWzhlA19avOa+rvUjmHtD3sFN7cXWtkGoi8b uNcby4U= Organization: UCLA Computer Science Department Message-ID: <5640e0dc-e97f-fc77-0087-9dbc8c506dc5@HIDDEN> Date: Fri, 4 Jan 2019 14:42:21 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <CA+8g5KEe5CDHBKFqUgEUTV6saK2XDSn2_SVPQp_U53SRMABDWA@HIDDEN> Content-Type: multipart/mixed; boundary="------------4C5C8295E10957DE69AEE802" Content-Language: en-US X-Spam-Score: -2.3 (--) X-Debbugs-Envelope-To: 33965 X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -3.3 (---) This is a multi-part message in MIME format. --------------4C5C8295E10957DE69AEE802 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit I'd rather think of this as a bug in the test case, not a bug in 'diff'. This is because the test case assumes more about the shell's "<&-" construct than what POSIX requires. The bigger picture here is that invoking programs with stdin closed is trouble, and although Gnulib provides several modules to work around the trouble these modules are a hassle and many applications don't use them. We should encourage platforms like HP-UX that try to work around the trouble, instead of having diffutils attempt to simulate the traditional but inferior exec semantics. Although the Linux kernel currently implements the traditional semantics, in this particular case I think I'd rather have diffutils adjust to what the platform provides, rather than attempt to simulate Linux behavior even on non-Linux kernels. So I propose the attached further patch. --------------4C5C8295E10957DE69AEE802 Content-Type: text/plain; charset=UTF-8; name="0001-diff-move-HP-UX-workaround-into-test-case.txt" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="0001-diff-move-HP-UX-workaround-into-test-case.txt" RnJvbSBmZDNjOTc4ZGQ5Mjk0NTNkZmJlMGJmOGVhYTkyOTUzMjEyNzRiYTMzIE1vbiBTZXAg MTcgMDA6MDA6MDAgMjAwMQpGcm9tOiBQYXVsIEVnZ2VydCA8ZWdnZXJ0QGNzLnVjbGEuZWR1 PgpEYXRlOiBGcmksIDQgSmFuIDIwMTkgMTM6NDM6NTUgLTA4MDAKU3ViamVjdDogW1BBVENI XSBkaWZmOiBtb3ZlIEhQLVVYIHdvcmthcm91bmQgaW50byB0ZXN0IGNhc2UKTUlNRS1WZXJz aW9uOiAxLjAKQ29udGVudC1UeXBlOiB0ZXh0L3BsYWluOyBjaGFyc2V0PVVURi04CkNvbnRl bnQtVHJhbnNmZXItRW5jb2Rpbmc6IDhiaXQKCiogc3JjL2RpZmYuYyAoY29tcGFyZV9maWxl cykgW19faHB1eF06IFJlbW92ZSByZWNlbnRseS1pbnRyb2R1Y2VkCnNwZWNpYWwgY2FzZSBm b3IgSFAtVVggZXhlYyB3aXRoIHN0ZGluIGNsb3NlZC4KKiB0ZXN0cy9uZXctZmlsZTogRG9u 4oCZdCBhc3N1bWUgc3RkaW4gc3RheXMgY2xvc2VkIGFmdGVyIGEKc3VjY2Vzc2Z1bCBleGVj LCBhcyBQT1NJWCBkb2VzbuKAmXQgZ3VhcmFudGVlIHRoaXMgYW5kIGl0IGlzCm5vdCB0cnVl IG9uIEhQLVVYLgotLS0KIHNyYy9kaWZmLmMgICAgIHwgIDcgLS0tLS0tLQogdGV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jIwLjEKCg== --------------4C5C8295E10957DE69AEE802--
bug-diffutils@HIDDEN
:bug#33965
; Package diffutils
.
Full text available.Received: (at 33965-done) by debbugs.gnu.org; 4 Jan 2019 06:15:39 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Fri Jan 04 01:15:39 2019 Received: from localhost ([127.0.0.1]:46164 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1gfIlf-0007sB-14 for submit <at> debbugs.gnu.org; Fri, 04 Jan 2019 01:15:39 -0500 Received: from mail-wm1-f42.google.com ([209.85.128.42]:40473) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <meyering@HIDDEN>) id 1gfIld-0007lo-3k for 33965-done <at> debbugs.gnu.org; Fri, 04 Jan 2019 01:15:37 -0500 Received: by mail-wm1-f42.google.com with SMTP id f188so225531wmf.5 for <33965-done <at> debbugs.gnu.org>; Thu, 03 Jan 2019 22:15:37 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=a4MlZlzjJ5MGW9dldKf2Oc79zPcg/IGWqtyl84K3mjI=; b=Vgz2z0zEkQSuXqcudLs5E/BRqBNHQgejih9Ffa24lwXtNFKiZ8fb1sMVAVg6zoKMl7 eeONfe8SRUZJctNL4VLzI31q7MmiiFUWkCC8oeKuTuO4A330jrZrOvFpbu5MT2VRGhR0 w9VetFbBlFa+jpjy15Jlr+G9GiQMnlPb/q1kjfLUftU83QBAOMSXXzz0w5BwtBv2qK1F 2fx8gh/7qC3o7qR9lUEcR+bHAhgU7QjCUJ3lW11nI2G2vtf84xoEwAWJTltr+fCjjlu3 OnlzsPpmQb9CL9lJyj4UL6qIPvlUXvXfvSxNkTsAMxo3idO139qB2cpFWGxkb0lFGJMV 9LMw== X-Gm-Message-State: AJcUukfW+sfD0+C8J5uUvE2Ws53iEqzEwVvph/iuptlW5sZC71yoICzS 68oPptSPtroguXjwGNVj3My8VleY22peHYE+zPA= X-Google-Smtp-Source: ALg8bN4nBAcsKqeVr8UOl8K8nFBi4mgl9sUySVCy3Al7Z9ZpfNFZ6cxYxfnLxp8hnGfzRD/mqQN4hNlTLGBodTMJ4hM= X-Received: by 2002:a1c:4346:: with SMTP id q67mr347065wma.114.1546582531343; Thu, 03 Jan 2019 22:15:31 -0800 (PST) MIME-Version: 1.0 References: <6639990.yRvKeTYcJc@omega> In-Reply-To: <6639990.yRvKeTYcJc@omega> From: Jim Meyering <jim@HIDDEN> Date: Thu, 3 Jan 2019 22:15:19 -0800 Message-ID: <CA+8g5KEe5CDHBKFqUgEUTV6saK2XDSn2_SVPQp_U53SRMABDWA@HIDDEN> Subject: Re: [bug-diffutils] bug#33965: handling of closed file descriptors To: Bruno Haible <bruno@HIDDEN> Content-Type: text/plain; charset="UTF-8" X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: 33965-done Cc: 33965-done <at> debbugs.gnu.org X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) On Thu, Jan 3, 2019 at 11:43 AM Bruno Haible <bruno@HIDDEN> wrote: > > There is a problem with the handling of closed file descriptors > in diff-3.7: As mentioned in [1], the 'new-file' test fails on HP-UX. > An investigation [2] shows that different coding techniques are needed, > depending on the desired outcome for closed file descriptors. > > This patch uses a variant of (A) from [2]. Namely, the result of fcntl > can apparently be used to distinguish the substitute file descriptor > stuffed in by exec() from a regular open("/dev/null",O_RDONLY). > > [1] https://lists.gnu.org/archive/html/diffutils-devel/2018-12/msg00019.html > [2] https://lists.gnu.org/archive/html/bug-gnulib/2019-01/msg00012.html Thank you. I have just pushed that with one tweak to the log message: s/parent parent/parent/.
Bruno Haible <bruno@HIDDEN>
:Jim Meyering <jim@HIDDEN>
:Received: (at submit) by debbugs.gnu.org; 3 Jan 2019 20:02:23 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jan 03 15:02:23 2019 Received: from localhost ([127.0.0.1]:45983 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1gf9CB-0007Bs-0C for submit <at> debbugs.gnu.org; Thu, 03 Jan 2019 15:02:23 -0500 Received: from eggs.gnu.org ([208.118.235.92]:60193) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <bruno@HIDDEN>) id 1gf9C8-0007Bk-AY for submit <at> debbugs.gnu.org; Thu, 03 Jan 2019 15:02:21 -0500 Received: from lists.gnu.org ([208.118.235.17]:56379) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <bruno@HIDDEN>) id 1gf9C8-0005eT-5L for submit <at> debbugs.gnu.org; Thu, 03 Jan 2019 15:02:20 -0500 Received: from eggs.gnu.org ([208.118.235.92]:59000) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <bruno@HIDDEN>) id 1gf9C7-0001rP-E5 for bug-diffutils@HIDDEN; Thu, 03 Jan 2019 15:02:20 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <bruno@HIDDEN>) id 1gf9C6-0005da-N6 for bug-diffutils@HIDDEN; Thu, 03 Jan 2019 15:02:19 -0500 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::6]:29686) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <bruno@HIDDEN>) id 1gf9C6-0005cd-6K for bug-diffutils@HIDDEN; Thu, 03 Jan 2019 15:02:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1546545736; s=strato-dkim-0002; d=clisp.org; h=References:In-Reply-To:Message-ID:Date:Subject:To:From: X-RZG-CLASS-ID:X-RZG-AUTH:From:Subject:Sender; bh=79sr3y1MmGIeyUSoORFJ9lk3S+H8Fvt2HPsNavAq95Q=; b=N1EVZUB2ksQt7EGQPtdH0J4YqBf6OBioxAMAtQ4RC46UnVyjTttQE5bd0AfCrsxsbp 8g9/WAvqIo3m9/REGJu4ur+DU55lK9CK8ddAIX1Dbfw5s57UyEUB43bmqURJUSX7xftg xc1vGJ9VHeFTnTKN1fwCjdySWixbE34UaMviRsJRHIgsFeIwfcxOBrl/qUFm0glE5/Ya Nf/PAOHzNVmmYYGFt5y1G8zbON5ds6yhFFIMFS377NbVnunFZOmtBY8IooAZeZMYbjPl 4viNRO1VJURJNt+drG67FDGz6KaaLkhIlCWPL8J8Hbb+NCWToaDzw+ij7Y28tviCWPc2 KGag== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGKf2y/s=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 44.9 DYNA|AUTH) with ESMTPSA id k06e80v03K2GLKy (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 3 Jan 2019 21:02:16 +0100 (CET) From: Bruno Haible <bruno@HIDDEN> To: bug-diffutils@HIDDEN Subject: Re: handling of closed file descriptors Date: Thu, 03 Jan 2019 21:02:16 +0100 Message-ID: <64441865.ngSBGZCanV@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; ) In-Reply-To: <6639990.yRvKeTYcJc@omega> References: <6639990.yRvKeTYcJc@omega> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5300::6 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: -5.0 (-----) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -6.0 (------) I wrote: > the result of fcntl > can apparently be used to distinguish the substitute file descriptor > stuffed in by exec() from a regular open("/dev/null",O_RDONLY). Note that the code works for STDIN_FILENO, where fcntl(...) is 5 in one case and 0 in the other case, and we use FD_CLOEXEC = 1 to distinguish the two. For STDOUT_FILENO, fcntl(...) would be 5 in one case and 1 in the other case, and the flag which allows to distinguish the two cases (4) is not listed in <sys/fcntl.h>, therefore likely is a kernel-private flag. Bruno
bug-diffutils@HIDDEN
:bug#33965
; Package diffutils
.
Full text available.Received: (at submit) by debbugs.gnu.org; 3 Jan 2019 19:42:40 +0000 From debbugs-submit-bounces <at> debbugs.gnu.org Thu Jan 03 14:42:40 2019 Received: from localhost ([127.0.0.1]:45978 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <debbugs-submit-bounces <at> debbugs.gnu.org>) id 1gf8t6-0006gz-8f for submit <at> debbugs.gnu.org; Thu, 03 Jan 2019 14:42:40 -0500 Received: from eggsout.gnu.org ([209.51.188.92]:54525) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from <bruno@HIDDEN>) id 1gf8t3-0006gr-PG for submit <at> debbugs.gnu.org; Thu, 03 Jan 2019 14:42:38 -0500 Received: from lists.gnu.org ([208.118.235.17]:39561) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <bruno@HIDDEN>) id 1gf8t3-0002Ue-CC for submit <at> debbugs.gnu.org; Thu, 03 Jan 2019 14:42:37 -0500 Received: from eggs.gnu.org ([208.118.235.92]:54177) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from <bruno@HIDDEN>) id 1gf8t2-0005nI-8s for bug-diffutils@HIDDEN; Thu, 03 Jan 2019 14:42:37 -0500 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on eggs.gnu.org X-Spam-Level: X-Spam-Status: No, score=0.8 required=5.0 tests=BAYES_50 autolearn=disabled version=3.3.2 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from <bruno@HIDDEN>) id 1gf8t1-0002TS-7F for bug-diffutils@HIDDEN; Thu, 03 Jan 2019 14:42:36 -0500 Received: from mo6-p00-ob.smtp.rzone.de ([2a01:238:20a:202:5300::5]:27735) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from <bruno@HIDDEN>) id 1gf8t0-0002QG-Mf for bug-diffutils@HIDDEN; Thu, 03 Jan 2019 14:42:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1546544549; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:X-RZG-CLASS-ID:X-RZG-AUTH:From: Subject:Sender; bh=bbtcrI9mcFw+VGLtihe2kprsV78PlZcIxbhyEi0xrk8=; b=dvC87gTWLRV5DM3s3hnmaaj85eZUkbRsefLnZKY6nGarjgMaivaE4aNOhZjvyISUMz Xu5m2CrfQM0x73vp8Q6DdStWyJqu3ZF/r5/mkHjIPrcwKhxLbZuXHd0TFltC2Lt6PQTp aK2dKIjNGMtBQ9Gf9PNviCBRRxy4ctRzK4hrv7O8YKBWZIOs5k5ozNwZx1UGF+1mcIXd PTOGaOVL1WvnfYfJNtiGy5MjDj9+lr7ZKmFSUaAWYHpw4gtmb/JfNiPAoeh2McM1oR82 ve3FZOjc5G163K6M8bOjBF/bPNNdtTy7BA/qkfTgXFmG1xB3c4SgGTBVn/FRLnJX/3q4 DuVQ== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOGKf2y/s=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 44.9 DYNA|AUTH) with ESMTPSA id k06e80v03JgTLIm (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate); Thu, 3 Jan 2019 20:42:29 +0100 (CET) From: Bruno Haible <bruno@HIDDEN> To: bug-diffutils@HIDDEN Subject: handling of closed file descriptors Date: Thu, 03 Jan 2019 20:42:28 +0100 Message-ID: <6639990.yRvKeTYcJc@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-141-generic; KDE/5.18.0; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart8317215.dh2gXTNRMh" Content-Transfer-Encoding: 7Bit X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a01:238:20a:202:5300::5 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Spam-Score: 0.0 (/) X-Debbugs-Envelope-To: submit X-BeenThere: debbugs-submit <at> debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: <debbugs-submit.debbugs.gnu.org> List-Unsubscribe: <https://debbugs.gnu.org/cgi-bin/mailman/options/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=unsubscribe> List-Archive: <https://debbugs.gnu.org/cgi-bin/mailman/private/debbugs-submit/> List-Post: <mailto:debbugs-submit <at> debbugs.gnu.org> List-Help: <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=help> List-Subscribe: <https://debbugs.gnu.org/cgi-bin/mailman/listinfo/debbugs-submit>, <mailto:debbugs-submit-request <at> debbugs.gnu.org?subject=subscribe> Errors-To: debbugs-submit-bounces <at> debbugs.gnu.org Sender: "Debbugs-submit" <debbugs-submit-bounces <at> debbugs.gnu.org> X-Spam-Score: -1.0 (-) This is a multi-part message in MIME format. --nextPart8317215.dh2gXTNRMh Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" There is a problem with the handling of closed file descriptors in diff-3.7: As mentioned in [1], the 'new-file' test fails on HP-UX. An investigation [2] shows that different coding techniques are needed, depending on the desired outcome for closed file descriptors. This patch uses a variant of (A) from [2]. Namely, the result of fcntl can apparently be used to distinguish the substitute file descriptor stuffed in by exec() from a regular open("/dev/null",O_RDONLY). [1] https://lists.gnu.org/archive/html/diffutils-devel/2018-12/msg00019.html [2] https://lists.gnu.org/archive/html/bug-gnulib/2019-01/msg00012.html --nextPart8317215.dh2gXTNRMh Content-Disposition: attachment; filename="0001-Recognize-file-descriptors-closed-by-the-parent-proc.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-Recognize-file-descriptors-closed-by-the-parent-proc.patch" From 288ddc7c18c022f39233ca78e78e49e02833966c Mon Sep 17 00:00:00 2001 From: Bruno Haible <bruno@HIDDEN> Date: Thu, 3 Jan 2019 20:36:35 +0100 Subject: [PATCH] Recognize file descriptors closed by the parent process on HP-UX. * src/diff.c (compare_files): Use fcntl to distinguish a file descriptor closed by the parent parent process from a file descriptor that references /dev/null. --- src/diff.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/diff.c b/src/diff.c index 6e8c6be..2ed3ae5 100644 --- a/src/diff.c +++ b/src/diff.c @@ -1172,6 +1172,13 @@ compare_files (struct comparison const *parent, cmp.file[f].desc = STDIN_FILENO; if (binary && ! isatty (STDIN_FILENO)) set_binary_mode (STDIN_FILENO, O_BINARY); +#ifdef __hpux + /* Recognize file descriptors closed by the parent on HP-UX. */ + int flags = fcntl (STDIN_FILENO, F_GETFL, NULL); + if (flags >= 0 && (flags & FD_CLOEXEC) != 0) + cmp.file[f].desc = ERRNO_ENCODE (EBADF); + else +#endif if (fstat (STDIN_FILENO, &cmp.file[f].stat) != 0) cmp.file[f].desc = ERRNO_ENCODE (errno); else -- 2.7.4 --nextPart8317215.dh2gXTNRMh--
Bruno Haible <bruno@HIDDEN>
:bug-diffutils@HIDDEN
.
Full text available.bug-diffutils@HIDDEN
:bug#33965
; Package diffutils
.
Full text available.
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997 nCipher Corporation Ltd,
1994-97 Ian Jackson.