btrfs-progs: fix return value problem for btrfs sub show
diff mbox

Message ID 1417053695-14210-1-git-send-email-guihc.fnst@cn.fujitsu.com
State Accepted
Headers show

Commit Message

Gui Hecheng Nov. 27, 2014, 2:01 a.m. UTC
If you exec:
	# btrfs sub show <dir>	<== non-subvolume dir
The cmd print error messages as expected, but returns 0.
By convetion, it should return non-zero and we should explicitly
set it before it goto out.

With other pieces adopted:
1) removed a unnecessary return value set -EINVAL
2) fixed another code branch which may return 0 upon error.
3) with 2) applied, the ret = 0 follows can be removed

Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com>
---
 cmds-subvolume.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Patch
diff mbox

diff --git a/cmds-subvolume.c b/cmds-subvolume.c
index fa58a24..53eec46 100644
--- a/cmds-subvolume.c
+++ b/cmds-subvolume.c
@@ -906,6 +906,7 @@  static int cmd_subvol_show(int argc, char **argv)
 	}
 	if (!ret) {
 		fprintf(stderr, "ERROR: '%s' is not a subvolume\n", fullpath);
+		ret = 1;
 		goto out;
 	}
 
@@ -919,7 +920,6 @@  static int cmd_subvol_show(int argc, char **argv)
 		fprintf(stderr,
 			"ERROR: %s doesn't belong to btrfs mount point\n",
 			fullpath);
-		ret = -EINVAL;
 		goto out;
 	}
 	ret = 1;
@@ -958,13 +958,13 @@  static int cmd_subvol_show(int argc, char **argv)
 	memset(&get_ri, 0, sizeof(get_ri));
 	get_ri.root_id = sv_id;
 
-	if (btrfs_get_subvol(mntfd, &get_ri)) {
+	ret = btrfs_get_subvol(mntfd, &get_ri);
+	if (ret) {
 		fprintf(stderr, "ERROR: can't find '%s'\n",
 			svpath);
 		goto out;
 	}
 
-	ret = 0;
 	/* print the info */
 	printf("%s\n", fullpath);
 	printf("\tName: \t\t\t%s\n", get_ri.name);