Bug 197866 - FreeBSD 10.1 file(1) utility returns 0 on error
Summary: FreeBSD 10.1 file(1) utility returns 0 on error
Status: Closed Works As Intended
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 10.1-RELEASE
Hardware: amd64 Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-20 21:49 UTC by Johan Ström
Modified: 2015-07-08 13:44 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Johan Ström 2015-02-20 21:49:08 UTC
From file(1) manpage:

RETURN CODE
     file returns 0 on success, and non-zero on error.

This seems to have broken on FreeBSD 10.1?

$ uname -v
FreeBSD 10.0-RELEASE-p10 #0: Mon Oct 20 12:42:25 UTC 2014     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC
$ file thisdoesnotexist
thisdoesnotexist: ERROR: cannot open `thisdoesnotexist' (No such file or directory)
$ echo $?
1



$ uname -v
FreeBSD 10.1-RELEASE-p5 #0: Tue Jan 27 08:55:07 UTC 2015     root@amd64-builder.daemonology.net:/usr/obj/usr/src/sys/GENERIC
$ file thisdoesnotexist
thisdoesnotexist: cannot open `thisdoesnotexist' (No such file or directory)
$ echo $?
0
Comment 1 Glen Barber freebsd_committer freebsd_triage 2015-07-08 13:44:07 UTC
It looks like this is intentional, from upstream file(1)/magic(5).

The '-E' option was added in February 2014, which predates the last file(1) update, which according to the manual page:

     -E      On filesystem errors (file not found etc), instead of handling
             the error as regular output as POSIX mandates and keep going,
             issue an error message and exit.

It is not clear to me why this change was made, but it appears to be that the previous '1' exit code observed on the 10.0-RELEASE machine was returned by stat(2), not file(1).