From: Laszlo Ersek <lersek@redhat.com>
To: qemu-devel@nongnu.org, mst@redhat.com, aliguori@us.ibm.com,
kraxel@redhat.com
Subject: [Qemu-devel] [PATCH 03/11] acpi_table_add(): report fatal errors through an internal Error object
Date: Thu, 21 Mar 2013 00:23:15 +0100 [thread overview]
Message-ID: <1363821803-3380-4-git-send-email-lersek@redhat.com> (raw)
In-Reply-To: <1363821803-3380-1-git-send-email-lersek@redhat.com>
The upcoming changes will need a cleanup section at the end of the
function, plus OptsVisitor reports errors via Error. For now keep
channeling any Errors to stderr.
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---
hw/acpi.c | 33 +++++++++++++++++++--------------
1 files changed, 19 insertions(+), 14 deletions(-)
diff --git a/hw/acpi.c b/hw/acpi.c
index c6320d5..f34fcde 100644
--- a/hw/acpi.c
+++ b/hw/acpi.c
@@ -64,6 +64,7 @@ static int acpi_checksum(const uint8_t *data, int len)
/* XXX fixme: this function uses obsolete argument parsing interface */
int acpi_table_add(const char *t)
{
+ Error *err = NULL;
char buf[1024], *p, *f;
unsigned long val;
size_t len, start, allen;
@@ -87,8 +88,8 @@ int acpi_table_add(const char *t)
has_header = true;
break;
default:
- fprintf(stderr, "acpitable: both data and file are specified\n");
- return -1;
+ error_setg(&err, "acpitable: both data and file are specified");
+ goto out;
}
if (!acpi_tables) {
@@ -108,8 +109,8 @@ int acpi_table_add(const char *t)
int fd = open(f, O_RDONLY | O_BINARY);
if (fd < 0) {
- fprintf(stderr, "can't open file %s: %s\n", f, strerror(errno));
- return -1;
+ error_setg(&err, "can't open file %s: %s", f, strerror(errno));
+ goto out;
}
for (;;) {
@@ -122,10 +123,10 @@ int acpi_table_add(const char *t)
memcpy(acpi_tables + allen, data, r);
allen += r;
} else if (errno != EINTR) {
- fprintf(stderr, "can't read file %s: %s\n",
- f, strerror(errno));
+ error_setg(&err, "can't read file %s: %s",
+ f, strerror(errno));
close(fd);
- return -1;
+ goto out;
}
}
@@ -169,8 +170,8 @@ int acpi_table_add(const char *t)
if (get_param_value(buf, sizeof(buf), "rev", t)) {
val = strtoul(buf, &p, 0);
if (val > 255 || *p) {
- fprintf(stderr, "acpitable: \"rev=%s\" is invalid\n", buf);
- return -1;
+ error_setg(&err, "acpitable: \"rev=%s\" is invalid", buf);
+ goto out;
}
hdr.revision = (uint8_t)val;
++changed;
@@ -191,8 +192,8 @@ int acpi_table_add(const char *t)
if (get_param_value(buf, sizeof(buf), "oem_rev", t)) {
val = strtol(buf, &p, 0);
if (*p) {
- fprintf(stderr, "acpitable: \"oem_rev=%s\" is invalid\n", buf);
- return -1;
+ error_setg(&err, "acpitable: \"oem_rev=%s\" is invalid", buf);
+ goto out;
}
hdr.oem_revision = cpu_to_le32(val);
++changed;
@@ -207,9 +208,9 @@ int acpi_table_add(const char *t)
if (get_param_value(buf, sizeof(buf), "asl_compiler_rev", t)) {
val = strtol(buf, &p, 0);
if (*p) {
- fprintf(stderr, "acpitable: \"%s=%s\" is invalid\n",
- "asl_compiler_rev", buf);
- return -1;
+ error_setg(&err, "acpitable: \"%s=%s\" is invalid",
+ "asl_compiler_rev", buf);
+ goto out;
}
hdr.asl_compiler_revision = cpu_to_le32(val);
++changed;
@@ -240,6 +241,10 @@ int acpi_table_add(const char *t)
acpi_tables_len = allen;
return 0;
+out:
+ fprintf(stderr, "%s\n", error_get_pretty(err));
+ error_free(err);
+ return -1;
}
static void acpi_notify_wakeup(Notifier *notifier, void *data)
--
1.7.1
next prev parent reply other threads:[~2013-03-20 23:21 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-03-20 23:23 [Qemu-devel] [PATCH 00/11] build ACPI MADT for fw_cfg clients Laszlo Ersek
2013-03-20 23:23 ` [Qemu-devel] [PATCH 01/11] strip some whitespace Laszlo Ersek
2013-03-20 23:23 ` [Qemu-devel] [PATCH 02/11] change element type from "char" to "unsigned char" in ACPI table data Laszlo Ersek
2013-03-20 23:40 ` Eric Blake
2013-03-21 0:18 ` Laszlo Ersek
2013-03-20 23:23 ` Laszlo Ersek [this message]
2013-03-20 23:23 ` [Qemu-devel] [PATCH 04/11] qapi schema: add AcpiTableOptions Laszlo Ersek
2013-03-20 23:45 ` Eric Blake
2013-03-21 0:31 ` Laszlo Ersek
2013-03-21 10:41 ` Laszlo Ersek
2013-03-21 11:51 ` Paolo Bonzini
2013-03-21 12:36 ` Michael S. Tsirkin
2013-03-21 12:42 ` Laszlo Ersek
2013-03-21 12:44 ` Paolo Bonzini
2013-04-03 19:59 ` Anthony Liguori
2013-04-03 20:01 ` Anthony Liguori
2013-03-20 23:23 ` [Qemu-devel] [PATCH 05/11] acpi_table_add(): accept QemuOpts and parse it with OptsVisitor Laszlo Ersek
2013-03-20 23:23 ` [Qemu-devel] [PATCH 06/11] acpi_table_add(): extract and reimplement internals Laszlo Ersek
2013-03-20 23:23 ` [Qemu-devel] [PATCH 07/11] like acpi_table_install(), acpi_table_add() should propagate Errors Laszlo Ersek
2013-03-20 23:23 ` [Qemu-devel] [PATCH 08/11] extract/unify the constant 0xfee00000 as APIC_DEFAULT_ADDRESS Laszlo Ersek
2013-03-20 23:23 ` [Qemu-devel] [PATCH 09/11] Introduce IO_APIC_DEFAULT_ADDRESS for 0xfec00000 Laszlo Ersek
2013-03-20 23:23 ` [Qemu-devel] [PATCH 10/11] pc_acpi_init(): don't bail as soon as failing to find default DSDT Laszlo Ersek
2013-03-20 23:23 ` [Qemu-devel] [PATCH 11/11] i386/pc: build ACPI MADT for fw_cfg clients Laszlo Ersek
2013-04-03 16:44 ` [Qemu-devel] [PATCH 00/11] " Laszlo Ersek
2013-04-03 20:05 ` Anthony Liguori
2013-04-04 7:52 ` Laszlo Ersek
2013-04-04 23:22 ` Kevin O'Connor
2013-04-05 11:39 ` Laszlo Ersek
2013-04-05 12:51 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1363821803-3380-4-git-send-email-lersek@redhat.com \
--to=lersek@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=kraxel@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).