Improve error reporting in execute_fsfreeze_hook() using ga_wait_child(). This patch depends on patchset to improve error reporting by Luiz Capitulino, especially on http://patchwork.ozlabs.org/patch/202208/ .
Signed-off-by: Tomoki Sekiyama <[email protected]> --- qga/commands-posix.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/qga/commands-posix.c b/qga/commands-posix.c index bf22a58..dbfcbdf 100644 --- a/qga/commands-posix.c +++ b/qga/commands-posix.c @@ -423,18 +423,18 @@ const char *fsfreeze_hook_arg_string[] = { static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **err) { int status; - pid_t pid, rpid; + pid_t pid; const char *hook; const char *arg_str = fsfreeze_hook_arg_string[arg]; - char err_msg[512]; + Error *local_err = NULL; hook = ga_fsfreeze_hook(ga_state); if (!hook) { return; } if (access(hook, X_OK) != 0) { - error_set_errno(err, errno, QERR_QGA_COMMAND_FAILED, - "fsfreeze hook is not executable"); + error_setg_errno(err, errno, + "fsfreeze hook '%s' is not executable", hook); return; } @@ -453,25 +453,20 @@ static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **err) return; } - do { - rpid = waitpid(pid, &status, 0); - } while (rpid == -1 && errno == EINTR); - if (rpid < 0) { - sprintf(err_msg, "failed to wait for fsfreeze hook(pid: %d)", pid); - error_set_errno(err, errno, QERR_QGA_COMMAND_FAILED, err_msg); + ga_wait_child(pid, &status, &local_err); + if (error_is_set(&local_err)) { + error_propagate(err, local_err); return; } if (!WIFEXITED(status)) { - error_set(err, QERR_QGA_COMMAND_FAILED, - "fsfreeze hook has terminated abnormally"); + error_setg(err, "fsfreeze hook has terminated abnormally"); return; } status = WEXITSTATUS(status); if (status) { - sprintf(err_msg, "fsfreeze hook has failed with signal %d", status); - error_set(err, QERR_QGA_COMMAND_FAILED, err_msg); + error_setg(err, "fsfreeze hook has failed with status %d", status); return; } }
