| 732 | } |
| 733 | |
| 734 | static int cli_activation_guard(cbm_daemon_runtime_activation_action_t action, |
| 735 | const char *target_version, const char *target_build, |
| 736 | cbm_cli_activation_mutation_fn mutation, void *mutation_context) { |
| 737 | if (g_cli_activation_test_ops_set) { |
| 738 | return cbm_cli_activation_guard_with_ops(&g_cli_activation_test_ops, mutation, |
| 739 | mutation_context); |
| 740 | } |
| 741 | |
| 742 | cli_activation_production_context_t context; |
| 743 | if (!cli_activation_production_context_init(&context, action, target_version, target_build)) { |
| 744 | cli_activation_production_context_close(&context); |
| 745 | cli_activation_production_diagnostic(NULL, CLI_ACTIVATION_REFUSED_MESSAGE); |
| 746 | return CLI_TRUE; |
| 747 | } |
| 748 | printf("Stopping active CBM sessions and operations for %s...\n", |
| 749 | cli_activation_action_text(action)); |
| 750 | (void)fflush(stdout); |
| 751 | if (!cli_activation_log_event(&context, "requested", NULL)) { |
| 752 | cli_activation_production_context_close(&context); |
| 753 | (void)fprintf(stderr, "error: activation request could not be recorded safely; " |
| 754 | "no activation was committed.\n"); |
| 755 | return CLI_TRUE; |
| 756 | } |
| 757 | |
| 758 | cbm_cli_activation_ops_t ops = { |
| 759 | .context = &context, |
| 760 | .reserve_for_mutation = cli_activation_production_reserve, |
| 761 | .mutation_lease_release = cli_activation_production_release, |
| 762 | .visible_diagnostic = cli_activation_production_diagnostic, |
| 763 | }; |
| 764 | int rc = cbm_cli_activation_guard_with_ops(&ops, mutation, mutation_context); |
| 765 | if (rc == CLI_OK) { |
| 766 | if (!cli_activation_log_event(&context, "completed", |
| 767 | "activation mutation completed; configuration APIs do not " |
| 768 | "provide an aggregate rollback status")) { |
| 769 | (void)fprintf(stderr, "warning: activation completed, but its final log " |
| 770 | "record could not be written.\n"); |
| 771 | } |
| 772 | } else { |
| 773 | (void)cli_activation_log_event( |
| 774 | &context, "failed", |
| 775 | context.mutation_authorized |
| 776 | ? (rc == CLI_ACTIVATION_PARTIAL |
| 777 | ? "published/current binary retained; agent " |
| 778 | "configuration refresh or cleanup incomplete" |
| 779 | : "activation mutation failed; filesystem writes may " |
| 780 | "have completed") |
| 781 | : "cohort drain or coordination failed"); |
| 782 | } |
| 783 | cli_activation_production_context_close(&context); |
| 784 | if (!context.cleanup_ok) { |
| 785 | (void)fprintf(stderr, "error: activation coordination cleanup failed; restart " |
| 786 | "your coding-agent sessions before retrying.\n"); |
| 787 | return CLI_TRUE; |
| 788 | } |
| 789 | return rc; |
| 790 | } |
| 791 |
no test coverage detected