diff options
author | Markus Armbruster <armbru@redhat.com> | 2015-05-15 13:58:52 +0200 |
---|---|---|
committer | Stefan Hajnoczi <stefanha@redhat.com> | 2015-05-27 09:51:05 +0100 |
commit | 3791f83ca999edc2d11eb2006ccc1091cd712c15 (patch) | |
tree | 0fea3606998240a6595e9d6a2ce12067b54a8462 /net | |
parent | 6630886863d4a9b3b7bcb3b0e2895d83eb269c75 (diff) |
net/dump: Improve -net/host_net_add dump error reporting
When -net dump fails, it first reports a specific error, then a
generic one, like this:
$ qemu-system-x86_64 -net dump,id=foo,file=/eperm
qemu-system-x86_64: -net dump,id=foo,file=/eperm: -net dump: can't open /eperm
qemu-system-x86_64: -net dump,id=foo,file=/eperm: Device 'dump' could not be initialized
Convert net_init_tap() to Error. This suppresses the unwanted second
message.
Improve the error messages to include strerror(errno) where
appropriate.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Message-id: 1431691143-1015-5-git-send-email-armbru@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
Diffstat (limited to 'net')
-rw-r--r-- | net/dump.c | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/net/dump.c b/net/dump.c index 214e88a768..02c8064be0 100644 --- a/net/dump.c +++ b/net/dump.c @@ -101,7 +101,8 @@ static NetClientInfo net_dump_info = { }; static int net_dump_init(NetClientState *peer, const char *device, - const char *name, const char *filename, int len) + const char *name, const char *filename, int len, + Error **errp) { struct pcap_file_hdr hdr; NetClientState *nc; @@ -111,7 +112,7 @@ static int net_dump_init(NetClientState *peer, const char *device, fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY | O_BINARY, 0644); if (fd < 0) { - error_report("-net dump: can't open %s", filename); + error_setg_errno(errp, errno, "-net dump: can't open %s", filename); return -1; } @@ -124,7 +125,7 @@ static int net_dump_init(NetClientState *peer, const char *device, hdr.linktype = 1; if (write(fd, &hdr, sizeof(hdr)) < sizeof(hdr)) { - error_report("-net dump write error: %s", strerror(errno)); + error_setg_errno(errp, errno, "-net dump write error"); close(fd); return -1; } @@ -148,7 +149,6 @@ static int net_dump_init(NetClientState *peer, const char *device, int net_init_dump(const NetClientOptions *opts, const char *name, NetClientState *peer, Error **errp) { - /* FIXME error_setg(errp, ...) on failure */ int len; const char *file; char def_file[128]; @@ -174,7 +174,7 @@ int net_init_dump(const NetClientOptions *opts, const char *name, if (dump->has_len) { if (dump->len > INT_MAX) { - error_report("invalid length: %"PRIu64, dump->len); + error_setg(errp, "invalid length: %"PRIu64, dump->len); return -1; } len = dump->len; @@ -182,5 +182,5 @@ int net_init_dump(const NetClientOptions *opts, const char *name, len = 65536; } - return net_dump_init(peer, "dump", name, file, len); + return net_dump_init(peer, "dump", name, file, len, errp); } |