From patchwork Thu May 8 18:52:31 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Capitulino X-Patchwork-Id: 347176 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 34F96140082 for ; Fri, 9 May 2014 04:56:03 +1000 (EST) Received: from localhost ([::1]:48872 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiTU9-0002V4-6p for incoming@patchwork.ozlabs.org; Thu, 08 May 2014 14:56:01 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54084) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiTRd-0007uS-10 for qemu-devel@nongnu.org; Thu, 08 May 2014 14:53:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WiTRW-0008Mk-No for qemu-devel@nongnu.org; Thu, 08 May 2014 14:53:24 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15892) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WiTRW-0008ML-F6 for qemu-devel@nongnu.org; Thu, 08 May 2014 14:53:18 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s48IrEMo007067 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 8 May 2014 14:53:14 -0400 Received: from localhost (ovpn-113-20.phx2.redhat.com [10.3.113.20]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s48IrEoe007363; Thu, 8 May 2014 14:53:14 -0400 From: Luiz Capitulino To: peter.maydell@linaro.org Date: Thu, 8 May 2014 14:52:31 -0400 Message-Id: <1399575182-9768-8-git-send-email-lcapitulino@redhat.com> In-Reply-To: <1399575182-9768-1-git-send-email-lcapitulino@redhat.com> References: <1399575182-9768-1-git-send-email-lcapitulino@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: qemu-devel@nongnu.org, anthony@codemonkey.ws Subject: [Qemu-devel] [PULL 07/38] monitor: add Error-propagating monitor_handle_fd_param2() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Laszlo Ersek and rebase monitor_handle_fd_param() to it. (Note that this will slightly change the behavior when the qemu_parse_fd() branch is selected and it fails: we now report (and in case of QMP, set) the error immediately, rather than allowing the caller to set its own error message (if any)). Signed-off-by: Laszlo Ersek Reviewed-by: Eric Blake Signed-off-by: Luiz Capitulino --- include/monitor/monitor.h | 1 + monitor.c | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index 42d8671..1c1f56f 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -75,6 +75,7 @@ int monitor_read_block_device_key(Monitor *mon, const char *device, int monitor_get_fd(Monitor *mon, const char *fdname, Error **errp); int monitor_handle_fd_param(Monitor *mon, const char *fdname); +int monitor_handle_fd_param2(Monitor *mon, const char *fdname, Error **errp); void monitor_vprintf(Monitor *mon, const char *fmt, va_list ap) GCC_FMT_ATTR(2, 0); diff --git a/monitor.c b/monitor.c index 2d3fb3f..9af6b0a 100644 --- a/monitor.c +++ b/monitor.c @@ -2611,16 +2611,33 @@ int monitor_handle_fd_param(Monitor *mon, const char *fdname) int fd; Error *local_err = NULL; - if (!qemu_isdigit(fdname[0]) && mon) { + fd = monitor_handle_fd_param2(mon, fdname, &local_err); + if (local_err) { + qerror_report_err(local_err); + error_free(local_err); + } + return fd; +} + +int monitor_handle_fd_param2(Monitor *mon, const char *fdname, Error **errp) +{ + int fd; + Error *local_err = NULL; + if (!qemu_isdigit(fdname[0]) && mon) { fd = monitor_get_fd(mon, fdname, &local_err); + } else { + fd = qemu_parse_fd(fdname); if (fd == -1) { - qerror_report_err(local_err); - error_free(local_err); - return -1; + error_setg(&local_err, "Invalid file descriptor number '%s'", + fdname); } + } + if (local_err) { + error_propagate(errp, local_err); + assert(fd == -1); } else { - fd = qemu_parse_fd(fdname); + assert(fd != -1); } return fd;