Red Hat Bugzilla – Bug 606757
chattr and lsattr always return 0
Last modified: 2011-07-21 08:38:43 EDT
Description of problem:
chattr and lsattr always return 0 even if they haven't done anything because of errors.
Version-Release number of selected component (if applicable):
Steps to Reproduce:
[root@a1 ~]# lsattr /non/existent/file; echo $?
lsattr: No such file or directory while trying to stat /non/existent/file
[root@a1 ~]# chattr +a /non/existent/file; echo $?
chattr: No such file or directory while trying to stat /non/existent/file
error code = 0. This makes using in scripts very difficult wrt error checking
EC=0 means that operation was completed successfully. Any failure must result in error code > 0.
I have a patch upstream for this:
Author: Theodore Ts'o <email@example.com>
Date: Mon Oct 22 08:51:39 2007 -0400
chattr: provide an exit code in case of failure and add -f flag
Fix chattr so that if there are errors, it will report it via a
non-zero exit code. It will now explicitly give errors when
attempting to set files that are not files or directories (which are
currently not supported under Linux). The -f flag will suppress error
messages from being printed, although the exit status will still be
Signed-off-by: "Theodore Ts'o" <firstname.lastname@example.org>
Signed-off-by: Eric Sandeen <email@example.com>
which should resolve the issue.
This request was evaluated by Red Hat Product Management for
inclusion in the current release of Red Hat Enterprise Linux.
Because the affected component is not scheduled to be updated in the
current release, Red Hat is unfortunately unable to address this
request at this time. Red Hat invites you to ask your support
representative to propose this request, if appropriate and relevant,
in the next release of Red Hat Enterprise Linux.
Eric, did this get pulled into RHEL5 for ext4 or ext3?
It is in RHEL6 via upstream. I plan to push it for RHEL5.7. The fix will be in e2fsprogs' chattr, and will work fine for any filesystem.
Built & tagged in e2fsprogs-1.39-28.el5
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on therefore solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.