qga: Shorten several error messages

Some, but not all error messages are of the form

    Guest agent command failed, error was '<actual error message>'

For instance, command guest-exec can fail with an error message like

    Guest agent command failed, error was 'Failed to execute child process “/bin/invalid-cmd42” (No such file or directory)'

Shorten this to just just the actual error message.  The guest-exec
example becomes

    Failed to execute child process “/bin/invalid-cmd42” (No such file or directory)

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Message-ID: <20240514105829.729342-3-armbru@redhat.com>
[Superfluous #include "qapi/qmp/qerror.h" deleted]
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
This commit is contained in:
Markus Armbruster 2024-05-14 12:58:27 +02:00
parent ecfc9890c4
commit cec07c79a4
2 changed files with 10 additions and 20 deletions

View File

@ -278,8 +278,7 @@ static void acquire_privilege(const char *name, Error **errp)
TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token))
{ {
if (!LookupPrivilegeValue(NULL, name, &priv.Privileges[0].Luid)) { if (!LookupPrivilegeValue(NULL, name, &priv.Privileges[0].Luid)) {
error_setg(errp, QERR_QGA_COMMAND_FAILED, error_setg(errp, "no luid for requested privilege");
"no luid for requested privilege");
goto out; goto out;
} }
@ -287,14 +286,12 @@ static void acquire_privilege(const char *name, Error **errp)
priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; priv.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
if (!AdjustTokenPrivileges(token, FALSE, &priv, 0, NULL, 0)) { if (!AdjustTokenPrivileges(token, FALSE, &priv, 0, NULL, 0)) {
error_setg(errp, QERR_QGA_COMMAND_FAILED, error_setg(errp, "unable to acquire requested privilege");
"unable to acquire requested privilege");
goto out; goto out;
} }
} else { } else {
error_setg(errp, QERR_QGA_COMMAND_FAILED, error_setg(errp, "failed to open privilege token");
"failed to open privilege token");
} }
out: out:
@ -308,8 +305,7 @@ static void execute_async(DWORD WINAPI (*func)(LPVOID), LPVOID opaque,
{ {
HANDLE thread = CreateThread(NULL, 0, func, opaque, 0, NULL); HANDLE thread = CreateThread(NULL, 0, func, opaque, 0, NULL);
if (!thread) { if (!thread) {
error_setg(errp, QERR_QGA_COMMAND_FAILED, error_setg(errp, "failed to dispatch asynchronous command");
"failed to dispatch asynchronous command");
} }
} }
@ -1418,22 +1414,19 @@ static void check_suspend_mode(GuestSuspendMode mode, Error **errp)
ZeroMemory(&sys_pwr_caps, sizeof(sys_pwr_caps)); ZeroMemory(&sys_pwr_caps, sizeof(sys_pwr_caps));
if (!GetPwrCapabilities(&sys_pwr_caps)) { if (!GetPwrCapabilities(&sys_pwr_caps)) {
error_setg(errp, QERR_QGA_COMMAND_FAILED, error_setg(errp, "failed to determine guest suspend capabilities");
"failed to determine guest suspend capabilities");
return; return;
} }
switch (mode) { switch (mode) {
case GUEST_SUSPEND_MODE_DISK: case GUEST_SUSPEND_MODE_DISK:
if (!sys_pwr_caps.SystemS4) { if (!sys_pwr_caps.SystemS4) {
error_setg(errp, QERR_QGA_COMMAND_FAILED, error_setg(errp, "suspend-to-disk not supported by OS");
"suspend-to-disk not supported by OS");
} }
break; break;
case GUEST_SUSPEND_MODE_RAM: case GUEST_SUSPEND_MODE_RAM:
if (!sys_pwr_caps.SystemS3) { if (!sys_pwr_caps.SystemS3) {
error_setg(errp, QERR_QGA_COMMAND_FAILED, error_setg(errp, "suspend-to-ram not supported by OS");
"suspend-to-ram not supported by OS");
} }
break; break;
default: default:
@ -2175,8 +2168,7 @@ static void ga_get_win_version(RTL_OSVERSIONINFOEXW *info, Error **errp)
HMODULE module = GetModuleHandle("ntdll"); HMODULE module = GetModuleHandle("ntdll");
PVOID fun = GetProcAddress(module, "RtlGetVersion"); PVOID fun = GetProcAddress(module, "RtlGetVersion");
if (fun == NULL) { if (fun == NULL) {
error_setg(errp, QERR_QGA_COMMAND_FAILED, error_setg(errp, "Failed to get address of RtlGetVersion");
"Failed to get address of RtlGetVersion");
return; return;
} }

View File

@ -15,7 +15,6 @@
#include "guest-agent-core.h" #include "guest-agent-core.h"
#include "qga-qapi-commands.h" #include "qga-qapi-commands.h"
#include "qapi/error.h" #include "qapi/error.h"
#include "qapi/qmp/qerror.h"
#include "qemu/base64.h" #include "qemu/base64.h"
#include "qemu/cutils.h" #include "qemu/cutils.h"
#include "commands-common.h" #include "commands-common.h"
@ -475,7 +474,7 @@ GuestExec *qmp_guest_exec(const char *path,
guest_exec_task_setup, &has_merge, &pid, input_data ? &in_fd : NULL, guest_exec_task_setup, &has_merge, &pid, input_data ? &in_fd : NULL,
has_output ? &out_fd : NULL, has_output ? &err_fd : NULL, &gerr); has_output ? &out_fd : NULL, has_output ? &err_fd : NULL, &gerr);
if (!ret) { if (!ret) {
error_setg(errp, QERR_QGA_COMMAND_FAILED, gerr->message); error_setg(errp, "%s", gerr->message);
g_error_free(gerr); g_error_free(gerr);
goto done; goto done;
} }
@ -586,8 +585,7 @@ GuestTimezone *qmp_guest_get_timezone(Error **errp)
info = g_new0(GuestTimezone, 1); info = g_new0(GuestTimezone, 1);
tz = g_time_zone_new_local(); tz = g_time_zone_new_local();
if (tz == NULL) { if (tz == NULL) {
error_setg(errp, QERR_QGA_COMMAND_FAILED, error_setg(errp, "Couldn't retrieve local timezone");
"Couldn't retrieve local timezone");
goto error; goto error;
} }