bin/169274: [patch] diff exit code always reports "trouble" when
there are differences between 2 files
Garrett Cooper
yanegomi at gmail.com
Wed Jun 20 18:30:13 UTC 2012
>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 at 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:
More information about the freebsd-bugs
mailing list