summaryrefslogtreecommitdiff
path: root/qga
diff options
context:
space:
mode:
authorEric Blake <eblake@redhat.com>2021-01-13 16:10:13 -0600
committerMarkus Armbruster <armbru@redhat.com>2021-01-28 08:08:45 +0100
commit95b3a8c8a82a34ca874ac0d4a9bbbdb38034acf3 (patch)
tree76d842228434aa8ac1dc10f8fcc4bfc5cce422d5 /qga
parentc3033fd372fdaf5b89190136a74b3d78880b85d6 (diff)
qapi: More complex uses of QAPI_LIST_APPEND
These cases require a bit more thought to review; in each case, the code was appending to a list, but not with a FOOList **tail variable. Signed-off-by: Eric Blake <eblake@redhat.com> Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com> Message-Id: <20210113221013.390592-6-eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Flawed change to qmp_guest_network_get_interfaces() dropped] Signed-off-by: Markus Armbruster <armbru@redhat.com>
Diffstat (limited to 'qga')
-rw-r--r--qga/commands-posix.c19
-rw-r--r--qga/commands-win32.c88
2 files changed, 36 insertions, 71 deletions
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index f0a23b0402..8dd94a3314 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -3138,11 +3138,10 @@ static double ga_get_login_time(struct utmpx *user_info)
GuestUserList *qmp_guest_get_users(Error **errp)
{
GHashTable *cache = NULL;
- GuestUserList *head = NULL, *cur_item = NULL;
+ GuestUserList *head = NULL, **tail = &head;
struct utmpx *user_info = NULL;
gpointer value = NULL;
GuestUser *user = NULL;
- GuestUserList *item = NULL;
double login_time = 0;
cache = g_hash_table_new(g_str_hash, g_str_equal);
@@ -3165,19 +3164,13 @@ GuestUserList *qmp_guest_get_users(Error **errp)
continue;
}
- item = g_new0(GuestUserList, 1);
- item->value = g_new0(GuestUser, 1);
- item->value->user = g_strdup(user_info->ut_user);
- item->value->login_time = ga_get_login_time(user_info);
+ user = g_new0(GuestUser, 1);
+ user->user = g_strdup(user_info->ut_user);
+ user->login_time = ga_get_login_time(user_info);
- g_hash_table_insert(cache, item->value->user, item->value);
+ g_hash_table_insert(cache, user->user, user);
- if (!cur_item) {
- head = cur_item = item;
- } else {
- cur_item->next = item;
- cur_item = item;
- }
+ QAPI_LIST_APPEND(tail, user);
}
endutxent();
g_hash_table_destroy(cache);
diff --git a/qga/commands-win32.c b/qga/commands-win32.c
index a6cc481bc3..a00e6cb165 100644
--- a/qga/commands-win32.c
+++ b/qga/commands-win32.c
@@ -1624,11 +1624,11 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
{
IP_ADAPTER_ADDRESSES *adptr_addrs, *addr;
IP_ADAPTER_UNICAST_ADDRESS *ip_addr = NULL;
- GuestNetworkInterfaceList *head = NULL, *cur_item = NULL;
- GuestIpAddressList *head_addr, *cur_addr;
- GuestNetworkInterfaceList *info;
+ GuestNetworkInterfaceList *head = NULL, **tail = &head;
+ GuestIpAddressList *head_addr, **tail_addr;
+ GuestNetworkInterface *info;
GuestNetworkInterfaceStat *interface_stat = NULL;
- GuestIpAddressList *address_item = NULL;
+ GuestIpAddress *address_item = NULL;
unsigned char *mac_addr;
char *addr_str;
WORD wsa_version;
@@ -1651,30 +1651,24 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
for (addr = adptr_addrs; addr; addr = addr->Next) {
info = g_malloc0(sizeof(*info));
- if (cur_item == NULL) {
- head = cur_item = info;
- } else {
- cur_item->next = info;
- cur_item = info;
- }
+ QAPI_LIST_APPEND(tail, info);
- info->value = g_malloc0(sizeof(*info->value));
- info->value->name = guest_wctomb_dup(addr->FriendlyName);
+ info->name = guest_wctomb_dup(addr->FriendlyName);
if (addr->PhysicalAddressLength != 0) {
mac_addr = addr->PhysicalAddress;
- info->value->hardware_address =
+ info->hardware_address =
g_strdup_printf("%02x:%02x:%02x:%02x:%02x:%02x",
(int) mac_addr[0], (int) mac_addr[1],
(int) mac_addr[2], (int) mac_addr[3],
(int) mac_addr[4], (int) mac_addr[5]);
- info->value->has_hardware_address = true;
+ info->has_hardware_address = true;
}
head_addr = NULL;
- cur_addr = NULL;
+ tail_addr = &head_addr;
for (ip_addr = addr->FirstUnicastAddress;
ip_addr;
ip_addr = ip_addr->Next) {
@@ -1685,37 +1679,29 @@ GuestNetworkInterfaceList *qmp_guest_network_get_interfaces(Error **errp)
address_item = g_malloc0(sizeof(*address_item));
- if (!cur_addr) {
- head_addr = cur_addr = address_item;
- } else {
- cur_addr->next = address_item;
- cur_addr = address_item;
- }
+ QAPI_LIST_APPEND(tail_addr, address_item);
- address_item->value = g_malloc0(sizeof(*address_item->value));
- address_item->value->ip_address = addr_str;
- address_item->value->prefix = guest_ip_prefix(ip_addr);
+ address_item->ip_address = addr_str;
+ address_item->prefix = guest_ip_prefix(ip_addr);
if (ip_addr->Address.lpSockaddr->sa_family == AF_INET) {
- address_item->value->ip_address_type =
- GUEST_IP_ADDRESS_TYPE_IPV4;
+ address_item->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV4;
} else if (ip_addr->Address.lpSockaddr->sa_family == AF_INET6) {
- address_item->value->ip_address_type =
- GUEST_IP_ADDRESS_TYPE_IPV6;
+ address_item->ip_address_type = GUEST_IP_ADDRESS_TYPE_IPV6;
}
}
if (head_addr) {
- info->value->has_ip_addresses = true;
- info->value->ip_addresses = head_addr;
+ info->has_ip_addresses = true;
+ info->ip_addresses = head_addr;
}
- if (!info->value->has_statistics) {
+ if (!info->has_statistics) {
interface_stat = g_malloc0(sizeof(*interface_stat));
if (guest_get_network_stats(addr->AdapterName,
interface_stat) == -1) {
- info->value->has_statistics = false;
+ info->has_statistics = false;
g_free(interface_stat);
} else {
- info->value->statistics = interface_stat;
- info->value->has_statistics = true;
+ info->statistics = interface_stat;
+ info->has_statistics = true;
}
}
}
@@ -2082,12 +2068,11 @@ GuestUserList *qmp_guest_get_users(Error **errp)
#define QGA_NANOSECONDS 10000000
GHashTable *cache = NULL;
- GuestUserList *head = NULL, *cur_item = NULL;
+ GuestUserList *head = NULL, **tail = &head;
DWORD buffer_size = 0, count = 0, i = 0;
GA_WTSINFOA *info = NULL;
WTS_SESSION_INFOA *entries = NULL;
- GuestUserList *item = NULL;
GuestUser *user = NULL;
gpointer value = NULL;
INT64 login = 0;
@@ -2123,23 +2108,17 @@ GuestUserList *qmp_guest_get_users(Error **errp)
user->login_time = login_time;
}
} else {
- item = g_new0(GuestUserList, 1);
- item->value = g_new0(GuestUser, 1);
+ user = g_new0(GuestUser, 1);
- item->value->user = g_strdup(info->UserName);
- item->value->domain = g_strdup(info->Domain);
- item->value->has_domain = true;
+ user->user = g_strdup(info->UserName);
+ user->domain = g_strdup(info->Domain);
+ user->has_domain = true;
- item->value->login_time = login_time;
+ user->login_time = login_time;
- g_hash_table_add(cache, item->value->user);
+ g_hash_table_add(cache, user->user);
- if (!cur_item) {
- head = cur_item = item;
- } else {
- cur_item->next = item;
- cur_item = item;
- }
+ QAPI_LIST_APPEND(tail, user);
}
}
WTSFreeMemory(info);
@@ -2424,7 +2403,7 @@ static GStrv ga_get_hardware_ids(DEVINST devInstance)
GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)
{
- GuestDeviceInfoList *head = NULL, *cur_item = NULL, *item = NULL;
+ GuestDeviceInfoList *head = NULL, **tail = &head;
HDEVINFO dev_info = INVALID_HANDLE_VALUE;
SP_DEVINFO_DATA dev_info_data;
int i, j;
@@ -2522,14 +2501,7 @@ GuestDeviceInfoList *qmp_guest_get_devices(Error **errp)
slog("driver: %s\ndriver version: %" PRId64 ",%s\n",
device->driver_name, device->driver_date,
device->driver_version);
- item = g_new0(GuestDeviceInfoList, 1);
- item->value = g_steal_pointer(&device);
- if (!cur_item) {
- head = cur_item = item;
- } else {
- cur_item->next = item;
- cur_item = item;
- }
+ QAPI_LIST_APPEND(tail, g_steal_pointer(&device));
}
if (dev_info != INVALID_HANDLE_VALUE) {