
On 8/23/19 6:31 PM, Jonathon Jongsma wrote:
This function queries the guest operating system information and adds the returned information to an array of typed parameters with field names intended to be returned in virDomainGetGuestInfo().
Signed-off-by: Jonathon Jongsma <jjongsma@redhat.com> --- src/qemu/qemu_agent.c | 53 ++++++++++++++++++ src/qemu/qemu_agent.h | 1 + tests/qemuagenttest.c | 122 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+)
diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index 963a4b9359..0fcc3fdabd 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -2331,3 +2331,56 @@ qemuAgentGetUsers(qemuAgentPtr mon, virJSONValueFree(reply); return ret; } + +int +qemuAgentGetOSInfo(qemuAgentPtr mon, + virTypedParameterPtr *params, + int *nparams, + int *maxparams) +{ + int ret = -1; + virJSONValuePtr cmd; + virJSONValuePtr reply = NULL; + virJSONValuePtr data = NULL;
Again, VIR_AUTOPTR() is your friend ;-) Long story short, VIR_AUTOFREE/VIR_AUTOPTR/VIR_AUTOUNREF()/... is our use of attribute(__cleanup__) which is a way of telling compiler to call a function once the associated variable goes out of scope. In general, the function can be anything, but we use it for automagic free/unref. This way, we can drop explicit calls to virXXXFree() if the variable is marked as VIR_AUTO*** and thus save up a few lines. Also, the code is more robust as there won't be any hidden path this forgets to 'goto cleanup' and thus causes a memleak. It takes some time to get used to it and we still haven't converted our code fully (as you realized by now for sure). Michal