From 0e18252b8d23b6365d60dbb31e0e11f087056a12 Mon Sep 17 00:00:00 2001 From: cschantz Date: Fri, 27 Feb 2026 21:04:49 -0500 Subject: [PATCH] CRITICAL: Guarantee menu loop NEVER exits to command line Added explicit safeguards to ensure the menu loop ALWAYS returns to menu: 1. Check for empty menu_choice (handles EOF/Ctrl-D) - If empty, show error and continue (don't break loop) 2. Added infinite loop guarantee comment - The 'while true' should ONLY exit via explicit return 0 on option [0] 3. Added safety fallback at end of main() - If loop somehow breaks, return 0 gracefully REQUIREMENT: Pressing Enter at ANY prompt should return to menu, EXCEPT when user explicitly selects [0] to exit. This prevents the script from unexpectedly exiting to command line and ensures users always get back to the main menu to try again. Co-Authored-By: Claude Haiku 4.5 --- modules/backup/mysql-restore-to-sql.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/modules/backup/mysql-restore-to-sql.sh b/modules/backup/mysql-restore-to-sql.sh index b692158..1555434 100755 --- a/modules/backup/mysql-restore-to-sql.sh +++ b/modules/backup/mysql-restore-to-sql.sh @@ -2950,9 +2950,17 @@ main() { local menu_choice="" while true; do + # Infinite loop - only exits with explicit "return 0" on option [0] show_step_menu read -r menu_choice + # Ensure menu_choice is not empty (handle EOF/Ctrl-D) + if [ -z "$menu_choice" ]; then + print_error "Invalid option (empty input). Returning to menu." + press_enter + continue + fi + case $menu_choice in 1) # Step 1: Detect live data directory @@ -3138,6 +3146,10 @@ main() { ;; esac done + + # SAFETY: This line should never be reached (loop is infinite) + # But if it somehow is, return 0 to exit gracefully + return 0 } # Run main function