From patchwork Sat Mar 20 06:23:24 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryota OZAKI X-Patchwork-Id: 48202 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 E02FEB7D4D for ; Sat, 20 Mar 2010 17:36:57 +1100 (EST) Received: from localhost ([127.0.0.1]:40419 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NssIo-0005Xk-US for incoming@patchwork.ozlabs.org; Sat, 20 Mar 2010 02:36:54 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nss7n-00040h-TU for qemu-devel@nongnu.org; Sat, 20 Mar 2010 02:25:31 -0400 Received: from [199.232.76.173] (port=49780 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nss7n-00040P-9N for qemu-devel@nongnu.org; Sat, 20 Mar 2010 02:25:31 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nss7m-00072O-0O for qemu-devel@nongnu.org; Sat, 20 Mar 2010 02:25:30 -0400 Received: from mx20.gnu.org ([199.232.41.8]:45486) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Nss7l-000722-GS for qemu-devel@nongnu.org; Sat, 20 Mar 2010 02:25:29 -0400 Received: from mail-gy0-f173.google.com ([209.85.160.173]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nss7k-0003cA-NL for qemu-devel@nongnu.org; Sat, 20 Mar 2010 02:25:28 -0400 Received: by gyd5 with SMTP id 5so1888661gyd.4 for ; Fri, 19 Mar 2010 23:25:28 -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=nj2OOq/ugQLMdLWARB0vIa/iyE1MFdzSzC2PAbpntDg=; b=rknbKZai/fzLVawlBe7ZqgZMUQCv4j8CAtLlkM6fimydcy07ta/yPpQrHVxDUodnHa P3BCqLLediAjYp1+cHhvL7eBAZ3lwi/BIUGc3cBBnlGQu/OU7q26gwbv8sBXzRihGtFE Iwee+/wT/LiB89CmhrBbxz2A445zPqN5JAVl0= 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=pIUg+ASIePVb/ih9jMMw8kSpzy0SWVW0UXoeXDDH/U/e/Ab5mOd9a59iiM5wJNoUNq ODDUDpl14z7vSbEHgzZt1Z9PlZLZYRLaTRCj5+Nyo+90NezMR5HZSyhLpErt07wrSl5K 8k9hbkvNIO4cUcf95YESd81mUQhAOLpm8+484= Received: by 10.101.136.13 with SMTP id o13mr9423617ann.235.1269066327523; Fri, 19 Mar 2010 23:25:27 -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.25 (version=SSLv3 cipher=RC4-MD5); Fri, 19 Mar 2010 23:25:26 -0700 (PDT) From: Ryota Ozaki To: qemu-devel@nongnu.org Date: Sat, 20 Mar 2010 15:23:24 +0900 Message-Id: <1269066204-4376-3-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 3/3] qemu-nbd: Improve error reporting 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 - use err(3) instead of errx(3) if errno is available to report why failed - let fail prior to daemon(3) if opening a nbd file is likely to fail after daemonizing to avoid silent failure exit Signed-off-by: Ryota Ozaki --- qemu-nbd.c | 16 +++++++++++----- 1 files changed, 11 insertions(+), 5 deletions(-) diff --git a/qemu-nbd.c b/qemu-nbd.c index 6d854d3..8fb8cc3 100644 --- a/qemu-nbd.c +++ b/qemu-nbd.c @@ -316,7 +316,7 @@ int main(int argc, char **argv) if (disconnect) { fd = open(argv[optind], O_RDWR); if (fd == -1) - errx(EXIT_FAILURE, "Cannot open %s", argv[optind]); + err(EXIT_FAILURE, "Cannot open %s", argv[optind]); nbd_disconnect(fd); @@ -333,23 +333,29 @@ int main(int argc, char **argv) if (bs == NULL) return 1; - if (bdrv_open(bs, argv[optind], flags) < 0) - return 1; + if ((ret = bdrv_open(bs, argv[optind], flags)) < 0) { + errno = -ret; + err(EXIT_FAILURE, "Failed to bdrv_open '%s'", argv[optind]); + } fd_size = bs->total_sectors * 512; if (partition != -1 && find_partition(bs, partition, &dev_offset, &fd_size)) - errx(EXIT_FAILURE, "Could not find partition %d", partition); + err(EXIT_FAILURE, "Could not find partition %d", partition); if (device) { pid_t pid; int sock; + /* want to fail before daemonizing */ + if (access(device, R_OK|W_OK) == -1) + err(EXIT_FAILURE, "Could not access '%s'", device); + if (!verbose) { /* detach client and server */ if (daemon(0, 0) == -1) { - errx(EXIT_FAILURE, "Failed to daemonize"); + err(EXIT_FAILURE, "Failed to daemonize"); } }