From owner-freebsd-bugs@FreeBSD.ORG Wed Jun 20 18:30:13 2012 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 154DA1065679 for ; Wed, 20 Jun 2012 18:30:13 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id DEE4A8FC1B for ; Wed, 20 Jun 2012 18:30:11 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.5/8.14.5) with ESMTP id q5KIUBSu043016 for ; Wed, 20 Jun 2012 18:30:11 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.5/8.14.5/Submit) id q5KIUBTT043010; Wed, 20 Jun 2012 18:30:11 GMT (envelope-from gnats) Resent-Date: Wed, 20 Jun 2012 18:30:11 GMT Resent-Message-Id: <201206201830.q5KIUBTT043010@freefall.freebsd.org> Resent-From: FreeBSD-gnats-submit@FreeBSD.org (GNATS Filer) Resent-To: freebsd-bugs@FreeBSD.org Resent-Reply-To: FreeBSD-gnats-submit@FreeBSD.org, Garrett Cooper Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BC699106564A for ; Wed, 20 Jun 2012 18:20:58 +0000 (UTC) (envelope-from nobody@FreeBSD.org) Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22]) by mx1.freebsd.org (Postfix) with ESMTP id 8DBF88FC18 for ; Wed, 20 Jun 2012 18:20:58 +0000 (UTC) Received: from red.freebsd.org (localhost [127.0.0.1]) by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q5KIKwIW013837 for ; Wed, 20 Jun 2012 18:20:58 GMT (envelope-from nobody@red.freebsd.org) Received: (from nobody@localhost) by red.freebsd.org (8.14.4/8.14.4/Submit) id q5KIKwOZ013836; Wed, 20 Jun 2012 18:20:58 GMT (envelope-from nobody) Message-Id: <201206201820.q5KIKwOZ013836@red.freebsd.org> Date: Wed, 20 Jun 2012 18:20:58 GMT From: Garrett Cooper To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-3.1 Cc: Subject: bin/169274: [patch] diff exit code always reports "trouble" when there are differences between 2 files X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 20 Jun 2012 18:30:13 -0000 >Number: 169274 >Category: bin >Synopsis: [patch] diff exit code always reports "trouble" when there are differences between 2 files >Confidential: no >Severity: serious >Priority: high >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Wed Jun 20 18:30:11 UTC 2012 >Closed-Date: >Last-Modified: >Originator: Garrett Cooper >Release: 9-STABLE >Organization: EMC Isilon >Environment: FreeBSD forza.west.isilon.com 9.0-STABLE FreeBSD 9.0-STABLE #0 r236977M: Tue Jun 12 17:38:29 PDT 2012 root@forza.west.isilon.com:/usr/obj/usr/src/sys/FORZA amd64 >Description: diff doesn't do the right thing according to the manpage differentiating errors from differences; from diff(1)... RETURN VALUE diff returns 0 if the files are identical or 1 if the files differ. If one or both of the files cannot be opened, then the return value is set to 2. Example: $ diff valid.output unittest.dip >/dev/null $ echo $? 2 $ The patch attached fixes this logic error and another inconsistency with "magic numbers": $ diff -q /usr/src/contrib/diff/src/diff.c /usr/src/contrib/diff/src/diff.c ; echo $? 0 $ diff -q /usr/src/contrib/diff/src/diff.c /usr/src/contrib/diff/src/diff.h ; echo $? Files /usr/src/contrib/diff/src/diff.c and /usr/src/contrib/diff/src/diff.h differ 1 $ diff -q /usr/src/contrib/diff/src/diff.c /usr/src/contrib/diff/src/diff.c~ ; echo $? diff: /usr/src/contrib/diff/src/diff.c~: No such file or directory 2 $ diff -N /usr/src/contrib/diff/src/diff.c /usr/src/contrib/diff/src/diff.c~ >/dev/null; echo $? 1 >How-To-Repeat: diff /usr/src/contrib/diff/src/diff.c /usr/src/contrib/diff/src/diff.h >/dev/null ec=$? if [ $ec -eq 1 ] then echo PASS else echo FAIL fi >Fix: Patch attached with submission follows: Index: contrib/diff/src/analyze.c =================================================================== --- contrib/diff/src/analyze.c (revision 237106) +++ contrib/diff/src/analyze.c (working copy) @@ -771,7 +771,7 @@ } /* If CHANGES, briefly report that two files differed. - Return 2 if trouble, CHANGES otherwise. */ + Returns CHANGES. */ static int briefly_report (int changes, struct file_data const filevec[]) { @@ -780,8 +780,7 @@ char const *label0 = file_label[0] ? file_label[0] : filevec[0].name; char const *label1 = file_label[1] ? file_label[1] : filevec[1].name; message ("Files %s and %s differ\n", label0, label1); - if (! brief) - changes = 2; + changes = 1; } return changes; Index: contrib/diff/src/diff.c =================================================================== --- contrib/diff/src/diff.c (revision 237106) +++ contrib/diff/src/diff.c (working copy) @@ -261,7 +261,7 @@ char *numend; /* Do our initializations. */ - exit_failure = 2; + exit_failure = EXIT_TROUBLE; initialize_main (&argc, &argv); program_name = argv[0]; setlocale (LC_ALL, ""); >Release-Note: >Audit-Trail: >Unformatted: