From patchwork Sat Mar 20 06:23:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryota OZAKI X-Patchwork-Id: 48201 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 42871B7CFC for ; Sat, 20 Mar 2010 17:35:02 +1100 (EST) Received: from localhost ([127.0.0.1]:47692 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NssDW-0004ZC-9C for incoming@patchwork.ozlabs.org; Sat, 20 Mar 2010 02:31:26 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nss7l-0003zW-8t for qemu-devel@nongnu.org; Sat, 20 Mar 2010 02:25:29 -0400 Received: from [199.232.76.173] (port=49778 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nss7k-0003zH-QT for qemu-devel@nongnu.org; Sat, 20 Mar 2010 02:25:28 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nss7j-000710-GA for qemu-devel@nongnu.org; Sat, 20 Mar 2010 02:25:28 -0400 Received: from mx20.gnu.org ([199.232.41.8]:45482) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Nss7i-00070d-SS for qemu-devel@nongnu.org; Sat, 20 Mar 2010 02:25:27 -0400 Received: from mail-yw0-f198.google.com ([209.85.211.198]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nss7i-0003c4-1y for qemu-devel@nongnu.org; Sat, 20 Mar 2010 02:25:26 -0400 Received: by ywh36 with SMTP id 36so931846ywh.4 for ; Fri, 19 Mar 2010 23:25:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:to:subject:date :message-id:x-mailer:in-reply-to:references; bh=FVPJtIyRaDSlVhAp11CGZD52r0qN9KhBvHYkEXSuf9E=; b=gNBREZ4KdVm0KUv+3BbTFwrLuwtC+s/3B5QF9EoY8SmVJOt/+Xph6F4sNH/P6leDvN 4K9xNK0aUjE0m9IzthrPlbJYIRf+/jv3iKnKq2T8Q44YqLJFMcdFzakmP0WhTE6O7sQV YncKMqaWKF8kKHejyW5R1VTEst46QCtMGOGPU= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:to:subject:date:message-id:x-mailer:in-reply-to:references; b=PoDN1G3ockw80y1DH7YYT2+ZCrHY/5hHykB5LY07vCFSLErpBWoje9RKHHmhNuTNOF 5yfcYRcwn+lKx7zUJs+vf0DxGBp3aum6sInfAKwlTEuW7y5ZKRoNu5NHiUuTPhLPMQU+ PlHtVISKQ3Dw/KkQNkYZ8M5QchTCYQ2aQCrSg= Received: by 10.101.131.27 with SMTP id i27mr9467199ann.230.1269066325240; Fri, 19 Mar 2010 23:25:25 -0700 (PDT) Received: from localhost.localdomain (host105.nvlab.org [122.1.115.105]) by mx.google.com with ESMTPS id 4sm688817ywd.13.2010.03.19.23.25.23 (version=SSLv3 cipher=RC4-MD5); Fri, 19 Mar 2010 23:25:24 -0700 (PDT) From: Ryota Ozaki To: qemu-devel@nongnu.org Date: Sat, 20 Mar 2010 15:23:23 +0900 Message-Id: <1269066204-4376-2-git-send-email-ozaki.ryota@gmail.com> X-Mailer: git-send-email 1.6.5.2 In-Reply-To: <1269066204-4376-1-git-send-email-ozaki.ryota@gmail.com> References: <1269066204-4376-1-git-send-email-ozaki.ryota@gmail.com> X-detected-operating-system: by mx20.gnu.org: GNU/Linux 2.6 (newer, 2) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6, seldom 2.4 (older, 4) Subject: [Qemu-devel] [PATCH 2/3] qemu-nbd: Fix invalid usage of the first argument of errx X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org errx takes the exit status of a process as the first argument. Passing errno to it is wrong. Instead the patch lets errx take EXIT_FAILURE. Signed-off-by: Ryota Ozaki --- qemu-nbd.c | 34 +++++++++++++++++----------------- 1 files changed, 17 insertions(+), 17 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index b89c361..6d854d3 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -114,7 +114,7 @@ static int find_partition(BlockDriverState *bs, int partition, int ext_partnum = 4; if (bdrv_read(bs, 0, data, 1)) - errx(EINVAL, "error while reading"); + errx(EXIT_FAILURE, "error while reading"); if (data[510] != 0x55 || data[511] != 0xaa) { errno = -EINVAL; @@ -133,7 +133,7 @@ static int find_partition(BlockDriverState *bs, int partition, int j; if (bdrv_read(bs, mbr[i].start_sector_abs, data1, 1)) - errx(EINVAL, "error while reading"); + errx(EXIT_FAILURE, "error while reading"); for (j = 0; j < 4; j++) { read_partition(&data1[446 + 16 * j], &ext[j]); @@ -240,20 +240,20 @@ int main(int argc, char **argv) case 'p': li = strtol(optarg, &end, 0); if (*end) { - errx(EINVAL, "Invalid port `%s'", optarg); + errx(EXIT_FAILURE, "Invalid port `%s'", optarg); } if (li < 1 || li > 65535) { - errx(EINVAL, "Port out of range `%s'", optarg); + errx(EXIT_FAILURE, "Port out of range `%s'", optarg); } port = (uint16_t)li; break; case 'o': dev_offset = strtoll (optarg, &end, 0); if (*end) { - errx(EINVAL, "Invalid offset `%s'", optarg); + errx(EXIT_FAILURE, "Invalid offset `%s'", optarg); } if (dev_offset < 0) { - errx(EINVAL, "Offset must be positive `%s'", optarg); + errx(EXIT_FAILURE, "Offset must be positive `%s'", optarg); } break; case 'r': @@ -263,14 +263,14 @@ int main(int argc, char **argv) case 'P': partition = strtol(optarg, &end, 0); if (*end) - errx(EINVAL, "Invalid partition `%s'", optarg); + errx(EXIT_FAILURE, "Invalid partition `%s'", optarg); if (partition < 1 || partition > 8) - errx(EINVAL, "Invalid partition %d", partition); + errx(EXIT_FAILURE, "Invalid partition %d", partition); break; case 'k': socket = optarg; if (socket[0] != '/') - errx(EINVAL, "socket path must be absolute\n"); + errx(EXIT_FAILURE, "socket path must be absolute\n"); break; case 'd': disconnect = true; @@ -281,10 +281,10 @@ int main(int argc, char **argv) case 'e': shared = strtol(optarg, &end, 0); if (*end) { - errx(EINVAL, "Invalid shared device number '%s'", optarg); + errx(EXIT_FAILURE, "Invalid shared device number '%s'", optarg); } if (shared < 1) { - errx(EINVAL, "Shared device number must be greater than 0\n"); + errx(EXIT_FAILURE, "Shared device number must be greater than 0\n"); } break; case 't': @@ -302,13 +302,13 @@ int main(int argc, char **argv) exit(0); break; case '?': - errx(EINVAL, "Try `%s --help' for more information.", + errx(EXIT_FAILURE, "Try `%s --help' for more information.", argv[0]); } } if ((argc - optind) != 1) { - errx(EINVAL, "Invalid number of argument.\n" + errx(EXIT_FAILURE, "Invalid number of argument.\n" "Try `%s --help' for more information.", argv[0]); } @@ -316,7 +316,7 @@ int main(int argc, char **argv) if (disconnect) { fd = open(argv[optind], O_RDWR); if (fd == -1) - errx(errno, "Cannot open %s", argv[optind]); + errx(EXIT_FAILURE, "Cannot open %s", argv[optind]); nbd_disconnect(fd); @@ -340,7 +340,7 @@ int main(int argc, char **argv) if (partition != -1 && find_partition(bs, partition, &dev_offset, &fd_size)) - errx(errno, "Could not find partition %d", partition); + errx(EXIT_FAILURE, "Could not find partition %d", partition); if (device) { pid_t pid; @@ -349,7 +349,7 @@ int main(int argc, char **argv) if (!verbose) { /* detach client and server */ if (daemon(0, 0) == -1) { - errx(errno, "Failed to daemonize"); + errx(EXIT_FAILURE, "Failed to daemonize"); } } @@ -429,7 +429,7 @@ int main(int argc, char **argv) data = qemu_memalign(512, NBD_BUFFER_SIZE); if (data == NULL) - errx(ENOMEM, "Cannot allocate data buffer"); + errx(EXIT_FAILURE, "Cannot allocate data buffer"); do {