From patchwork Thu Nov 27 02:01:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 5391121 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 07013C11AC for ; Thu, 27 Nov 2014 02:03:32 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 2A3D520123 for ; Thu, 27 Nov 2014 02:03:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 310F620115 for ; Thu, 27 Nov 2014 02:03:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753424AbaK0CD0 (ORCPT ); Wed, 26 Nov 2014 21:03:26 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:15539 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751882AbaK0CDZ (ORCPT ); Wed, 26 Nov 2014 21:03:25 -0500 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="44051002" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 27 Nov 2014 10:00:06 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id sAR233e5010587 for ; Thu, 27 Nov 2014 10:03:03 +0800 Received: from localhost.localdomain (10.167.226.111) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Thu, 27 Nov 2014 10:03:20 +0800 From: Gui Hecheng To: CC: Gui Hecheng Subject: [PATCH] btrfs-progs: fix return value problem for btrfs sub show Date: Thu, 27 Nov 2014 10:01:34 +0800 Message-ID: <1417053695-14210-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.111] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If you exec: # btrfs sub show <== 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 --- cmds-subvolume.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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);