From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:47229) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYAI7-0005N8-OZ for qemu-devel@nongnu.org; Thu, 10 Apr 2014 04:25:07 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WYAHz-0003K1-RY for qemu-devel@nongnu.org; Thu, 10 Apr 2014 04:24:59 -0400 Received: from mx1.redhat.com ([209.132.183.28]:43323) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WYAHz-0003Jv-IZ for qemu-devel@nongnu.org; Thu, 10 Apr 2014 04:24:51 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s3A8Oodq008290 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 10 Apr 2014 04:24:51 -0400 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-60.ams2.redhat.com [10.36.116.60]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s3A8OlIS005705 for ; Thu, 10 Apr 2014 04:24:50 -0400 From: Laszlo Ersek Date: Thu, 10 Apr 2014 10:24:31 +0200 Message-Id: <1397118285-11715-3-git-send-email-lersek@redhat.com> In-Reply-To: <1397118285-11715-1-git-send-email-lersek@redhat.com> References: <1397118285-11715-1-git-send-email-lersek@redhat.com> Subject: [Qemu-devel] [PATCH 02/16] monitor: add Error-propagating monitor_handle_fd_param2() List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org 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 --- include/monitor/monitor.h | 1 + monitor.c | 29 +++++++++++++++++++++++------ 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/include/monitor/monitor.h b/include/monitor/monitor.h index a49ea11..07e3d29 100644 --- a/include/monitor/monitor.h +++ b/include/monitor/monitor.h @@ -73,10 +73,11 @@ int monitor_read_block_device_key(Monitor *mon, const char *device, BlockDriverCompletionFunc *completion_cb, void *opaque); 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); void monitor_printf(Monitor *mon, const char *fmt, ...) GCC_FMT_ATTR(2, 3); void monitor_print_filename(Monitor *mon, const char *filename); diff --git a/monitor.c b/monitor.c index 342e83b..0ef9749 100644 --- a/monitor.c +++ b/monitor.c @@ -2634,20 +2634,37 @@ int monitor_fdset_dup_fd_remove(int dup_fd) int monitor_handle_fd_param(Monitor *mon, const char *fdname) { int fd; Error *local_err = NULL; + 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); - if (fd == -1) { - qerror_report_err(local_err); - error_free(local_err); - return -1; - } } else { fd = qemu_parse_fd(fdname); + if (fd == -1) { + error_setg(&local_err, "Invalid file descriptor number '%s'", + fdname); + } + } + if (local_err) { + error_propagate(errp, local_err); + assert(fd == -1); + } else { + assert(fd != -1); } return fd; } -- 1.8.3.1