From: Charlie Brej Date: Sat, 3 Jan 2009 15:58:39 +0000 (+0000) Subject: Make Ctrl+C and Ctrl+D cause the password/question entry to quit X-Git-Tag: 0.7.0~234 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e2404b991adb7b694fa7d35b52af53fc32790dbc;p=thirdparty%2Fplymouth.git Make Ctrl+C and Ctrl+D cause the password/question entry to quit When asking for a password or a question, if the user presses Ctrl+C or Ctrl+D the backend will reply a NULL. This is interprited as a "Stop asking me". The client will not repeat the request (even if number of retries hasn't been reached) and quit with an error exit_status. --- diff --git a/src/client/plymouth.c b/src/client/plymouth.c index 7128264d..c181dadc 100644 --- a/src/client/plymouth.c +++ b/src/client/plymouth.c @@ -178,34 +178,39 @@ on_password_answer (password_answer_state_t *answer_state, { int exit_status; - exit_status = 0; - if (answer_state->command != NULL) + exit_status = 127; + if (answer != NULL) /* a NULL answer means the user quit */ { - bool command_started = false; - - exit_status = 127; - command_started = answer_via_command (answer_state->command, answer, - &exit_status); - - if (command_started && (!WIFEXITED (exit_status) || - WEXITSTATUS (exit_status) != 0)) + if (answer_state->command != NULL) { - answer_state->number_of_tries_left--; + bool command_started = false; - if (answer_state->number_of_tries_left > 0) + command_started = answer_via_command (answer_state->command, answer, + &exit_status); + + if (command_started && (!WIFEXITED (exit_status) || + WEXITSTATUS (exit_status) != 0)) { - ply_boot_client_ask_daemon_for_password (answer_state->state->client, - answer_state->prompt, - (ply_boot_client_answer_handler_t) - on_password_answer, - (ply_boot_client_response_handler_t) - on_password_answer_failure, answer_state); - return; + answer_state->number_of_tries_left--; + + if (answer_state->number_of_tries_left > 0) + { + ply_boot_client_ask_daemon_for_password (answer_state->state->client, + answer_state->prompt, + (ply_boot_client_answer_handler_t) + on_password_answer, + (ply_boot_client_response_handler_t) + on_password_answer_failure, answer_state); + return; + } } } + else + { + write (STDOUT_FILENO, answer, strlen (answer)); + exit_status = 0; + } } - else - write (STDOUT_FILENO, answer, strlen (answer)); if (WIFSIGNALED (exit_status)) raise (WTERMSIG (exit_status)); @@ -218,19 +223,20 @@ on_question_answer (question_answer_state_t *answer_state, const char *answer, ply_boot_client_t *client) { - if (answer_state->command != NULL) + if (answer != NULL) { - answer_via_command (answer_state->command, answer, NULL); + if (answer_state->command != NULL) + { + answer_via_command (answer_state->command, answer, NULL); + } + else + { + write (STDOUT_FILENO, answer, strlen (answer)); + } + ply_event_loop_exit (answer_state->state->loop, 0); } else - { - if (answer) - write (STDOUT_FILENO, answer, strlen (answer)); - } - - if (answer) - ply_event_loop_exit (answer_state->state->loop, 0); - ply_event_loop_exit (answer_state->state->loop, 1); + ply_event_loop_exit (answer_state->state->loop, 1); } static void diff --git a/src/main.c b/src/main.c index 003a59b6..fa612ed8 100644 --- a/src/main.c +++ b/src/main.c @@ -630,8 +630,19 @@ on_keyboard_input (state_t *state, ply_list_node_t *node; node = ply_list_get_first_node (state->entry_triggers); if (node) - { - ply_buffer_append_bytes (state->entry_buffer, keyboard_input, character_size); + { /* \x3 (ETX) is Ctrl+C and \x4 (EOT) is Ctrl+D */ + if (character_size == 1 && ( keyboard_input[0] == '\x3' || keyboard_input[0] == '\x4' )) + { + ply_entry_trigger_t* entry_trigger = ply_list_node_get_data (node); + ply_trigger_pull (entry_trigger->trigger, NULL); + ply_buffer_clear (state->entry_buffer); + ply_list_remove_node (state->entry_triggers, node); + free (entry_trigger); + } + else + { + ply_buffer_append_bytes (state->entry_buffer, keyboard_input, character_size); + } update_display (state); } else @@ -651,6 +662,7 @@ on_keyboard_input (state_t *state, return; } } + void on_backspace (state_t *state) { @@ -686,12 +698,11 @@ on_enter (state_t *state, ply_trigger_pull (entry_trigger->trigger, reply_text); ply_buffer_clear (state->entry_buffer); ply_list_remove_node (state->entry_triggers, node); - free(entry_trigger); + free (entry_trigger); update_display (state); } } - static ply_window_t * create_window (state_t *state, const char *tty_name)