diff options
author | Eric Blake <eblake@redhat.com> | 2021-01-13 16:10:13 -0600 |
---|---|---|
committer | Markus Armbruster <armbru@redhat.com> | 2021-01-28 08:08:45 +0100 |
commit | 95b3a8c8a82a34ca874ac0d4a9bbbdb38034acf3 (patch) | |
tree | 76d842228434aa8ac1dc10f8fcc4bfc5cce422d5 /qga/commands-posix.c | |
parent | c3033fd372fdaf5b89190136a74b3d78880b85d6 (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/commands-posix.c')
-rw-r--r-- | qga/commands-posix.c | 19 |
1 files changed, 6 insertions, 13 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); |