Blob Blame History Raw
From c3fa3829e494c1875416058bb8d448a89f9e5e55 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Wed, 22 Dec 2010 14:13:27 +0100
Subject: [PATCH] getfattr: return non-zero exit code on failure
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

reported by Jean-Pierre André at https://bugzilla.redhat.com/660619
---
 getfattr/getfattr.c |    7 ++++---
 test/attr.test      |    4 ++++
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/getfattr/getfattr.c b/getfattr/getfattr.c
index 7ced700..d8a7bc5 100644
--- a/getfattr/getfattr.c
+++ b/getfattr/getfattr.c
@@ -355,6 +355,7 @@ int do_print(const char *path, const struct stat *stat, int walk_flags,
 	     void *unused)
 {
 	int header_printed = 0;
+	int err = 0;
 
 	if (walk_flags & WALK_TREE_FAILED) {
 		fprintf(stderr, "%s: %s: %s\n", progname, xquote(path, "\n\r"),
@@ -363,13 +364,13 @@ int do_print(const char *path, const struct stat *stat, int walk_flags,
 	}
 
 	if (opt_name)
-		print_attribute(path, opt_name, &header_printed);
+		err = print_attribute(path, opt_name, &header_printed);
 	else
-		list_attributes(path, &header_printed);
+		err = list_attributes(path, &header_printed);
 
 	if (header_printed)
 		puts("");
-	return 0;
+	return err;
 }
 
 void help(void)
diff --git a/test/attr.test b/test/attr.test
index e8f134c..10f10d0 100644
--- a/test/attr.test
+++ b/test/attr.test
@@ -22,6 +22,10 @@ Try various valid and invalid names
 	> user.name
 	> 
 	
+	$ setfattr -x user.name f
+	$ sh -c 'getfattr -n user.name f && echo zero exit code'
+	> f: user.name: No such attribute
+	
 	$ setfattr -n user.n -v value f
 	$ rm f
 
-- 
1.7.3.3