diff: remove unportable ‘diff -N - f <&-’ feature

* 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.
This commit is contained in:
Paul Eggert 2019-01-05 19:20:11 -08:00
parent 1104d02651
commit 2c9d956aac
5 changed files with 15 additions and 23 deletions

9
NEWS
View File

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

View File

@ -67,6 +67,7 @@ stat
stat-macros
stat-time
stdint
stdopen
strcase
strftime
strptime

View File

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

View File

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

View 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