Verified Commit df57ddf6 authored by Michal Hrusecky's avatar Michal Hrusecky 🐭
Browse files

pkgupdate/main: Always run posh update hooks

Run postupdate hooks even if we encountered some problematic error. Post
update hooks are quite often used even for vital functionality like
taking snapshots and deploying the kernel. Thus we need to run them even
if everything didn't went as expected.
parent cc4e3681
Pipeline #105587 passed with stages
in 3 minutes and 29 seconds
......@@ -9,7 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Invalid keyword in documentation stating that transaction ends with `STOP` but
it is signaled by keyword `END` instead
- Using correct hashing function to detect changes to non-configuration files
- Run post hooks regardless of errors during the execution of updater
## [70.0.0] - 22-01-26
### Added
......
......@@ -102,6 +102,9 @@ static const char *time_load(void) {
// use this macro.
#define GOTO_CLEANUP do { if (opts.reexec) goto REPLAN_CLEANUP; else goto CLEANUP; } while(false)
// If something fails and we are deep enough,
#define ASSERT_MSG_POST(COND, STATUS) do { if(!(COND)) { STATUS = false; goto REPLAN_CLEANUP; } } while(false)
int main(int argc, char *argv[]) {
// Some setup of the machinery
log_stderr_level(LL_INFO);
......@@ -130,6 +133,7 @@ int main(int argc, char *argv[]) {
ASSERT_MSG(!err, "%s", err);
bool trans_ok = true;
bool cleanup_ok = true;
size_t result_count;
// Set some configuration
if (opts.no_replan || opmode(OPMODE_REINSTALL_ALL)) {
......@@ -149,6 +153,7 @@ int main(int argc, char *argv[]) {
if (err) {
trans_ok = false;
ERROR("%s", err);
err = NULL;
GOTO_CLEANUP;
goto CLEANUP; // This is to suppress cppcheck redundant assigment warning
}
......@@ -179,10 +184,10 @@ int main(int argc, char *argv[]) {
exec_hook(hook_path, "Executing preupdate hook");
}
err = interpreter_call(interpreter, "transaction.perform_queue", &result_count, "");
ASSERT_MSG(!err, "%s", err);
ASSERT_MSG_POST(!err, trans_ok);
trans_ok = results_interpret(interpreter, result_count);
err = interpreter_call(interpreter, "updater.pre_cleanup", NULL, "");
ASSERT_MSG(!err, "%s", err);
ASSERT_MSG_POST(!err, cleanup_ok);
bool reboot_delayed, reboot_finished;
ASSERT(interpreter_collect_results(interpreter, "bb", &reboot_delayed, &reboot_finished) == -1);
if (reboot_finished)
......@@ -193,12 +198,16 @@ int main(int argc, char *argv[]) {
exec_hook(hook_path, "Executing reboot_required hook");
}
err = interpreter_call(interpreter, "updater.cleanup", NULL, "bb", opts.reboot_finished);
ASSERT_MSG(!err, "%s", err);
ASSERT_MSG_POST(!err, cleanup_ok);
err = NULL;
REPLAN_CLEANUP: {
const char *hook_path = aprintf("%s%s", root_dir(), hook_postupdate);
setenv("ROOT_DIR", root_dir(), true);
setenv("SUCCESS", trans_ok ? "true" : "false", true);
setenv("SUCCESS", (trans_ok && cleanup_ok) ? "true" : "false", true);
setenv("TRANSACTION_SUCCESS", trans_ok ? "true" : "false", true);
setenv("CLEANUP_SUCCESS", cleanup_ok ? "true" : "false", true);
exec_hook(hook_path, "Executing postupdate hook");
ASSERT_MSG(!err, "%s", err);
}
CLEANUP:
free(opts.approve);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment