From 9a1582734027f7352f16eb5a6251eabeffa46375 Mon Sep 17 00:00:00 2001 Message-Id: <9a1582734027f7352f16eb5a6251eabeffa46375.1367947969.git.minovotn@redhat.com> In-Reply-To: <707b9b97153063374d2530e72c49b1499fc21af9.1367947969.git.minovotn@redhat.com> References: <707b9b97153063374d2530e72c49b1499fc21af9.1367947969.git.minovotn@redhat.com> From: Michal Novotny Date: Tue, 7 May 2013 18:36:13 +0200 Subject: [PATCH 007/114] Revert "qemu-ga: qmp_guest_network_get_interfaces(): get rid of snprintf() + error_set()" This reverts commit 68785d91377a8308478e74e771158c2cc778940f. Reverting as asked by Laszlo in message <51892739.2030807@redhat.com> because of the ordering issue (most likely) related to supersed testing. Signed-off-by: Michal Novotny --- qga/commands-posix.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index e28dfd4..6463a9a 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -963,9 +963,12 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) { GuestNetworkInterfaceList *head = NULL, *cur_item = NULL; struct ifaddrs *ifap, *ifa; + char err_msg[512]; if (getifaddrs(&ifap) < 0) { - error_setg_errno(errp, errno, "getifaddrs failed"); + snprintf(err_msg, sizeof(err_msg), + "getifaddrs failed: %s", strerror(errno)); + error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg); goto error; } @@ -1001,16 +1004,20 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) /* we haven't obtained HW address yet */ sock = socket(PF_INET, SOCK_STREAM, 0); if (sock == -1) { - error_setg_errno(errp, errno, "failed to create socket"); + snprintf(err_msg, sizeof(err_msg), + "failed to create socket: %s", strerror(errno)); + error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg); goto error; } memset(&ifr, 0, sizeof(ifr)); pstrcpy(ifr.ifr_name, IF_NAMESIZE, info->value->name); if (ioctl(sock, SIOCGIFHWADDR, &ifr) == -1) { - error_setg_errno(errp, errno, - "failed to get MAC address of %s", - ifa->ifa_name); + snprintf(err_msg, sizeof(err_msg), + "failed to get MAC addresss of %s: %s", + ifa->ifa_name, + strerror(errno)); + error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg); goto error; } @@ -1021,7 +1028,9 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) (int) mac_addr[0], (int) mac_addr[1], (int) mac_addr[2], (int) mac_addr[3], (int) mac_addr[4], (int) mac_addr[5]) == -1) { - error_setg_errno(errp, errno, "failed to format MAC"); + snprintf(err_msg, sizeof(err_msg), + "failed to format MAC: %s", strerror(errno)); + error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg); goto error; } @@ -1036,7 +1045,9 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) address_item->value = g_malloc0(sizeof(*address_item->value)); p = &((struct sockaddr_in *)ifa->ifa_addr)->sin_addr; if (!inet_ntop(AF_INET, p, addr4, sizeof(addr4))) { - error_setg_errno(errp, errno, "inet_ntop failed"); + snprintf(err_msg, sizeof(err_msg), + "inet_ntop failed : %s", strerror(errno)); + error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg); goto error; } @@ -1056,7 +1067,9 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp) address_item->value = g_malloc0(sizeof(*address_item->value)); p = &((struct sockaddr_in6 *)ifa->ifa_addr)->sin6_addr; if (!inet_ntop(AF_INET6, p, addr6, sizeof(addr6))) { - error_setg_errno(errp, errno, "inet_ntop failed"); + snprintf(err_msg, sizeof(err_msg), + "inet_ntop failed : %s", strerror(errno)); + error_set(errp, QERR_QGA_COMMAND_FAILED, err_msg); goto error; } -- 1.7.11.7