>From 2c9d956aacdfddbb87334c985cd995d75102f789 Mon Sep 17 00:00:00 2001 From: Paul Eggert 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 address@hidden does, and similarly @samp{diff -N - b} treats standard input -as empty if it is closed but @file{b} exists. address@hidden 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 #include #include +#include #include #include #include @@ -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