Bug 197567 - chflags -f argument ignored when no file found to be modified
Summary: chflags -f argument ignored when no file found to be modified
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 Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-02-12 14:30 UTC by jesco.freund
Modified: 2015-07-08 13:18 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 jesco.freund 2015-02-12 14:30:35 UTC
According to the chflags(1) manual page, the -f argument should prevent chflags from printing any message to stderr and from modifying its exit status. However, when called with a a pattern not delivering any files, chflags will still exit with status 1 and print "chflags: No match." to stderr.

This behaviour can be reproduced:

#~ mkdir test
#~ /bin/chflags -f noschg test/*
chflags: No match.
#~ echo $?
1

Suggested fix:
Either change behaviour of chflags to silently exit with status 0 when an empty set of files is supplied (if called with the -f flag, of course) - or update man page to document the current behaviour correctly.
Comment 1 Jilles Tjoelker freebsd_committer freebsd_triage 2015-02-15 23:23:32 UTC
The error message ("No match") you get is from tcsh. It happens before chflags is started, so chflags cannot do anything about it.

With sh, the error message is:

chflags: /var/empty/*: No such file or directory

A command like  chflags -f noschg /  correctly prints no error message and returns exit status 0, however.

To me, the text in the man page

     -f      Do not display a diagnostic message if chflags could not modify
             the flags for file, nor modify the exit status to reflect such
             failures.

seems to match the behaviour I see: only failures to modify flags are suppressed, while failures to locate files are unaffected. This matches chmod's -f option, but that option is not standard either.