mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-12-17 21:26:13 -07:00
qga: Clean up fragile use of error_is_set()
Using error_is_set(ERRP) to find out whether a function failed is
either wrong, fragile, or unnecessarily opaque. It's wrong when ERRP
may be null, because errors go undetected when it is. It's fragile
when proving ERRP non-null involves a non-local argument. Else, it's
unnecessarily opaque (see commit 84d18f0).
The error_is_set(errp) in the guest agent command handler functions
are merely fragile, because all chall chains (do_qmp_dispatch() via
the generated marshalling functions) pass a non-null errp argument.
Make the code more robust and more obviously correct: receive the
error in a local variable, then propagate it through the parameter.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com>
This commit is contained in:
parent
ee16ce9337
commit
0f230bf70e
2 changed files with 40 additions and 20 deletions
|
|
@ -1067,8 +1067,11 @@ out:
|
|||
|
||||
void qmp_guest_suspend_disk(Error **errp)
|
||||
{
|
||||
bios_supports_mode("pm-is-supported", "--hibernate", "disk", errp);
|
||||
if (error_is_set(errp)) {
|
||||
Error *local_err = NULL;
|
||||
|
||||
bios_supports_mode("pm-is-supported", "--hibernate", "disk", &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1077,8 +1080,11 @@ void qmp_guest_suspend_disk(Error **errp)
|
|||
|
||||
void qmp_guest_suspend_ram(Error **errp)
|
||||
{
|
||||
bios_supports_mode("pm-is-supported", "--suspend", "mem", errp);
|
||||
if (error_is_set(errp)) {
|
||||
Error *local_err = NULL;
|
||||
|
||||
bios_supports_mode("pm-is-supported", "--suspend", "mem", &local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
@ -1087,8 +1093,12 @@ void qmp_guest_suspend_ram(Error **errp)
|
|||
|
||||
void qmp_guest_suspend_hybrid(Error **errp)
|
||||
{
|
||||
bios_supports_mode("pm-is-supported", "--suspend-hybrid", NULL, errp);
|
||||
if (error_is_set(errp)) {
|
||||
Error *local_err = NULL;
|
||||
|
||||
bios_supports_mode("pm-is-supported", "--suspend-hybrid", NULL,
|
||||
&local_err);
|
||||
if (local_err) {
|
||||
error_propagate(errp, local_err);
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue