mirror of
https://gitlab.freedesktop.org/plymouth/plymouth.git
synced 2026-05-05 00:38:10 +02:00
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.
This commit is contained in:
parent
31f121080d
commit
cb111dab45
6 changed files with 77 additions and 32 deletions
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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: */
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
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);
|
||||
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 (!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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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_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_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);
|
||||
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue