From: Peter Jones Date: Mon, 9 Jun 2008 19:40:35 +0000 (-0400) Subject: Add "plymouth --newroot=/sysroot" support, and make --sysinit open the log. X-Git-Tag: 0.3.0~31 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=620e9477114c88ca4ac76a0ef76824164bb70ec1;p=thirdparty%2Fplymouth.git Add "plymouth --newroot=/sysroot" support, and make --sysinit open the log. --- diff --git a/src/client/ply-boot-client.c b/src/client/ply-boot-client.c index fc998f1f..e75309de 100644 --- a/src/client/ply-boot-client.c +++ b/src/client/ply-boot-client.c @@ -444,6 +444,20 @@ ply_boot_client_update_daemon (ply_boot_client_t *client, status, handler, failed_handler, user_data); } +void +ply_boot_client_tell_daemon_to_change_root (ply_boot_client_t *client, + const char *root_dir, + ply_boot_client_response_handler_t handler, + ply_boot_client_response_handler_t failed_handler, + void *user_data) +{ + assert (client != NULL); + assert (root_dir != NULL); + + ply_boot_client_queue_request(client, PLY_BOOT_PROTOCOL_REQUEST_TYPE_NEWROOT, + root_dir, handler, failed_handler, user_data); +} + void ply_boot_client_tell_daemon_system_is_initialized (ply_boot_client_t *client, ply_boot_client_response_handler_t handler, @@ -578,6 +592,12 @@ on_update_failed (ply_event_loop_t *loop) ply_event_loop_exit (loop, 1); } +static void +on_newroot (ply_event_loop_t *loop) +{ + printf ("NEWROOT!\n"); +} + static void on_system_initialized (ply_event_loop_t *loop) { diff --git a/src/client/ply-boot-client.h b/src/client/ply-boot-client.h index c3240cd2..8ee6718c 100644 --- a/src/client/ply-boot-client.h +++ b/src/client/ply-boot-client.h @@ -54,6 +54,11 @@ void ply_boot_client_update_daemon (ply_boot_client_t *client, ply_boot_client_response_handler_t handler, ply_boot_client_response_handler_t failed_handler, void *user_data); +void ply_boot_client_tell_daemon_to_change_root (ply_boot_client_t *client, + const char *chroot_dir, + ply_boot_client_response_handler_t handler, + ply_boot_client_response_handler_t failed_handler, + void *user_data); void ply_boot_client_ask_daemon_for_password (ply_boot_client_t *client, ply_boot_client_answer_handler_t handler, ply_boot_client_response_handler_t failed_handler, diff --git a/src/client/plymouth.c b/src/client/plymouth.c index d4d04b25..9d40e147 100644 --- a/src/client/plymouth.c +++ b/src/client/plymouth.c @@ -60,7 +60,7 @@ on_disconnect (ply_event_loop_t *loop) void print_usage (void) { - ply_log ("plymouth [--ping] [--update=STATUS] [--show-splash] [--details] [--sysinit] [--quit]"); + ply_log ("plymouth [--ping] [--update=STATUS] [--show-splash] [--details] [--newroot=] [--sysinit] [--quit]"); ply_flush_log (); } @@ -72,7 +72,7 @@ main (int argc, ply_boot_client_t *client; ply_command_parser_t *command_parser; bool should_help, should_quit, should_ping, should_sysinit, should_ask_for_password, should_show_splash; - char *status; + char *status, *chroot_dir; int exit_code; int i; @@ -90,6 +90,7 @@ main (int argc, ply_command_parser_add_options (command_parser, "help", "This help message", PLY_COMMAND_OPTION_TYPE_FLAG, + "newroot", "Tell boot daemon that new root filesystem is mounted", PLY_COMMAND_OPTION_TYPE_STRING, "quit", "Tell boot daemon to quit", PLY_COMMAND_OPTION_TYPE_BOOLEAN, "sysinit", "Tell boot daemon root filesystem is mounted read-write", PLY_COMMAND_OPTION_TYPE_BOOLEAN, "show-splash", "Show splash screen", PLY_COMMAND_OPTION_TYPE_BOOLEAN, @@ -111,6 +112,7 @@ main (int argc, ply_command_parser_get_options (command_parser, "help", &should_help, + "newroot", &chroot_dir, "quit", &should_quit, "sysinit", &should_sysinit, "show-splash", &should_show_splash, @@ -188,6 +190,12 @@ main (int argc, on_success, (ply_boot_client_response_handler_t) on_failure, loop); + else if (chroot_dir) + ply_boot_client_tell_daemon_to_change_root (client, chroot_dir, + (ply_boot_client_response_handler_t) + on_success, + (ply_boot_client_response_handler_t) + on_failure, loop); else return 1; diff --git a/src/main.c b/src/main.c index 9b0d1cf2..16812a95 100644 --- a/src/main.c +++ b/src/main.c @@ -103,14 +103,22 @@ on_ask_for_password (state_t *state, } static void -on_system_initialized (state_t *state) +on_newroot (state_t *state, + const char *root_dir) { - - ply_trace ("system now initialized, preparing for root filesystem switch"); - chdir("/sysroot"); + ply_trace ("new root mounted, switching to it"); + chdir(root_dir); chroot("."); } +static void +on_system_initialized (state_t *state) +{ + ply_trace ("system now initialized, opening boot.log"); + ply_terminal_session_open_log (state->session, + "/var/log/boot.log"); +} + static void on_show_splash (state_t *state) { @@ -133,9 +141,7 @@ on_show_splash (state_t *state) static void on_quit (state_t *state) { - ply_trace ("time to quit, writing boot.log"); - ply_terminal_session_open_log (state->session, - "/var/log/boot.log"); + ply_trace ("time to quit, closing boot.log"); ply_terminal_session_close_log (state->session); ply_trace ("hiding splash"); if (state->boot_splash != NULL) @@ -152,6 +158,7 @@ start_boot_server (state_t *state) server = ply_boot_server_new ((ply_boot_server_update_handler_t) on_update, (ply_boot_server_ask_for_password_handler_t) on_ask_for_password, (ply_boot_server_show_splash_handler_t) on_show_splash, + (ply_boot_server_newroot_handler_t) on_newroot, (ply_boot_server_system_initialized_handler_t) on_system_initialized, (ply_boot_server_quit_handler_t) on_quit, state); diff --git a/src/ply-boot-protocol.h b/src/ply-boot-protocol.h index 5814a47d..de316992 100644 --- a/src/ply-boot-protocol.h +++ b/src/ply-boot-protocol.h @@ -29,6 +29,7 @@ #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_QUIT "Q" #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_PASSWORD "*" #define PLY_BOOT_PROTOCOL_REQUEST_TYPE_SHOW_SPLASH "$" +#define PLY_BOOT_PROTOCOL_REQUEST_TYPE_NEWROOT "R" #define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ACK "\x6" #define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_NAK "\x15" #define PLY_BOOT_PROTOCOL_RESPONSE_TYPE_ANSWER "\x2" diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c index ec0f0cea..7b4cce19 100644 --- a/src/ply-boot-server.c +++ b/src/ply-boot-server.c @@ -50,6 +50,7 @@ struct _ply_boot_server int socket_fd; ply_boot_server_update_handler_t update_handler; + ply_boot_server_newroot_handler_t newroot_handler; ply_boot_server_system_initialized_handler_t system_initialized_handler; ply_boot_server_show_splash_handler_t show_splash_handler; ply_boot_server_ask_for_password_handler_t ask_for_password_handler; @@ -63,6 +64,7 @@ ply_boot_server_t * ply_boot_server_new (ply_boot_server_update_handler_t update_handler, ply_boot_server_ask_for_password_handler_t ask_for_password_handler, ply_boot_server_show_splash_handler_t show_splash_handler, + ply_boot_server_newroot_handler_t newroot_handler, ply_boot_server_system_initialized_handler_t initialized_handler, ply_boot_server_quit_handler_t quit_handler, void *user_data) @@ -272,6 +274,11 @@ ply_boot_connection_on_request (ply_boot_connection_t *connection) */ return; } + else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_NEWROOT) != 0) + { + if (server->newroot_handler != NULL) + server->newroot_handler(server->user_data, argument, server); + } else if (strcmp (command, PLY_BOOT_PROTOCOL_REQUEST_TYPE_PING) != 0) { ply_error ("received unknown command '%s' from client", command); @@ -388,6 +395,12 @@ on_update (ply_event_loop_t *loop, printf ("new status is '%s'\n", status); } +static void +on_newroot (ply_event_loop_t *loop) +{ + printf ("got newroot request\n"); +} + static void on_system_initialized (ply_event_loop_t *loop) { @@ -430,6 +443,7 @@ main (int argc, server = ply_boot_server_new ((ply_boot_server_update_handler_t) on_update, (ply_boot_server_ask_for_password_handler_t) on_ask_for_password, (ply_boot_server_show_splash_handler_t) on_show_splash, + (ply_boot_server_newroot_handler_t) on_newroot, (ply_boot_server_system_initialized_handler_t) on_system_initialized, (ply_boot_server_quit_handler_t) on_quit, loop); diff --git a/src/ply-boot-server.h b/src/ply-boot-server.h index a8eb7b2e..d2e2418b 100644 --- a/src/ply-boot-server.h +++ b/src/ply-boot-server.h @@ -36,6 +36,10 @@ typedef void (* ply_boot_server_update_handler_t) (void *user_data, const char *status, ply_boot_server_t *server); +typedef void (* ply_boot_server_newroot_handler_t) (void *user_data, + const char *root_dir, + ply_boot_server_t *server); + typedef void (* ply_boot_server_show_splash_handler_t) (void *user_data, ply_boot_server_t *server); @@ -56,6 +60,7 @@ typedef void (* ply_boot_server_quit_handler_t) (void *user_data, ply_boot_server_t *ply_boot_server_new (ply_boot_server_update_handler_t update_handler, ply_boot_server_ask_for_password_handler_t ask_for_password_handler, ply_boot_server_show_splash_handler_t show_splash_handler, + ply_boot_server_newroot_handler_t newroot_handler, ply_boot_server_system_initialized_handler_t initialized_handler, ply_boot_server_quit_handler_t quit_handler, void *user_data);