From: Ray Strode Date: Tue, 19 Aug 2008 18:32:33 +0000 (-0400) Subject: Allow details plugin to work without window X-Git-Tag: 0.6.0~200 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb111dab45c330d5f99c78e742eb49dadaea7ecb;p=thirdparty%2Fplymouth.git Allow details plugin to work without window If it's NULL send a NOANSWER reply to any questions asked by the client and make the client handle NOANSWER by asking the user itself. --- diff --git a/src/client/ply-boot-client.c b/src/client/ply-boot-client.c index 2b1d075a..c6b30751 100644 --- a/src/client/ply-boot-client.c +++ b/src/client/ply-boot-client.c @@ -282,6 +282,10 @@ ply_boot_client_process_incoming_replies (ply_boot_client_t *client) ((ply_boot_client_answer_handler_t) request->handler) (request->user_data, answer, client); } + else if (memcmp (byte, PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER, sizeof (uint8_t)) == 0) + { + ((ply_boot_client_answer_handler_t) request->handler) (request->user_data, NULL, client); + } else goto out; diff --git a/src/client/plymouth.c b/src/client/plymouth.c index c3433787..33deb243 100644 --- a/src/client/plymouth.c +++ b/src/client/plymouth.c @@ -102,9 +102,16 @@ answer_via_command (answer_state_t *answer_state, pid_t pid; int command_input_sender_fd, command_input_receiver_fd; + /* answer may be NULL which means, + * "The daemon can't ask the user questions, + * do all the prompting from the client" + */ + gave_answer = false; - if (!ply_open_unidirectional_pipe (&command_input_sender_fd, - &command_input_receiver_fd)) return false; + if (answer != NULL && + !ply_open_unidirectional_pipe (&command_input_sender_fd, + &command_input_receiver_fd)) + return false; pid = fork (); @@ -114,21 +121,29 @@ answer_via_command (answer_state_t *answer_state, if (pid == 0) { char **args; - close (command_input_sender_fd); args = split_string (answer_state->command, ' '); - dup2 (command_input_receiver_fd, STDIN_FILENO); + if (answer != NULL) + { + close (command_input_sender_fd); + dup2 (command_input_receiver_fd, STDIN_FILENO); + } execvp (args[0], args); ply_trace ("could not run command: %m"); _exit (127); } - close (command_input_receiver_fd); - if (write (command_input_sender_fd, answer, strlen (answer)) < 0) - goto out; + if (answer != NULL) + { + close (command_input_receiver_fd); + + if (write (command_input_sender_fd, answer, strlen (answer)) < 0) + goto out; + } gave_answer = true; out: - close (command_input_sender_fd); + if (answer != NULL) + close (command_input_sender_fd); waitpid (pid, exit_status, 0); return gave_answer; diff --git a/src/ply-boot-protocol.h b/src/ply-boot-protocol.h index 594064a9..852b9d9d 100644 --- a/src/ply-boot-protocol.h +++ b/src/ply-boot-protocol.h @@ -35,6 +35,7 @@ #define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK "\x6" #define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NAK "\x15" #define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER "\x2" +#define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER "\x5" #endif /* PLY_BOOT_PROTOCOL_H */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c index 29f402ed..6e39f864 100644 --- a/src/ply-boot-server.c +++ b/src/ply-boot-server.c @@ -197,21 +197,34 @@ ply_boot_connection_on_password_answer (ply_boot_connection_t *connection, size_t size; - /* FIXME: support up to 4 billion + /* splash plugin isn't able to ask for password, + * punt to client */ - if (strlen (password) > 255) - ply_error ("password to long to fit in buffer"); - - size = (uint8_t) strlen (password); - - if (!ply_write (connection->fd, - PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER, - strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER)) || - !ply_write (connection->fd, - &size, sizeof (uint8_t)) || - !ply_write (connection->fd, - password, size)) - ply_error ("could not write bytes: %m"); + if (password == NULL) + { + if (!ply_write (connection->fd, + PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER, + strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NO_ANSWER))) + ply_error ("could not write bytes: %m"); + } + else + { + /* FIXME: support up to 4 billion + */ + if (strlen (password) > 255) + ply_error ("password to long to fit in buffer"); + + size = (uint8_t) strlen (password); + + if (!ply_write (connection->fd, + PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER, + strlen (PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER)) || + !ply_write (connection->fd, + &size, sizeof (uint8_t)) || + !ply_write (connection->fd, + password, size)) + ply_error ("could not write bytes: %m"); + } ply_answer_free (answer); } diff --git a/src/ply-boot-splash.c b/src/ply-boot-splash.c index 8ccaf6c4..3fd63318 100644 --- a/src/ply-boot-splash.c +++ b/src/ply-boot-splash.c @@ -226,7 +226,7 @@ ply_boot_splash_ask_for_password (ply_boot_splash_t *splash, if (splash->plugin_interface->ask_for_password == NULL) { - ply_answer_with_string (answer, ""); + ply_answer_unknown (answer); return; } diff --git a/src/splash-plugins/details/plugin.c b/src/splash-plugins/details/plugin.c index 3bfb14d6..ae52b152 100644 --- a/src/splash-plugins/details/plugin.c +++ b/src/splash-plugins/details/plugin.c @@ -56,6 +56,10 @@ #define CLEAR_LINE_SEQUENCE "\033[2K\r\n" #define BACKSPACE "\b\033[0K" +void ask_for_password (ply_boot_splash_plugin_t *plugin, + ply_answer_t *answer); + +ply_boot_splash_plugin_interface_t *ply_boot_splash_plugin_get_interface (void); struct _ply_boot_splash_plugin { ply_event_loop_t *loop; @@ -136,17 +140,26 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin, assert (plugin != NULL); - ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT); + if (window != NULL) + { + ply_boot_splash_plugin_interface_t *interface; + + ply_window_set_mode (window, PLY_WINDOW_MODE_TEXT); - ply_window_set_keyboard_input_handler (window, - (ply_window_keyboard_input_handler_t) - on_keyboard_input, plugin); - ply_window_set_backspace_handler (window, - (ply_window_backspace_handler_t) - on_backspace, plugin); - ply_window_set_enter_handler (window, - (ply_window_enter_handler_t) - on_enter, plugin); + ply_window_set_keyboard_input_handler (window, + (ply_window_keyboard_input_handler_t) + on_keyboard_input, plugin); + ply_window_set_backspace_handler (window, + (ply_window_backspace_handler_t) + on_backspace, plugin); + ply_window_set_enter_handler (window, + (ply_window_enter_handler_t) + on_enter, plugin); + + interface = ply_boot_splash_plugin_get_interface (); + + interface->ask_for_password = ask_for_password; + } plugin->loop = loop; @@ -223,7 +236,6 @@ ply_boot_splash_plugin_get_interface (void) .update_status = update_status, .on_boot_output = on_boot_output, .hide_splash_screen = hide_splash_screen, - .ask_for_password = ask_for_password, }; return &plugin_interface;