[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v3 5/7] qga/commands-posix: execute_fsfreeze_hook: use ga_run_com
From: |
Andrey Drobyshev |
Subject: |
[PATCH v3 5/7] qga/commands-posix: execute_fsfreeze_hook: use ga_run_command helper |
Date: |
Fri, 15 Mar 2024 14:29:44 +0200 |
There's no need to check for the existence of the hook executable, as the
exec() call will do that for us.
Signed-off-by: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
---
qga/commands-posix.c | 35 +++--------------------------------
1 file changed, 3 insertions(+), 32 deletions(-)
diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 94b652d54e..610d225d30 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -736,8 +736,6 @@ static const char *fsfreeze_hook_arg_string[] = {
static void execute_fsfreeze_hook(FsfreezeHookArg arg, Error **errp)
{
- int status;
- pid_t pid;
const char *hook;
const char *arg_str = fsfreeze_hook_arg_string[arg];
Error *local_err = NULL;
@@ -746,42 +744,15 @@ static void execute_fsfreeze_hook(FsfreezeHookArg arg,
Error **errp)
if (!hook) {
return;
}
- if (access(hook, X_OK) != 0) {
- error_setg_errno(errp, errno, "can't access fsfreeze hook '%s'", hook);
- return;
- }
- slog("executing fsfreeze hook with arg '%s'", arg_str);
- pid = fork();
- if (pid == 0) {
- setsid();
- reopen_fd_to_null(0);
- reopen_fd_to_null(1);
- reopen_fd_to_null(2);
-
- execl(hook, hook, arg_str, NULL);
- _exit(EXIT_FAILURE);
- } else if (pid < 0) {
- error_setg_errno(errp, errno, "failed to create child process");
- return;
- }
+ const char *argv[] = {hook, arg_str, NULL};
- ga_wait_child(pid, &status, &local_err);
+ slog("executing fsfreeze hook with arg '%s'", arg_str);
+ ga_run_command(argv, NULL, "execute fsfreeze hook", &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
-
- if (!WIFEXITED(status)) {
- error_setg(errp, "fsfreeze hook has terminated abnormally");
- return;
- }
-
- status = WEXITSTATUS(status);
- if (status) {
- error_setg(errp, "fsfreeze hook has failed with status %d", status);
- return;
- }
}
/*
--
2.39.3
- Re: [PATCH v3 1/7] qga: guest-get-fsinfo: add optional 'total-bytes-root' field, (continued)
- [PATCH v3 2/7] qga: introduce ga_run_command() helper for guest cmd execution, Andrey Drobyshev, 2024/03/15
- [PATCH v3 6/7] qga/commands-posix: don't do fork()/exec() when suspending via sysfs, Andrey Drobyshev, 2024/03/15
- [PATCH v3 4/7] qga/commands-posix: qmp_guest_set_time: use ga_run_command helper, Andrey Drobyshev, 2024/03/15
- [PATCH v3 7/7] qga/commands-posix: qmp_guest_set_user_password: use ga_run_command helper, Andrey Drobyshev, 2024/03/15
- [PATCH v3 5/7] qga/commands-posix: execute_fsfreeze_hook: use ga_run_command helper,
Andrey Drobyshev <=
- [PATCH v3 3/7] qga/commands-posix: qmp_guest_shutdown: use ga_run_command helper, Andrey Drobyshev, 2024/03/15