From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Nsrg7-0005cr-8W for qemu-devel@nongnu.org; Sat, 20 Mar 2010 01:56:55 -0400 Received: from [199.232.76.173] (port=53169 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Nsrg5-0005c0-Uu for qemu-devel@nongnu.org; Sat, 20 Mar 2010 01:56:53 -0400 Received: from Debian-exim by monty-python.gnu.org with spam-scanned (Exim 4.60) (envelope-from ) id 1Nsrg4-0003oR-Jk for qemu-devel@nongnu.org; Sat, 20 Mar 2010 01:56:53 -0400 Received: from mx20.gnu.org ([199.232.41.8]:45052) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Nsrg4-0003o3-8o for qemu-devel@nongnu.org; Sat, 20 Mar 2010 01:56:52 -0400 Received: from mail-pw0-f45.google.com ([209.85.160.45]) by mx20.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Nsrg3-00032W-Cl for qemu-devel@nongnu.org; Sat, 20 Mar 2010 01:56:51 -0400 Received: by pwi9 with SMTP id 9so2609166pwi.4 for ; Fri, 19 Mar 2010 22:56:49 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <1269060643-3321-1-git-send-email-ozaki.ryota@gmail.com> <1269060643-3321-2-git-send-email-ozaki.ryota@gmail.com> From: Ryota Ozaki Date: Sat, 20 Mar 2010 14:56:29 +0900 Message-ID: <5e93dcec1003192256n3c9c1bdasd26a6aa3c594286@mail.gmail.com> Subject: Re: [Qemu-devel] [PATCH 2/2] qemu-nbd: Improve error reporting Content-Type: text/plain; charset=KOI8-R Content-Transfer-Encoding: quoted-printable List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: malc Cc: qemu-devel@nongnu.org On Sat, Mar 20, 2010 at 2:26 PM, malc wrote: > On Sat, 20 Mar 2010, Ryota Ozaki wrote: > >> - use err(3) instead of errx(3) if errno is available >> =9A to report why failed >> - let fail prior to daemon(3) if opening a nbd file >> =9A is likely to fail after daemonizing to avoid silent >> =9A failure exit > > I'm under impression that you and the original author of this > code is misunderstading how err[x] works, first argument is > what will be used to exit the process and has little to do > with POSIX/C error codes. Oh, you're right. I'll revise and resend the patch. (and I'll add missing Signed-off-by fields) Thanks, ozaki-r > >> --- >> =9Aqemu-nbd.c | =9A 16 +++++++++++----- >> =9A1 files changed, 11 insertions(+), 5 deletions(-) >> >> diff --git a/qemu-nbd.c b/qemu-nbd.c >> index b89c361..5f10ff0 100644 >> --- a/qemu-nbd.c >> +++ b/qemu-nbd.c >> @@ -316,7 +316,7 @@ int main(int argc, char **argv) >> =9A =9A =9Aif (disconnect) { >> =9A =9A =9A =9A =9Afd =3D open(argv[optind], O_RDWR); >> =9A =9A =9A =9A =9Aif (fd =3D=3D -1) >> - =9A =9A =9A =9A =9A =9Aerrx(errno, "Cannot open %s", argv[optind]); >> + =9A =9A =9A =9A =9A =9Aerr(errno, "Cannot open %s", argv[optind]); >> >> =9A =9A =9A =9A =9Anbd_disconnect(fd); >> >> @@ -333,23 +333,29 @@ int main(int argc, char **argv) >> =9A =9A =9Aif (bs =3D=3D NULL) >> =9A =9A =9A =9A =9Areturn 1; >> >> - =9A =9Aif (bdrv_open(bs, argv[optind], flags) < 0) >> - =9A =9A =9A =9Areturn 1; >> + =9A =9Aif ((ret =3D bdrv_open(bs, argv[optind], flags)) < 0) { >> + =9A =9A =9A =9Aerrno =3D -ret; >> + =9A =9A =9A =9Aerr(errno, "Failed to bdrv_open '%s'", argv[optind]); >> + =9A =9A} >> >> =9A =9A =9Afd_size =3D bs->total_sectors * 512; >> >> =9A =9A =9Aif (partition !=3D -1 && >> =9A =9A =9A =9A =9Afind_partition(bs, partition, &dev_offset, &fd_size)) >> - =9A =9A =9A =9Aerrx(errno, "Could not find partition %d", partition); >> + =9A =9A =9A =9Aerr(errno, "Could not find partition %d", partition); >> >> =9A =9A =9Aif (device) { >> =9A =9A =9A =9A =9Apid_t pid; >> =9A =9A =9A =9A =9Aint sock; >> >> + =9A =9A =9A =9A/* want to fail before daemonizing */ >> + =9A =9A =9A =9Aif (access(device, R_OK|W_OK) =3D=3D -1) >> + =9A =9A =9A =9A =9A =9Aerr(errno, "Could not access '%s'", device); >> + >> =9A =9A =9A =9A =9Aif (!verbose) { >> =9A =9A =9A =9A =9A =9A =9A/* detach client and server */ >> =9A =9A =9A =9A =9A =9A =9Aif (daemon(0, 0) =3D=3D -1) { >> - =9A =9A =9A =9A =9A =9A =9A =9Aerrx(errno, "Failed to daemonize"); >> + =9A =9A =9A =9A =9A =9A =9A =9Aerr(errno, "Failed to daemonize"); >> =9A =9A =9A =9A =9A =9A =9A} >> =9A =9A =9A =9A =9A} >> >> > > -- > mailto:av1474@comtv.ru >