From owner-dev-commits-src-all@freebsd.org Mon Feb 1 13:05:32 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id BF3BF528699; Mon, 1 Feb 2021 13:05:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4DTp8X0JYrz3MCD; Mon, 1 Feb 2021 13:05:32 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D44B61B765; Mon, 1 Feb 2021 13:05:31 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 111D5V0C026663; Mon, 1 Feb 2021 13:05:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 111D5VpX026662; Mon, 1 Feb 2021 13:05:31 GMT (envelope-from git) Date: Mon, 1 Feb 2021 13:05:31 GMT Message-Id: <202102011305.111D5VpX026662@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Baptiste Daroussin Subject: git: 3728c4d31495 - stable/13 - diff: fix incorrectly displaying files as duplicates MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: bapt X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 3728c4d3149553967532a97254737bdb2cd92417 Auto-Submitted: auto-generated X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Feb 2021 13:05:32 -0000 The branch stable/13 has been updated by bapt: URL: https://cgit.FreeBSD.org/src/commit/?id=3728c4d3149553967532a97254737bdb2cd92417 commit 3728c4d3149553967532a97254737bdb2cd92417 Author: Jamie Landeg-Jones AuthorDate: 2021-01-25 17:42:26 +0000 Commit: Baptiste Daroussin CommitDate: 2021-02-01 13:05:25 +0000 diff: fix incorrectly displaying files as duplicates When diff hits certain access errors, function diffreg() shows the error message, and then returns to the calling function, which calls print_status() with the return value. However, in these cases, the return value isn't changed from the initial default value of D_SAME. Normally, print_status() with a value of D_SAME does nothing, so this works out ok, however, if the "-s" flag is set, a message is displayed showing identicality: case D_SAME: if (sflag) printf("Files %s%s and %s%s are identical\n", path1, entry, path2, entry); break; This then produces such results as: % diff -s /COPYRIGHT /var/run/rpcbind.sock diff: /var/run/rpcbind.sock: Operation not supported Files /COPYRIGHT and /var/run/rpcbind.sock are identical % diff -s /COPYRIGHT /etc/master.passwd diff: /etc/master.passwd: Permission denied Files /COPYRIGHT and /etc/master.passwd are identical Create a D_ERROR status which is returned in such cases, and print_status() then deals with that status seperately from D_SAME PR: 252614 MFC after: 1 week (cherry picked from commit fefb3c46a80fdde6f307e73a2b5b5aed806df1ce) --- usr.bin/diff/diff.c | 2 ++ usr.bin/diff/diff.h | 1 + usr.bin/diff/diffreg.c | 5 +++++ 3 files changed, 8 insertions(+) diff --git a/usr.bin/diff/diff.c b/usr.bin/diff/diff.c index 0e46b96f9667..1bad6226f49d 100644 --- a/usr.bin/diff/diff.c +++ b/usr.bin/diff/diff.c @@ -511,6 +511,8 @@ print_status(int val, char *path1, char *path2, const char *entry) printf("File %s%s is not a regular file or directory and was skipped\n", path2, entry); break; + case D_ERROR: + break; } } diff --git a/usr.bin/diff/diff.h b/usr.bin/diff/diff.h index 30387610fc19..1974b5cc08d6 100644 --- a/usr.bin/diff/diff.h +++ b/usr.bin/diff/diff.h @@ -83,6 +83,7 @@ #define D_MISMATCH2 4 /* path1 was a file, path2 a dir */ #define D_SKIPPED1 5 /* path1 was a special file */ #define D_SKIPPED2 6 /* path2 was a special file */ +#define D_ERROR 7 /* A file access error occurred */ struct excludes { char *pattern; diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c index 7d2b20b43def..4e887ab27c7b 100644 --- a/usr.bin/diff/diffreg.c +++ b/usr.bin/diff/diffreg.c @@ -299,6 +299,7 @@ diffreg(char *file1, char *file2, int flags, int capsicum) if ((f1 = opentemp(file1)) == NULL || fstat(fileno(f1), &stb1) == -1) { warn("%s", file1); + rval = D_ERROR; status |= 2; goto closem; } @@ -309,6 +310,7 @@ diffreg(char *file1, char *file2, int flags, int capsicum) } if (f1 == NULL) { warn("%s", file1); + rval = D_ERROR; status |= 2; goto closem; } @@ -320,6 +322,7 @@ diffreg(char *file1, char *file2, int flags, int capsicum) if ((f2 = opentemp(file2)) == NULL || fstat(fileno(f2), &stb2) == -1) { warn("%s", file2); + rval = D_ERROR; status |= 2; goto closem; } @@ -330,6 +333,7 @@ diffreg(char *file1, char *file2, int flags, int capsicum) } if (f2 == NULL) { warn("%s", file2); + rval = D_ERROR; status |= 2; goto closem; } @@ -365,6 +369,7 @@ diffreg(char *file1, char *file2, int flags, int capsicum) break; default: /* error */ + rval = D_ERROR; status |= 2; goto closem; }