From 63e9b4faee93a4f4ff4e504e5a4f1148c095d8b6 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 27 Nov 2013 00:07:54 -0500 Subject: [PATCH 01/32] main: drop parameters for check_for_consoles function both the default tty and whether or not displays should be added are available in the global state object (as state->default_tty and state->is_shown respectively), so they don't need to be parameters. The latter one was a boolean, so having it as a parameter was confusing at the call sites. This commit drops the parameters. --- src/main.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/src/main.c b/src/main.c index 9c450c0c..17dd23a3 100644 --- a/src/main.c +++ b/src/main.c @@ -146,9 +146,7 @@ static void on_error_message (ply_buffer_t *debug_buffer, static ply_buffer_t *debug_buffer; static char *debug_buffer_path = NULL; static char *pid_file = NULL; -static void check_for_consoles (state_t *state, - const char *default_tty, - bool should_add_displays); +static void check_for_consoles (state_t *state); static void toggle_between_splash_and_details (state_t *state); #ifdef PLY_ENABLE_SYSTEMD_INTEGRATION static void tell_systemd_to_print_details (state_t *state); @@ -891,7 +889,7 @@ on_show_splash (state_t *state) state->is_shown = true; - check_for_consoles (state, state->default_tty, true); + check_for_consoles (state); has_display = ply_list_get_length (state->pixel_displays) > 0 || ply_list_get_length (state->text_displays) > 0; @@ -2115,9 +2113,7 @@ add_consoles_from_kernel_command_line (state_t *state, } static void -check_for_consoles (state_t *state, - const char *default_tty, - bool should_add_displays) +check_for_consoles (state_t *state) { char *console; ply_hashtable_t *consoles; @@ -2125,7 +2121,7 @@ check_for_consoles (state_t *state, bool ignore_serial_consoles; ply_trace ("checking for consoles%s", - should_add_displays? " and adding displays": ""); + state->is_shown? " and adding displays": ""); consoles = ply_hashtable_new (ply_hashtable_string_hash, ply_hashtable_string_compare); @@ -2152,7 +2148,7 @@ check_for_consoles (state_t *state, if (console != NULL) { free (console); - console = strdup (default_tty); + console = strdup (state->default_tty); ply_hashtable_insert (consoles, console, console); } @@ -2160,7 +2156,7 @@ check_for_consoles (state_t *state, if (console != NULL) { free (console); - console = strdup (default_tty); + console = strdup (state->default_tty); ply_hashtable_insert (consoles, console, console); } @@ -2170,14 +2166,14 @@ check_for_consoles (state_t *state, if (console != NULL) state->kernel_console_tty = strdup (console); - if (should_add_displays) + if (state->is_shown) { /* Do a full graphical splash if there's no weird serial console * stuff going on, otherwise just prepare text splashes */ if ((num_consoles == 0) || ((num_consoles == 1) && - (ply_hashtable_lookup (consoles, (void *) default_tty) != NULL))) + (ply_hashtable_lookup (consoles, (void *) state->default_tty) != NULL))) add_default_displays_and_keyboard (state); else ply_hashtable_foreach (consoles, @@ -2279,8 +2275,7 @@ initialize_environment (state_t *state) state->messages = ply_list_new (); state->keyboard = NULL; - - check_for_consoles (state, state->default_tty, false); + check_for_consoles (state); redirect_standard_io_to_dev_null (); From 6b2b068e04b2f9e345d8831ba59ffb3c18329a03 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 27 Nov 2013 00:24:54 -0500 Subject: [PATCH 02/32] main: drop kernel_console_tty We aren't actually really using it anymore. It gets checked in on place in the debugging code, but only before it's set. This commit drops it. --- src/main.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/main.c b/src/main.c index 17dd23a3..6e774ba2 100644 --- a/src/main.c +++ b/src/main.c @@ -116,7 +116,6 @@ typedef struct uint32_t is_shown : 1; uint32_t should_force_details : 1; - char *kernel_console_tty; char *override_splash_path; char *system_default_splash_path; char *distribution_default_splash_path; @@ -1902,10 +1901,7 @@ check_verbosity (state_t *state) const char* device; char *file; - if (state->kernel_console_tty != NULL) - device = state->kernel_console_tty; - else - device = state->default_tty; + device = state->default_tty; ply_trace ("redirecting debug output to %s", device); @@ -2160,12 +2156,6 @@ check_for_consoles (state_t *state) ply_hashtable_insert (consoles, console, console); } - free (state->kernel_console_tty); - state->kernel_console_tty = NULL; - - if (console != NULL) - state->kernel_console_tty = strdup (console); - if (state->is_shown) { /* Do a full graphical splash if there's no weird serial console From 43583e44dc3b299f0be43fe883758eec5f852017 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Wed, 27 Nov 2013 00:26:45 -0500 Subject: [PATCH 03/32] main: drop check_for_consoles call at startup It was only used to make kernel_console_tty get set, which we no longer have. --- src/main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main.c b/src/main.c index 6e774ba2..4dceb9ab 100644 --- a/src/main.c +++ b/src/main.c @@ -2265,8 +2265,6 @@ initialize_environment (state_t *state) state->messages = ply_list_new (); state->keyboard = NULL; - check_for_consoles (state); - redirect_standard_io_to_dev_null (); ply_trace ("Making sure " PLYMOUTH_RUNTIME_DIR " exists"); From 67addd18e3cd04be2955435d06ae8b5b1fc03b18 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Fri, 29 Nov 2013 23:02:34 -0500 Subject: [PATCH 04/32] renderer: use enum for selecting renderer type, not plugin path ply_renderer_new takes a path to a renderer plugin, or NULL to try each one in turn. It's cleaner to abstract the path behind an enum type, so this commit makes that change. Now it will be possible to instantiate specific renderers without hardcoding the paths to plugins in more than one place. --- src/libply-splash-core/ply-boot-splash.c | 2 +- src/libply-splash-core/ply-renderer.c | 45 +++++++++++------------- src/libply-splash-core/ply-renderer.h | 11 +++++- src/main.c | 2 +- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/src/libply-splash-core/ply-boot-splash.c b/src/libply-splash-core/ply-boot-splash.c index 93d93450..7e69675f 100644 --- a/src/libply-splash-core/ply-boot-splash.c +++ b/src/libply-splash-core/ply-boot-splash.c @@ -914,7 +914,7 @@ main (int argc, return errno; } - renderer = ply_renderer_new (NULL, terminal); + renderer = ply_renderer_new (PLY_RENDERER_TYPE_AUTO, NULL, terminal); free(tty_name); if (!ply_renderer_open (renderer)) diff --git a/src/libply-splash-core/ply-renderer.c b/src/libply-splash-core/ply-renderer.c index 3559e013..39fbf9ab 100644 --- a/src/libply-splash-core/ply-renderer.c +++ b/src/libply-splash-core/ply-renderer.c @@ -49,7 +49,7 @@ struct _ply_renderer const ply_renderer_plugin_interface_t *plugin_interface; ply_renderer_backend_t *backend; - char *plugin_path; + ply_renderer_type_t type; char *device_name; ply_terminal_t *terminal; @@ -63,16 +63,15 @@ typedef const ply_renderer_plugin_interface_t * static void ply_renderer_unload_plugin (ply_renderer_t *renderer); ply_renderer_t * -ply_renderer_new (const char *plugin_path, - const char *device_name, - ply_terminal_t *terminal) +ply_renderer_new (ply_renderer_type_t renderer_type, + const char *device_name, + ply_terminal_t *terminal) { ply_renderer_t *renderer; renderer = calloc (1, sizeof (struct _ply_renderer)); - if (plugin_path != NULL) - renderer->plugin_path = strdup (plugin_path); + renderer->type = renderer_type; if (device_name != NULL) renderer->device_name = strdup (device_name); @@ -95,7 +94,6 @@ ply_renderer_free (ply_renderer_t *renderer) } free (renderer->device_name); - free (renderer->plugin_path); free (renderer); } @@ -258,29 +256,28 @@ ply_renderer_open (ply_renderer_t *renderer) { int i; - /* FIXME: at some point we may want to make this - * part more dynamic (so you don't have to edit this - * list to add a new renderer) - */ - const char *known_plugins[] = + struct { - PLYMOUTH_PLUGIN_PATH "renderers/x11.so", - PLYMOUTH_PLUGIN_PATH "renderers/drm.so", - PLYMOUTH_PLUGIN_PATH "renderers/frame-buffer.so", - NULL + ply_renderer_type_t type; + const char *path; + } known_plugins[] = + { + { PLY_RENDERER_TYPE_X11, PLYMOUTH_PLUGIN_PATH "renderers/x11.so" }, + { PLY_RENDERER_TYPE_DRM, PLYMOUTH_PLUGIN_PATH "renderers/drm.so" }, + { PLY_RENDERER_TYPE_FRAME_BUFFER, PLYMOUTH_PLUGIN_PATH "renderers/frame-buffer.so" }, + { PLY_RENDERER_TYPE_NONE, NULL } }; - if (renderer->plugin_path != NULL) + for (i = 0; known_plugins[i].type != PLY_RENDERER_TYPE_NONE; i++) { - return ply_renderer_open_plugin (renderer, renderer->plugin_path); + if (renderer->type == known_plugins[i].type || + renderer->type == PLY_RENDERER_TYPE_AUTO) + { + if (ply_renderer_open_plugin (renderer, known_plugins[i].path)) + return true; + } } - for (i = 0; known_plugins[i] != NULL; i++) - { - if (ply_renderer_open_plugin (renderer, known_plugins[i])) - return true; - } - ply_trace ("could not find suitable rendering plugin"); return false; } diff --git a/src/libply-splash-core/ply-renderer.h b/src/libply-splash-core/ply-renderer.h index 4b3bd1a3..75c39fab 100644 --- a/src/libply-splash-core/ply-renderer.h +++ b/src/libply-splash-core/ply-renderer.h @@ -35,12 +35,21 @@ typedef struct _ply_renderer ply_renderer_t; typedef struct _ply_renderer_head ply_renderer_head_t; typedef struct _ply_renderer_input_source ply_renderer_input_source_t; +typedef enum +{ + PLY_RENDERER_TYPE_NONE = -1, + PLY_RENDERER_TYPE_AUTO, + PLY_RENDERER_TYPE_DRM, + PLY_RENDERER_TYPE_FRAME_BUFFER, + PLY_RENDERER_TYPE_X11 +} ply_renderer_type_t; + typedef void (* ply_renderer_input_source_handler_t) (void *user_data, ply_buffer_t *key_buffer, ply_renderer_input_source_t *input_source); #ifndef PLY_HIDE_FUNCTION_DECLARATIONS -ply_renderer_t *ply_renderer_new (const char *plugin_path, +ply_renderer_t *ply_renderer_new (ply_renderer_type_t renderer_type, const char *device_name, ply_terminal_t *terminal); void ply_renderer_free (ply_renderer_t *renderer); diff --git a/src/main.c b/src/main.c index 4dceb9ab..6ef7bff2 100644 --- a/src/main.c +++ b/src/main.c @@ -1577,7 +1577,7 @@ add_default_displays_and_keyboard (state_t *state) state->local_console_terminal = ply_terminal_new (state->default_tty); - renderer = ply_renderer_new (NULL, NULL, state->local_console_terminal); + renderer = ply_renderer_new (PLY_RENDERER_TYPE_AUTO, NULL, state->local_console_terminal); if (!ply_renderer_open (renderer)) { From c72bf93546912b59ac819e473c58cb55e41b3a4d Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Sat, 30 Nov 2013 20:34:24 -0500 Subject: [PATCH 05/32] terminal: add new get_name() method The name is passed in at construct time, but it gets canonicalized. This commit adds api to get the final name. The api is also useful, since it prevents callers that need the mapping from having to maintain it separately, which will be good for a future clean up. --- src/libply-splash-core/ply-terminal.c | 6 ++++++ src/libply-splash-core/ply-terminal.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/libply-splash-core/ply-terminal.c b/src/libply-splash-core/ply-terminal.c index 2e95dc8c..992dd3f3 100644 --- a/src/libply-splash-core/ply-terminal.c +++ b/src/libply-splash-core/ply-terminal.c @@ -876,6 +876,12 @@ ply_terminal_free (ply_terminal_t *terminal) free (terminal); } +const char * +ply_terminal_get_name (ply_terminal_t *terminal) +{ + return terminal->name; +} + int ply_terminal_get_vt_number (ply_terminal_t *terminal) { diff --git a/src/libply-splash-core/ply-terminal.h b/src/libply-splash-core/ply-terminal.h index 8b4b0177..48b4f77f 100644 --- a/src/libply-splash-core/ply-terminal.h +++ b/src/libply-splash-core/ply-terminal.h @@ -91,6 +91,7 @@ void ply_terminal_set_mode (ply_terminal_t *terminal, void ply_terminal_ignore_mode_changes (ply_terminal_t *terminal, bool should_ignore); +const char *ply_terminal_get_name (ply_terminal_t *terminal); int ply_terminal_get_vt_number (ply_terminal_t *terminal); bool ply_terminal_activate_vt (ply_terminal_t *terminal); bool ply_terminal_deactivate_vt (ply_terminal_t *terminal); From 27f0711414d69626756cbb4b87970c0b6400c14f Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Sun, 1 Dec 2013 18:58:02 -0500 Subject: [PATCH 06/32] hashtable: add get_size method Right now there's no easy way to know if a hash table is empty, which I'm going to need in a future commit. This commit adds a get_size method to return the number of items in the hash table. --- src/libply/ply-hashtable.c | 5 +++++ src/libply/ply-hashtable.h | 2 ++ 2 files changed, 7 insertions(+) diff --git a/src/libply/ply-hashtable.c b/src/libply/ply-hashtable.c index 7d8d648e..7f20a534 100644 --- a/src/libply/ply-hashtable.c +++ b/src/libply/ply-hashtable.c @@ -281,6 +281,11 @@ ply_hashtable_foreach (ply_hashtable_t *hashtable, } } +int +ply_hashtable_get_size (ply_hashtable_t *hashtable) +{ + return hashtable->live_node_count; +} #ifdef PLY_HASHTABLE_ENABLE_TEST #include diff --git a/src/libply/ply-hashtable.h b/src/libply/ply-hashtable.h index 016c781e..e7e1a6eb 100644 --- a/src/libply/ply-hashtable.h +++ b/src/libply/ply-hashtable.h @@ -57,6 +57,8 @@ int ply_hashtable_lookup_full (ply_hashtable_t *hashtable, void ply_hashtable_foreach (ply_hashtable_t *hashtable, ply_hashtable_foreach_func_t func, void *user_data); + +int ply_hashtable_get_size (ply_hashtable_t *hashtable); #endif #endif /* PLY_HASHTABLE_H */ From a20a99790ca0ac7df57c8e93d56706210ab12c8b Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Sat, 30 Nov 2013 20:57:52 -0500 Subject: [PATCH 07/32] main: maintain better accounting of terminals Currently terminals are created in the main file and passed down to other layers, with no direct reference maintained in the main file. There are points when we need to get references to all those terminals again, and we have to fish them out from other layers. This commit makes it all more explicit, maintaining the terminals in a hash table in the main state object. --- src/main.c | 190 +++++++++++++++++++++-------------------------------- 1 file changed, 76 insertions(+), 114 deletions(-) diff --git a/src/main.c b/src/main.c index 6ef7bff2..715e5bdc 100644 --- a/src/main.c +++ b/src/main.c @@ -84,6 +84,7 @@ typedef struct { ply_event_loop_t *loop; ply_boot_server_t *boot_server; + ply_hashtable_t *terminals; ply_list_t *pixel_displays; ply_list_t *text_displays; ply_keyboard_t *keyboard; @@ -153,6 +154,58 @@ static void tell_systemd_to_stop_printing_details (state_t *state); #endif static const char * get_cache_file_for_mode (ply_mode_t mode); +static void +free_terminal (char *device, + ply_terminal_t *terminal, + state_t *state) +{ + ply_hashtable_remove (state->terminals, device); + + ply_terminal_close (terminal); + ply_terminal_free (terminal); +} + +static void +free_terminals (state_t *state) +{ + ply_hashtable_foreach (state->terminals, + (ply_hashtable_foreach_func_t *) + free_terminal, + state); +} + +static ply_terminal_t * +get_terminal (state_t *state, + const char *device_name) +{ + char *full_name; + ply_terminal_t *terminal; + + if (strncmp (device_name, "/dev/", strlen ("/dev/")) == 0) + full_name = strdup (device_name); + else + asprintf (&full_name, "/dev/%s", device_name); + + if (strcmp (full_name, "/dev/tty0") == 0 || + strcmp (full_name, "/dev/tty") == 0) + { + free (full_name); + full_name = strdup (state->default_tty); + } + + terminal = ply_hashtable_lookup (state->terminals, full_name); + + if (terminal == NULL) + { + terminal = ply_terminal_new (full_name); + + ply_hashtable_insert (state->terminals, (void *) ply_terminal_get_name (terminal), terminal); + } + free (full_name); + + return terminal; +} + static void on_session_output (state_t *state, const char *output, @@ -915,62 +968,9 @@ on_show_splash (state_t *state) show_messages (state); } -static ply_list_t * -get_tracked_terminals (state_t *state) -{ - ply_list_t *terminals; - ply_list_node_t *node; - - terminals = ply_list_new (); - - node = ply_list_get_first_node (state->text_displays); - while (node != NULL) - { - ply_list_node_t *next_node; - ply_text_display_t *display; - ply_terminal_t *terminal; - - next_node = ply_list_get_next_node (state->text_displays, node); - display = ply_list_node_get_data (node); - terminal = ply_text_display_get_terminal (display); - - ply_list_append_data (terminals, terminal); - - node = next_node; - } - - return terminals; -} - -static void -free_terminals (state_t *state, - ply_list_t *terminals) -{ - ply_list_node_t *node; - node = ply_list_get_first_node (terminals); - while (node != NULL) - { - ply_list_node_t *next_node; - ply_terminal_t *terminal; - - next_node = ply_list_get_next_node (state->text_displays, node); - terminal = ply_list_node_get_data (node); - - ply_terminal_close (terminal); - ply_terminal_free (terminal); - ply_list_remove_node (terminals, node); - - node = next_node; - } - - ply_list_free (terminals); -} - static void quit_splash (state_t *state) { - ply_list_t *terminals; - ply_trace ("quiting splash"); if (state->boot_splash != NULL) { @@ -979,8 +979,6 @@ quit_splash (state_t *state) state->boot_splash = NULL; } - terminals = get_tracked_terminals (state); - ply_trace ("removing displays and keyboard"); remove_displays_and_keyboard (state); @@ -1000,7 +998,8 @@ quit_splash (state_t *state) } state->local_console_terminal = NULL; } - free_terminals (state, terminals); + + free_terminals (state); detach_from_running_session (state); } @@ -1575,7 +1574,7 @@ add_default_displays_and_keyboard (state_t *state) ply_trace ("adding default displays and keyboard"); - state->local_console_terminal = ply_terminal_new (state->default_tty); + state->local_console_terminal = get_terminal (state, state->default_tty); renderer = ply_renderer_new (PLY_RENDERER_TYPE_AUTO, NULL, state->local_console_terminal); @@ -1957,24 +1956,19 @@ check_logging (state_t *state) } static void -add_display_and_keyboard_for_console (const char *console, - const char *null, - state_t *state) +add_display_and_keyboard_for_console (const char *name, + ply_terminal_t *terminal, + state_t *state) { - ply_terminal_t *terminal; - - terminal = ply_terminal_new (console); - - if (strcmp (console, state->default_tty) == 0) + if (strcmp (name, state->default_tty) == 0) state->local_console_terminal = terminal; - ply_trace ("adding display and keyboard for console %s", console); + ply_trace ("adding display and keyboard for console %s", name); add_display_and_keyboard_for_terminal (state, terminal); } static int add_consoles_from_file (state_t *state, - ply_hashtable_t *consoles, const char *path) { int fd; @@ -2010,7 +2004,8 @@ add_consoles_from_file (state_t *state, { char *console; size_t console_length; - char *console_device; + const char *console_device; + ply_terminal_t *terminal; /* Advance past any leading whitespace */ remaining_file_contents += strspn (remaining_file_contents, " \n\t\v"); @@ -2035,12 +2030,12 @@ add_consoles_from_file (state_t *state, if (strcmp (console, "tty0") != 0) state->should_force_details = true; - asprintf (&console_device, "/dev/%s", console); + terminal = get_terminal (state, console); + console_device = ply_terminal_get_name (terminal); free (console); ply_trace ("console %s found!", console_device); - ply_hashtable_insert (consoles, console_device, console_device); num_consoles++; /* Move past the parsed console string, and the whitespace we @@ -2055,8 +2050,7 @@ add_consoles_from_file (state_t *state, } static int -add_consoles_from_kernel_command_line (state_t *state, - ply_hashtable_t *consoles) +add_consoles_from_kernel_command_line (state_t *state) { const char *console_string; const char *remaining_command_line; @@ -2072,7 +2066,8 @@ add_consoles_from_kernel_command_line (state_t *state, { char *end; size_t console_length; - char *console_device; + const char *console_device; + ply_terminal_t *terminal; remaining_command_line = console_string; @@ -2087,20 +2082,10 @@ add_consoles_from_kernel_command_line (state_t *state, console_length = strlen (console); - if (strncmp (console, "/dev/", strlen ("/dev/")) == 0) - { - console_device = console; - console = NULL; - } - else - { - asprintf (&console_device, "/dev/%s", console); - free (console); - console = NULL; - } + terminal = get_terminal (state, console); + console_device = ply_terminal_get_name (terminal); ply_trace ("console %s found!", console_device); - ply_hashtable_insert (consoles, console_device, console_device); num_consoles++; remaining_command_line += console_length; } @@ -2111,49 +2096,30 @@ add_consoles_from_kernel_command_line (state_t *state, static void check_for_consoles (state_t *state) { - char *console; - ply_hashtable_t *consoles; int num_consoles; bool ignore_serial_consoles; ply_trace ("checking for consoles%s", state->is_shown? " and adding displays": ""); - consoles = ply_hashtable_new (ply_hashtable_string_hash, - ply_hashtable_string_compare); ignore_serial_consoles = command_line_has_argument (state->kernel_command_line, "plymouth.ignore-serial-consoles"); num_consoles = 0; if (!ignore_serial_consoles) { - num_consoles = add_consoles_from_file (state, consoles, "/sys/class/tty/console/active"); + num_consoles = add_consoles_from_file (state, "/sys/class/tty/console/active"); if (num_consoles == 0) { ply_trace ("falling back to kernel command line"); - num_consoles = add_consoles_from_kernel_command_line (state, consoles); + num_consoles = add_consoles_from_kernel_command_line (state); } } else { ply_trace ("ignoring all consoles but default console because of plymouth.ignore-serial-consoles"); - } - - console = ply_hashtable_remove (consoles, (void *) "/dev/tty0"); - if (console != NULL) - { - free (console); - console = strdup (state->default_tty); - ply_hashtable_insert (consoles, console, console); - } - - console = ply_hashtable_remove (consoles, (void *) "/dev/tty"); - if (console != NULL) - { - free (console); - console = strdup (state->default_tty); - ply_hashtable_insert (consoles, console, console); + get_terminal (state, state->default_tty); } if (state->is_shown) @@ -2161,20 +2127,15 @@ check_for_consoles (state_t *state) /* Do a full graphical splash if there's no weird serial console * stuff going on, otherwise just prepare text splashes */ - if ((num_consoles == 0) || - ((num_consoles == 1) && - (ply_hashtable_lookup (consoles, (void *) state->default_tty) != NULL))) + if (num_consoles <= 1) add_default_displays_and_keyboard (state); else - ply_hashtable_foreach (consoles, + ply_hashtable_foreach (state->terminals, (ply_hashtable_foreach_func_t *) add_display_and_keyboard_for_console, state); } - ply_hashtable_foreach (consoles, (ply_hashtable_foreach_func_t *) free, NULL); - ply_hashtable_free (consoles); - ply_trace ("After processing serial consoles there are now %d text displays", ply_list_get_length (state->text_displays)); } @@ -2260,6 +2221,7 @@ initialize_environment (state_t *state) state->keystroke_triggers = ply_list_new (); state->entry_triggers = ply_list_new (); state->entry_buffer = ply_buffer_new(); + state->terminals = ply_hashtable_new (ply_hashtable_string_hash, ply_hashtable_string_compare); state->pixel_displays = ply_list_new (); state->text_displays = ply_list_new (); state->messages = ply_list_new (); From ca0b7cc87d1f4d45cbdc5de2385ab3f554c09592 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 2 Dec 2013 21:13:28 -0500 Subject: [PATCH 08/32] boot-splash: drop debugging keybindings The boot splash currently lets the user hit ctrl-L to refresh, ctrl-T to force text mode, and ctrl-V to toggle verbose messages. These easter eggs are undocumented and really only used when I was first writing plymouth. These days it's just taking up space, so drop it. --- src/libply-splash-core/ply-boot-splash.c | 102 ----------------------- 1 file changed, 102 deletions(-) diff --git a/src/libply-splash-core/ply-boot-splash.c b/src/libply-splash-core/ply-boot-splash.c index 7e69675f..7b63a111 100644 --- a/src/libply-splash-core/ply-boot-splash.c +++ b/src/libply-splash-core/ply-boot-splash.c @@ -48,10 +48,6 @@ #define UPDATES_PER_SECOND 30 #endif -#define KEY_CTRL_L ('\100' ^'L') -#define KEY_CTRL_T ('\100' ^'T') -#define KEY_CTRL_V ('\100' ^'V') - struct _ply_boot_splash { ply_event_loop_t *loop; @@ -106,48 +102,6 @@ ply_boot_splash_new (const char *theme_path, return splash; } -static void -refresh_displays (ply_boot_splash_t *splash) -{ - ply_list_node_t *node; - - node = ply_list_get_first_node (splash->pixel_displays); - while (node != NULL) - { - ply_pixel_display_t *display; - ply_list_node_t *next_node; - unsigned long width, height; - - display = ply_list_node_get_data (node); - next_node = ply_list_get_next_node (splash->pixel_displays, node); - - width = ply_pixel_display_get_width (display); - height = ply_pixel_display_get_height (display); - - ply_pixel_display_draw_area (display, 0, 0, width, height); - node = next_node; - } - - node = ply_list_get_first_node (splash->text_displays); - while (node != NULL) - { - ply_text_display_t *display; - ply_list_node_t *next_node; - int number_of_columns, number_of_rows; - - display = ply_list_node_get_data (node); - next_node = ply_list_get_next_node (splash->text_displays, node); - - number_of_columns = ply_text_display_get_number_of_columns (display); - number_of_rows = ply_text_display_get_number_of_rows (display); - - ply_text_display_draw_area (display, 0, 0, - number_of_columns, - number_of_rows); - node = next_node; - } -} - static ply_terminal_t * find_local_console_terminal (ply_boot_splash_t *splash) { @@ -174,64 +128,12 @@ find_local_console_terminal (ply_boot_splash_t *splash) return NULL; } -static void -on_keyboard_input (ply_boot_splash_t *splash, - const char *keyboard_input, - size_t character_size) -{ - wchar_t key; - - if ((ssize_t) mbrtowc (&key, keyboard_input, character_size, NULL) > 0) - { - switch (key) - { - case KEY_CTRL_L: - refresh_displays (splash); - return; - - case KEY_CTRL_T: - ply_trace ("toggle text mode!"); - splash->should_force_text_mode = !splash->should_force_text_mode; - - if (ply_list_get_length (splash->pixel_displays) >= 1) - { - ply_terminal_t *terminal; - - terminal = find_local_console_terminal (splash); - - if (terminal != NULL) - { - if (splash->should_force_text_mode) - { - ply_terminal_set_mode (terminal, PLY_TERMINAL_MODE_TEXT); - ply_terminal_ignore_mode_changes (terminal, true); - } - else - ply_terminal_ignore_mode_changes (terminal, false); - } - } - ply_trace ("text mode toggled!"); - return; - - case KEY_CTRL_V: - ply_trace ("toggle verbose mode!"); - ply_toggle_tracing (); - ply_trace ("verbose mode toggled!"); - return; - } - } -} - void ply_boot_splash_set_keyboard (ply_boot_splash_t *splash, ply_keyboard_t *keyboard) { splash->keyboard = keyboard; - ply_keyboard_add_input_handler (keyboard, - (ply_keyboard_input_handler_t) - on_keyboard_input, splash); - if (splash->plugin_interface->set_keyboard == NULL) return; @@ -241,10 +143,6 @@ ply_boot_splash_set_keyboard (ply_boot_splash_t *splash, void ply_boot_splash_unset_keyboard (ply_boot_splash_t *splash) { - ply_keyboard_remove_input_handler (splash->keyboard, - (ply_keyboard_input_handler_t) - on_keyboard_input); - if (splash->plugin_interface->set_keyboard == NULL) return; From 9b211cb1736d4d15fa11a5be13cf677fe281fda0 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 2 Dec 2013 22:07:37 -0500 Subject: [PATCH 09/32] boot-splash: set KD_TEXT from main instead of boot_splash object Now that debugging keybindings are gone, ply-boot-splash is really just a wrapper around splash plugins. As such, it doesn't really make sense to be mucking with terminal objects from it. This commit moves that mucking to main until I can find a better destination for it. --- src/libply-splash-core/ply-boot-splash.c | 36 ------------------------ src/main.c | 22 +++++++++++---- 2 files changed, 17 insertions(+), 41 deletions(-) diff --git a/src/libply-splash-core/ply-boot-splash.c b/src/libply-splash-core/ply-boot-splash.c index 7b63a111..29247c77 100644 --- a/src/libply-splash-core/ply-boot-splash.c +++ b/src/libply-splash-core/ply-boot-splash.c @@ -102,32 +102,6 @@ ply_boot_splash_new (const char *theme_path, return splash; } -static ply_terminal_t * -find_local_console_terminal (ply_boot_splash_t *splash) -{ - ply_list_node_t *node; - node = ply_list_get_first_node (splash->text_displays); - - while (node != NULL) - { - ply_text_display_t *display; - ply_terminal_t *terminal; - ply_list_node_t *next_node; - - display = ply_list_node_get_data (node); - next_node = ply_list_get_next_node (splash->text_displays, node); - - terminal = ply_text_display_get_terminal (display); - - if (terminal != NULL && ply_terminal_is_vt (terminal)) - return terminal; - - node = next_node; - } - - return NULL; -} - void ply_boot_splash_set_keyboard (ply_boot_splash_t *splash, ply_keyboard_t *keyboard) @@ -574,16 +548,6 @@ ply_boot_splash_hide (ply_boot_splash_t *splash) splash->plugin_interface->hide_splash_screen (splash->plugin, splash->loop); - if (ply_list_get_length (splash->pixel_displays) >= 1) - { - ply_terminal_t *terminal; - - terminal = find_local_console_terminal (splash); - - if (terminal != NULL) - ply_terminal_set_mode (terminal, PLY_TERMINAL_MODE_TEXT); - } - splash->mode = PLY_BOOT_SPLASH_MODE_INVALID; if (splash->loop != NULL) diff --git a/src/main.c b/src/main.c index 715e5bdc..ab5438b1 100644 --- a/src/main.c +++ b/src/main.c @@ -1004,6 +1004,18 @@ quit_splash (state_t *state) detach_from_running_session (state); } +static void +hide_splash (state_t *state) +{ + if (state->boot_splash == NULL) + return; + + ply_boot_splash_hide (state->boot_splash); + + if (state->local_console_terminal != NULL) + ply_terminal_set_mode (state->local_console_terminal, PLY_TERMINAL_MODE_TEXT); +} + static void dump_details_and_quit_splash (state_t *state) { @@ -1012,8 +1024,8 @@ dump_details_and_quit_splash (state_t *state) if (state->renderer != NULL) ply_renderer_deactivate (state->renderer); - if (state->boot_splash != NULL) - ply_boot_splash_hide (state->boot_splash); + + hide_splash (state); state->is_shown = false; @@ -1126,8 +1138,8 @@ on_boot_splash_idle (state_t *state) ply_trace ("hiding splash"); if (state->renderer != NULL) ply_renderer_deactivate (state->renderer); - if (state->boot_splash != NULL) - ply_boot_splash_hide (state->boot_splash); + + hide_splash (state); state->is_shown = false; } @@ -1372,7 +1384,7 @@ toggle_between_splash_and_details (state_t *state) if (state->boot_splash != NULL) { ply_trace ("hiding and freeing current splash"); - ply_boot_splash_hide (state->boot_splash); + hide_splash (state); ply_boot_splash_free (state->boot_splash); state->boot_splash = NULL; } From 3a356a450f5cc4d10864bcbb49e3569123419c0a Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 3 Dec 2013 10:39:03 -0500 Subject: [PATCH 10/32] tests: drop for now They're fairly bitrotten, don't tie into make check, and aren't that useful. Drop them for now, until we can come up with a better story. --- src/Makefile.am | 2 +- src/client/Makefile.am | 2 - src/client/ply-boot-client.c | 133 ------------- src/client/tests/Makefile.am | 10 - src/client/tests/ply-boot-client-test.am | 16 -- src/libply-splash-core/ply-boot-splash.c | 144 -------------- src/libply/Makefile.am | 1 - src/libply/ply-array.c | 30 --- src/libply/ply-bitarray.c | 60 ------ src/libply/ply-buffer.c | 18 -- src/libply/ply-command-parser.c | 96 ---------- src/libply/ply-event-loop.c | 84 -------- src/libply/ply-hashtable.c | 59 ------ src/libply/ply-list.c | 81 -------- src/libply/ply-logger.c | 22 --- src/libply/ply-progress.c | 70 ------- src/libply/ply-region.c | 137 -------------- src/libply/ply-terminal-session.c | 53 ------ src/libply/tests/Makefile.am | 25 --- src/libply/tests/ply-array-test.am | 16 -- src/libply/tests/ply-bitarray-test.am | 8 - src/libply/tests/ply-command-parser-test.am | 18 -- src/libply/tests/ply-event-loop-test.am | 14 -- src/libply/tests/ply-hashtable-test.am | 10 - src/libply/tests/ply-list-test.am | 8 - src/libply/tests/ply-logger-test.am | 12 -- src/libply/tests/ply-progress-test.am | 15 -- src/libply/tests/ply-region.am | 12 -- src/libply/tests/ply-terminal-session-test.am | 18 -- src/ply-boot-server.c | 179 ------------------ src/tests/Makefile.am | 18 -- src/tests/ply-boot-server-test.am | 8 - src/tests/ply-boot-splash-test.am | 25 --- 33 files changed, 1 insertion(+), 1403 deletions(-) delete mode 100644 src/client/tests/Makefile.am delete mode 100644 src/client/tests/ply-boot-client-test.am delete mode 100644 src/libply/tests/Makefile.am delete mode 100644 src/libply/tests/ply-array-test.am delete mode 100644 src/libply/tests/ply-bitarray-test.am delete mode 100644 src/libply/tests/ply-command-parser-test.am delete mode 100644 src/libply/tests/ply-event-loop-test.am delete mode 100644 src/libply/tests/ply-hashtable-test.am delete mode 100644 src/libply/tests/ply-list-test.am delete mode 100644 src/libply/tests/ply-logger-test.am delete mode 100644 src/libply/tests/ply-progress-test.am delete mode 100644 src/libply/tests/ply-region.am delete mode 100644 src/libply/tests/ply-terminal-session-test.am delete mode 100644 src/tests/Makefile.am delete mode 100644 src/tests/ply-boot-server-test.am delete mode 100644 src/tests/ply-boot-splash-test.am diff --git a/src/Makefile.am b/src/Makefile.am index a9e6eb17..150e959c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = libply libply-splash-core libply-splash-graphics . plugins client viewer tests +SUBDIRS = libply libply-splash-core libply-splash-graphics . plugins client viewer if ENABLE_UPSTART_MONITORING SUBDIRS += upstart-bridge endif diff --git a/src/client/Makefile.am b/src/client/Makefile.am index 9487901b..ead574a9 100644 --- a/src/client/Makefile.am +++ b/src/client/Makefile.am @@ -1,5 +1,3 @@ -SUBDIRS = . tests - INCLUDES = -I$(top_srcdir) \ -I$(top_srcdir)/src \ -I$(top_srcdir)/src/libply \ diff --git a/src/client/ply-boot-client.c b/src/client/ply-boot-client.c index 56458ceb..3480676a 100644 --- a/src/client/ply-boot-client.c +++ b/src/client/ply-boot-client.c @@ -869,137 +869,4 @@ ply_boot_client_attach_to_event_loop (ply_boot_client_t *client, } -#ifdef PLY_BOOT_CLIENT_ENABLE_TEST - -#include - -#include "ply-event-loop.h" -#include "ply-boot-client.h" - -static void -on_pinged (ply_event_loop_t *loop) -{ - printf ("PING!\n"); -} - -static void -on_ping_failed (ply_event_loop_t *loop) -{ - printf ("PING FAILED! %m\n"); - ply_event_loop_exit (loop, 1); -} - -static void -on_update (ply_event_loop_t *loop) -{ - printf ("UPDATE!\n"); -} - -static void -on_update_failed (ply_event_loop_t *loop) -{ - printf ("UPDATE FAILED! %m\n"); - 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) -{ - printf ("SYSTEM INITIALIZED!\n"); -} - -static void -on_system_initialized_failed (ply_event_loop_t *loop) -{ - printf ("SYSTEM INITIALIZATION REQUEST FAILED!\n"); - ply_event_loop_exit (loop, 1); -} - -static void -on_quit (ply_event_loop_t *loop) -{ - printf ("QUIT!\n"); - ply_event_loop_exit (loop, 0); -} - -static void -on_quit_failed (ply_event_loop_t *loop) -{ - printf ("QUIT FAILED! %m\n"); - ply_event_loop_exit (loop, 2); -} - -static void -on_disconnect (ply_event_loop_t *loop) -{ - printf ("DISCONNECT!\n"); - ply_event_loop_exit (loop, 1); -} - -int -main (int argc, - char **argv) -{ - ply_event_loop_t *loop; - ply_boot_client_t *client; - int exit_code; - - exit_code = 0; - - loop = ply_event_loop_new (); - - client = ply_boot_client_new (); - - if (!ply_boot_client_connect (client, - (ply_boot_client_disconnect_handler_t) on_disconnect, - loop)) - { - perror ("could not start boot client"); - return errno; - } - - ply_boot_client_attach_to_event_loop (client, loop); - ply_boot_client_ping_daemon (client, - (ply_boot_client_response_handler_t) on_pinged, - (ply_boot_client_response_handler_t) on_ping_failed, - loop); - - ply_boot_client_update_daemon (client, - "loading", - (ply_boot_client_response_handler_t) on_update, - (ply_boot_client_response_handler_t) on_update_failed, - loop); - - ply_boot_client_update_daemon (client, - "loading more", - (ply_boot_client_response_handler_t) on_update, - (ply_boot_client_response_handler_t) on_update_failed, - loop); - - ply_boot_client_tell_daemon_system_is_initialized (client, - (ply_boot_client_response_handler_t) - on_system_initialized, - (ply_boot_client_response_handler_t) - on_system_initialized_failed, - loop); - - ply_boot_client_tell_daemon_to_quit (client, - (ply_boot_client_response_handler_t) on_quit, - (ply_boot_client_response_handler_t) on_quit_failed, - loop); - - exit_code = ply_event_loop_run (loop); - - ply_boot_client_free (client); - - return exit_code; -} - -#endif /* PLY_BOOT_CLIENT_ENABLE_TEST */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/client/tests/Makefile.am b/src/client/tests/Makefile.am deleted file mode 100644 index c6dbfdbd..00000000 --- a/src/client/tests/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -INCLUDES = \ - -I$(top_srcdir) \ - -I$(srcdir)/.. \ - -I$(srcdir)/../.. \ - -I$(srcdir) -TESTS = - -noinst_PROGRAMS = $(TESTS) - -MAINTAINERCLEANFILES = Makefile.in diff --git a/src/client/tests/ply-boot-client-test.am b/src/client/tests/ply-boot-client-test.am deleted file mode 100644 index f733032f..00000000 --- a/src/client/tests/ply-boot-client-test.am +++ /dev/null @@ -1,16 +0,0 @@ -TESTS += ply-boot-client-test - -ply_boot_client_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_BOOT_CLIENT_ENABLE_TEST -ply_boot_client_test_LDADD = $(PLYMOUTH_LIBS) - -ply_boot_client_test_SOURCES = \ - $(srcdir)/../ply-utils.h \ - $(srcdir)/../ply-utils.c \ - $(srcdir)/../ply-logger.h \ - $(srcdir)/../ply-logger.c \ - $(srcdir)/../ply-list.h \ - $(srcdir)/../ply-list.c \ - $(srcdir)/../ply-event-loop.h \ - $(srcdir)/../ply-event-loop.c \ - $(srcdir)/../ply-boot-client.h \ - $(srcdir)/../ply-boot-client.c diff --git a/src/libply-splash-core/ply-boot-splash.c b/src/libply-splash-core/ply-boot-splash.c index 29247c77..cf052915 100644 --- a/src/libply-splash-core/ply-boot-splash.c +++ b/src/libply-splash-core/ply-boot-splash.c @@ -682,148 +682,4 @@ ply_boot_splash_become_idle (ply_boot_splash_t *splash, splash->plugin_interface->become_idle (splash->plugin, splash->idle_trigger); } -#ifdef PLY_BOOT_SPLASH_ENABLE_TEST - -#include - -#include "ply-event-loop.h" -#include "ply-boot-splash.h" - -typedef struct test_state test_state_t; -struct test_state { - ply_event_loop_t *loop; - ply_boot_splash_t *splash; - ply_buffer_t *buffer; -}; - -static void -on_timeout (ply_boot_splash_t *splash) -{ - ply_boot_splash_update_status (splash, "foo"); - ply_event_loop_watch_for_timeout (splash->loop, - 5.0, - (ply_event_loop_timeout_handler_t) - on_timeout, - splash); -} - -static void -on_quit (test_state_t *state) -{ - ply_boot_splash_hide (state->splash); - ply_event_loop_exit (state->loop, 0); -} - -static void -add_displays_to_splash_from_renderer (test_state_t *state, - ply_renderer_t *renderer) -{ - ply_list_t *heads; - ply_list_node_t *node; - - heads = ply_renderer_get_heads (renderer); - - node = ply_list_get_first_node (heads); - while (node != NULL) - { - ply_list_node_t *next_node; - ply_renderer_head_t *head; - ply_pixel_display_t *display; - - head = ply_list_node_get_data (node); - next_node = ply_list_get_next_node (heads, node); - - display = ply_pixel_display_new (renderer, head); - - ply_boot_splash_add_pixel_display (state->splash, display); - - node = next_node; - } -} - -int -main (int argc, - char **argv) -{ - int exit_code; - test_state_t state; - char *tty_name; - const char *theme_path; - ply_text_display_t *text_display; - ply_renderer_t *renderer; - ply_terminal_t *terminal; - ply_keyboard_t *keyboard; - - exit_code = 0; - - state.loop = ply_event_loop_new (); - - if (argc > 1) - theme_path = argv[1]; - else - theme_path = PLYMOUTH_THEME_PATH "/fade-in/fade-in.plymouth"; - - if (argc > 2) - asprintf(&tty_name, "tty%s", argv[2]); - else - tty_name = strdup("tty0"); - - terminal = ply_terminal_new (tty_name); - - if (!ply_terminal_open (terminal)) - { - perror ("could not open tty"); - return errno; - } - - renderer = ply_renderer_new (PLY_RENDERER_TYPE_AUTO, NULL, terminal); - free(tty_name); - - if (!ply_renderer_open (renderer)) - { - perror ("could not open renderer /dev/fb"); - ply_renderer_free (renderer); - return errno; - } - - keyboard = ply_keyboard_new_for_renderer (renderer); - ply_keyboard_add_escape_handler (keyboard, - (ply_keyboard_escape_handler_t) on_quit, &state); - - state.buffer = ply_buffer_new (); - state.splash = ply_boot_splash_new (theme_path, PLYMOUTH_PLUGIN_PATH, state.buffer); - - if (!ply_boot_splash_load (state.splash)) - { - perror ("could not load splash screen"); - return errno; - } - - ply_boot_splash_set_keyboard (state.splash, keyboard); - add_displays_to_splash_from_renderer (&state, renderer); - - text_display = ply_text_display_new (terminal); - ply_boot_splash_add_text_display (state.splash, text_display); - - ply_boot_splash_attach_to_event_loop (state.splash, state.loop); - - if (!ply_boot_splash_show (state.splash, PLY_BOOT_SPLASH_MODE_BOOT_UP)) - { - perror ("could not show splash screen"); - return errno; - } - - ply_event_loop_watch_for_timeout (state.loop, - 1.0, - (ply_event_loop_timeout_handler_t) - on_timeout, - state.splash); - exit_code = ply_event_loop_run (state.loop); - ply_boot_splash_free (state.splash); - ply_buffer_free (state.buffer); - - return exit_code; -} - -#endif /* PLY_BOOT_SPLASH_ENABLE_TEST */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/Makefile.am b/src/libply/Makefile.am index 302e47d1..41b3a463 100644 --- a/src/libply/Makefile.am +++ b/src/libply/Makefile.am @@ -1,4 +1,3 @@ -SUBDIRS = tests INCLUDES = -I$(top_srcdir) \ -I$(srcdir) \ -DPLYMOUTH_TIME_DIRECTORY=\"$(localstatedir)/lib/plymouth/\" diff --git a/src/libply/ply-array.c b/src/libply/ply-array.c index 41134b86..999c86e5 100644 --- a/src/libply/ply-array.c +++ b/src/libply/ply-array.c @@ -171,34 +171,4 @@ ply_array_steal_uint32_elements (ply_array_t *array) return data; } -#ifdef PLY_ARRAY_ENABLE_TEST -#include - -int -main (int argc, - char **argv) -{ - ply_array_t *array; - int i; - char **data; - - array = ply_array_new (PLY_ARRAY_ELEMENT_TYPE_POINTER); - - ply_array_add_pointer_element (array, "foo"); - ply_array_add_pointer_element (array, "bar"); - ply_array_add_pointer_element (array, "baz"); - ply_array_add_pointer_element (array, "qux"); - - data = (char **) ply_array_get_pointer_elements (array); - for (i = 0; data[i] != NULL; i++) - { - printf ("element '%d' has data '%s'\n", i, data[i]); - i++; - } - - ply_array_free (array); - return 0; -} - -#endif /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-bitarray.c b/src/libply/ply-bitarray.c index 89e22169..3d0cdd0c 100644 --- a/src/libply/ply-bitarray.c +++ b/src/libply/ply-bitarray.c @@ -42,64 +42,4 @@ ply_bitarray_count (ply_bitarray_t *bitarray, return count; } - - - -#ifdef PLY_BITARRAY_ENABLE_TEST -#include - -int -main (int argc, - char **argv) -{ - ply_bitarray_t *bitarray; - int i, i2; - printf ("bitarray test start\n"); - bitarray = ply_bitarray_new (134); - - for (i=0; i<64; i++) - { - if (ply_bitarray_lookup (bitarray, i)) - printf ("1"); - else - printf ("0"); - } - printf ("\n"); - - for (i=0; i<64; i++) - if ((6654654654654654654ll >> i) & 1) - ply_bitarray_set (bitarray, i); - - for (i=0; i<64; i++) - { - if (ply_bitarray_lookup (bitarray, i)) - printf ("1"); - else - printf ("0"); - } - printf ("\n"); - - for (i = 63; i > 0; i--) - { - if ((6654654654654654654ll >> i) & 1) - { - ply_bitarray_clear (bitarray, i); - for (i2 = 0; i2 < 64; i2++) - { - if (ply_bitarray_lookup (bitarray, i2)) - printf ("1"); - else - printf ("0"); - } - printf ("\n"); - } - } - - ply_bitarray_free (bitarray); - - printf ("bitarray test end\n"); - return 0; -} - -#endif /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-buffer.c b/src/libply/ply-buffer.c index c65634f5..0d0406ff 100644 --- a/src/libply/ply-buffer.c +++ b/src/libply/ply-buffer.c @@ -263,22 +263,4 @@ ply_buffer_clear (ply_buffer_t *buffer) buffer->size = 0; } -#ifdef PLY_BUFFER_ENABLE_TEST -int -main (int argc, - char **argv) -{ - int exit_code; - ply_buffer_t *buffer; - - exit_code = 0; - buffer = ply_buffer_new (); - - ply_buffer_append (buffer, "yo yo yo\n"); - ply_buffer_free (buffer); - - return exit_code; -} - -#endif /* PLY_BUFFER_ENABLE_TEST */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-command-parser.c b/src/libply/ply-command-parser.c index 6ab323bc..2768668a 100644 --- a/src/libply/ply-command-parser.c +++ b/src/libply/ply-command-parser.c @@ -968,100 +968,4 @@ ply_command_parser_parse_arguments (ply_command_parser_t *parser, return parsed_arguments; } -#ifdef PLY_COMMAND_PARSER_ENABLE_TEST - -#include - -#include "ply-command-parser.h" -#include "ply-event-loop.h" -#include "ply-logger.h" - -static void -on_ask_for_password (ply_command_parser_t *parser, - const char *command) -{ - char *prompt; - char *program; - - prompt = NULL; - program = NULL; - ply_command_parser_get_command_options (parser, command, "prompt", &prompt, "command", &program, NULL); - - printf ("ask for password with prompt '%s' feed result to '%s'\n", prompt, program); - free (prompt); - free (program); -} - -static void -on_show_splash (ply_command_parser_t *parser, - const char *command) -{ - char *plugin_name; - - plugin_name = NULL; - ply_command_parser_get_command_options (parser, command, "plugin-name", &plugin_name, NULL); - - printf ("show splash plugin '%s'\n", plugin_name); - free (plugin_name); -} - -int -main (int argc, - char **argv) -{ - ply_event_loop_t *loop; - ply_command_parser_t *parser; - bool should_help; - - loop = ply_event_loop_new (); - parser = ply_command_parser_new (argv[0], "Test Program"); - - ply_command_parser_add_options (parser, - "help", "This help message", PLY_COMMAND_OPTION_TYPE_FLAG, - NULL); - - ply_command_parser_add_command (parser, - "ask-for-password", - "Ask user for password", - (ply_command_handler_t) - on_ask_for_password, parser, - "command", "command to pipe result to", PLY_COMMAND_OPTION_TYPE_STRING, - "prompt", "string to present to user", PLY_COMMAND_OPTION_TYPE_STRING, - "output-result", "print result", PLY_COMMAND_OPTION_TYPE_BOOLEAN, - NULL); - - ply_command_parser_add_command (parser, - "show-splash", - "Show splash to user", - (ply_command_handler_t) - on_show_splash, parser, - "plugin-name", "name of the plugin to run", PLY_COMMAND_OPTION_TYPE_STRING, - NULL); - - if (!ply_command_parser_parse_arguments (parser, loop, argv, argc)) - { - ply_error ("couldn't parse arguments"); - return 1; - } - - - ply_command_parser_get_options (parser, "help", &should_help, NULL); - - if (should_help) - { - char *usage; - usage = ply_command_parser_get_help_string (parser); - printf ("%s\n", usage); - free (usage); - return 0; - } - - ply_event_loop_run (loop); - - ply_command_parser_free (parser); - - return 0; -} - -#endif /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-event-loop.c b/src/libply/ply-event-loop.c index 4abf25fc..0c85cb93 100644 --- a/src/libply/ply-event-loop.c +++ b/src/libply/ply-event-loop.c @@ -1376,88 +1376,4 @@ ply_event_loop_run (ply_event_loop_t *loop) return loop->exit_code; } -#ifdef PLY_EVENT_LOOP_ENABLE_TEST - -static ply_event_loop_t *loop; - -static void -alrm_signal_handler (void) -{ - write (1, "times up!\n", sizeof ("times up!\n") - 1); - ply_event_loop_exit (loop, 0); -} - -static void -usr1_signal_handler (void) -{ - write (1, "got sigusr1\n", sizeof ("got sigusr1\n") - 1); -} - -static void -hangup_signal_handler (void) -{ - write (1, "got hangup\n", sizeof ("got hangup\n") - 1); -} - -static void -terminate_signal_handler (void) -{ - write (1, "got terminate\n", sizeof ("got terminate\n") - 1); - ply_event_loop_exit (loop, 0); -} - -static void -line_received_handler (void) -{ - char line[512] = { 0 }; - printf ("Received line: "); - fflush (stdout); - - fgets (line, sizeof (line), stdin); - printf ("%s", line); -} - -static void -on_timeout (ply_event_loop_t *loop) -{ - printf ("timeout elapsed\n"); -} - -int -main (int argc, - char **argv) -{ - int exit_code; - - loop = ply_event_loop_new (); - - ply_event_loop_watch_signal (loop, SIGHUP, - (ply_event_handler_t) hangup_signal_handler, - NULL); - ply_event_loop_watch_signal (loop, SIGTERM, - (ply_event_handler_t) - terminate_signal_handler, NULL); - ply_event_loop_watch_signal (loop, SIGUSR1, - (ply_event_handler_t) - usr1_signal_handler, NULL); - ply_event_loop_watch_signal (loop, SIGALRM, - (ply_event_handler_t) - alrm_signal_handler, NULL); - - ply_event_loop_watch_for_timeout (loop, 2.0, - (ply_event_loop_timeout_handler_t) - on_timeout, loop); - ply_event_loop_watch_fd (loop, 0, PLY_EVENT_LOOP_FD_STATUS_HAS_DATA, - (ply_event_handler_t) line_received_handler, - (ply_event_handler_t) line_received_handler, - NULL); - - alarm (5); - exit_code = ply_event_loop_run (loop); - - ply_event_loop_free (loop); - - return exit_code; -} -#endif /* PLY_EVENT_LOOP_ENABLE_TEST */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-hashtable.c b/src/libply/ply-hashtable.c index 7f20a534..7b03d876 100644 --- a/src/libply/ply-hashtable.c +++ b/src/libply/ply-hashtable.c @@ -130,14 +130,6 @@ ply_hashtable_insert_internal (ply_hashtable_t *hashtable, { unsigned int hash_index; int step = 0; - -#ifdef PLY_HASHTABLE_ENABLE_TEST - /* Make sure the counts are synchronised with bitmap */ - assert (ply_bitarray_count (hashtable->dirty_node_bitmap, hashtable->total_node_count) == - (int) hashtable->dirty_node_count); - assert (ply_bitarray_count (hashtable->live_node_bitmap, hashtable->total_node_count) == - (int) hashtable->live_node_count); -#endif /* PLY_HASHTABLE_ENABLE_TEST */ hash_index = hashtable->hash_func (key); hash_index &= hashtable->total_node_count - 1; @@ -287,55 +279,4 @@ ply_hashtable_get_size (ply_hashtable_t *hashtable) return hashtable->live_node_count; } -#ifdef PLY_HASHTABLE_ENABLE_TEST -#include - -static void -foreach_func (void *key, - void *data, - void *user_data) -{ - printf ("foreach key:%s data:%s\n", (char*) key, (char*) data); -} - - -int -main (int argc, - char **argv) -{ - ply_hashtable_t *hashtable; - int i; - const char* key[10] = {"k1", "k2", "k3", "k4", "k5", "k6", "k7", "k8", "k9", "k10"}; - const char* data[10] = {"d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "d10"}; - char* reply_key = NULL; - char* reply_data = NULL; - - printf ("hashtable test start\n"); - hashtable = ply_hashtable_new (ply_hashtable_string_hash, ply_hashtable_string_compare); - for (i=0; i<10; i++) - { - ply_hashtable_insert (hashtable, (void *) key[i], (void *) data[9-i]); - } - for (i=0; i<10; i++) - { - reply_data = ply_hashtable_lookup (hashtable, (void *) key[i]); - printf ("got:%s\n", reply_data); - } - for (i=0; i<10; i++) - { - ply_hashtable_remove (hashtable, (void *) key[i]); - ply_hashtable_insert (hashtable, (void *) key[i], (void *) data[i]); - } - for (i=0; i<10; i++) - { - if (ply_hashtable_lookup_full (hashtable, (void *) key[i], (void**) &reply_key, (void**) &reply_data)) - printf ("got key:%s data:%s\n", reply_key, reply_data); - } - ply_hashtable_foreach (hashtable, foreach_func, NULL); - ply_hashtable_free(hashtable); - printf ("hashtable test end\n"); - return 0; -} - -#endif /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-list.c b/src/libply/ply-list.c index 85262ab6..8c589c21 100644 --- a/src/libply/ply-list.c +++ b/src/libply/ply-list.c @@ -375,85 +375,4 @@ ply_list_node_get_data (ply_list_node_t *node) return node->data; } -#ifdef PLY_LIST_ENABLE_TEST -#include - -static int -compare_int_ptr (void *element_a, - void *element_b) -{ - int *int_a = element_a; - int *int_b = element_b; - return *int_a - *int_b; - -} - -int -main (int argc, - char **argv) -{ - ply_list_t *list; - ply_list_node_t *node; - int i, lastval; - int *value; - int errors; - - errors = 0; - - list = ply_list_new (); - - ply_list_append_data (list, (void *) "foo"); - ply_list_append_data (list, (void *) "bar"); - ply_list_append_data (list, (void *) "baz"); - ply_list_prepend_data (list, (void *) "qux"); - ply_list_prepend_data (list, (void *) "quux"); - ply_list_remove_data (list, (void *) "baz"); - ply_list_remove_data (list, (void *) "foo"); - - node = ply_list_get_first_node (list); - i = 0; - while (node != NULL) - { - printf ("node '%d' has data '%s'\n", i, - (char *) ply_list_node_get_data (node)); - node = ply_list_get_next_node (list, node); - i++; - } - - printf ("\n"); - ply_list_remove_all_nodes (list); - srandom(1); - - for (i = 0; i<100; i++) - { - value = malloc (sizeof (int)); - *value = random() % 100; - ply_list_append_data (list, (void *) value); - } - - ply_list_sort (list, compare_int_ptr); - - node = ply_list_get_first_node (list); - i = 0; - lastval = 0; - - while (node != NULL) - { - value = (int *) ply_list_node_get_data (node); - if (*value < lastval) - { - printf ("ERROR: incorrect order\n"); - errors = 1; - } - lastval = *value; - printf ("node '%d' has data '%d'\n", i, *value); - node = ply_list_get_next_node (list, node); - i++; - } - - ply_list_free (list); - return errors; -} - -#endif /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-logger.c b/src/libply/ply-logger.c index ec5b6e52..740c30ea 100644 --- a/src/libply/ply-logger.c +++ b/src/libply/ply-logger.c @@ -598,26 +598,4 @@ ply_logger_is_tracing_enabled (ply_logger_t *logger) } #endif /* PLY_ENABLE_TRACING */ -#ifdef PLY_LOGGER_ENABLE_TEST - -int -main (int argc, - char **argv) -{ - int exit_code; - ply_logger_t *logger; - - exit_code = 0; - logger = ply_logger_new (); - - ply_logger_inject (logger, "yo yo yo\n"); - ply_logger_set_output_fd (logger, 1); - ply_logger_inject (logger, "yo yo yo yo\n"); - ply_logger_flush (logger); - ply_logger_free (logger); - - return exit_code; -} - -#endif /* PLY_LOGGER_ENABLE_TEST */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-progress.c b/src/libply/ply-progress.c index cf372cdd..a88aa28b 100644 --- a/src/libply/ply-progress.c +++ b/src/libply/ply-progress.c @@ -330,75 +330,5 @@ ply_progress_status_update (ply_progress_t* progress, } } -#ifdef PLY_PROGRESS_ENABLE_TEST - -#include - -int -main (int argc, - char **argv) -{ - double percent; - int slowness; - double time; - int i; - const char* strings[10]={"foobar", "barfoo", "barbar", "foo", "foo", "bar", "foo", "more", "even more", "even even more"}; - ply_progress_t* progress = ply_progress_new (); - - progress->scalar = 1.0/5; /* Original time estimate is 5 sec*/ - - percent = ply_progress_get_percentage (progress); - time = ply_progress_get_time (progress); - printf("Time:%f \t Percentage: %f%%\n", time, percent*100); - srand ((int) ply_get_timestamp ()); - - slowness = rand () % 500000 + 50000; - - for (i=0; i<2; i++) - { - usleep ((rand () % slowness+slowness)); - percent = ply_progress_get_percentage (progress); - time = ply_progress_get_time (progress); - printf("Time:%f \t Percentage: %f%%\n", time, percent*100); - } - printf("Load cache\n"); - ply_progress_load_cache (progress, PLYMOUTH_TIME_DIRECTORY "/boot-duration"); - - for (i=0; i<10; i++) - { - ply_progress_status_update (progress, strings[i]); - usleep ((rand () % slowness+slowness)); - percent = ply_progress_get_percentage (progress); - time = ply_progress_get_time (progress); - printf("Time:%f \t Percentage: %f%% \tScalar:%f\n", time, percent*100, progress->scalar); - } - printf("Save and free cache\n"); - ply_progress_save_cache (progress, PLYMOUTH_TIME_DIRECTORY "/boot-duration"); - ply_progress_free(progress); - - printf("\nManual set percentage run\n\n"); - - progress = ply_progress_new (); - progress->scalar = 1.0/5; /* Original time estimate is 5 sec*/ - - percent = ply_progress_get_percentage (progress); - time = ply_progress_get_time (progress); - printf("Time:%f \t Percentage: %f%%\n", time, percent*100); - srand ((int) ply_get_timestamp ()); - - for (i=0; i<12; i++) - { - ply_progress_set_percentage (progress, (double)i/12); - usleep ((rand () % slowness+slowness)); - percent = ply_progress_get_percentage (progress); - time = ply_progress_get_time (progress); - printf("Time:%f \t Percentage: %f%% (%f%%)\tScalar:%f\n", time, percent*100, (double)i/12*100, progress->scalar); - } - ply_progress_free(progress); - - return 0; -} - -#endif /* PLY_PROGRESS_ENABLE_TEST */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-region.c b/src/libply/ply-region.c index cbaca403..92d35743 100644 --- a/src/libply/ply-region.c +++ b/src/libply/ply-region.c @@ -467,141 +467,4 @@ ply_region_get_sorted_rectangle_list (ply_region_t *region) return region->rectangle_list; } -#ifdef PLY_REGION_ENABLE_TEST -#include - -#define COVER_SIZE 100 -#define RECTANGLE_COUNT 1000 - -static void -cover_with_rect(char cover[COVER_SIZE][COVER_SIZE], - ply_rectangle_t *rectangle, - char value) -{ /* is value is not zero, the entry will be set to the value, - otherwise entry is incremented*/ - unsigned long x, y; - for (y=0; yheight; y++) - { - for (x=0; xwidth; x++) - { - if (rectangle->x + x < COVER_SIZE && - rectangle->y + y < COVER_SIZE) - { - if (value) - cover[rectangle->y + y][rectangle->x + x] = value; - else - cover[rectangle->y + y][rectangle->x + x]++; - } - } - } -} - -static int -do_test (void) -{ - ply_rectangle_t rectangle; - char cover[COVER_SIZE][COVER_SIZE]; - int i; - unsigned long x, y; - ply_region_t *region; - ply_list_node_t *node; - - region = ply_region_new (); - - for (y = 0; y < COVER_SIZE; y++) - { - for (x = 0; x < COVER_SIZE; x++) - { - cover[y][x] = 0; - } - } - - for (i = 0; i < RECTANGLE_COUNT; i++) - { - rectangle.x = random() % COVER_SIZE-5; - rectangle.y = random() % COVER_SIZE-5; - rectangle.width = 1 + random() % 20; - rectangle.height = 1 + random() % 20; - printf("Adding X=%ld Y=%ld W=%ld H=%ld\n", - rectangle.x, - rectangle.y, - rectangle.width, - rectangle.height); - cover_with_rect(cover, &rectangle, 100); /* 100 means covered by origial squares */ - ply_region_add_rectangle (region, &rectangle); - } - - printf("Converted to:\n"); - int count = 0; - - ply_list_t *rectangle_list = ply_region_get_rectangle_list (region); - for (node = ply_list_get_first_node (rectangle_list); - node; - node = ply_list_get_next_node (rectangle_list, node)) - { - ply_rectangle_t *small_rectangle = ply_list_node_get_data (node); - printf("Processed X=%ld Y=%ld W=%ld H=%ld\n", - small_rectangle->x, - small_rectangle->y, - small_rectangle->width, - small_rectangle->height); - cover_with_rect(cover, small_rectangle, 0); - count++; - } - printf("Rectangles in:%d out:%d\n", RECTANGLE_COUNT, count); - - count=0; - - for (y = 0; y < COVER_SIZE; y++) - { - printf("%03ld ", y); - for (x = 0; x < COVER_SIZE; x++) - { - if (cover[y][x] >= 100) - { - if (cover[y][x] == 100) - { - printf("-"); /* "-" means should have been covered but wasn't */ - count++; - } - else - { - if (cover[y][x] == 101) - printf("O"); /* "O" means correctly covered */ - else - { - printf("%d", cover[y][x] - 101); - count++; /* 1+ means covered multiple times*/ - } - } - } - else - { - if (cover[y][x] == 0) - printf("o"); /* "o" means not involved*/ - else - { - printf("%c", 'A' - 1 + cover[y][x]); - count++; /* A+ means covered despite being not involved*/ - } - } - } - printf("\n"); - } - printf("errors:%d\n", count); - return count; -} -int -main (int argc, - char **argv) -{ - int i; - srandom(312); - for (i=0; i<100; i++) - { - if (do_test ()) return 1; - } - return 0; -} -#endif /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/ply-terminal-session.c b/src/libply/ply-terminal-session.c index 0bdb985b..379035cc 100644 --- a/src/libply/ply-terminal-session.c +++ b/src/libply/ply-terminal-session.c @@ -587,57 +587,4 @@ ply_terminal_session_close_log (ply_terminal_session_t *session) return ply_logger_close_file (session->logger); } -#ifdef PLY_TERMINAL_SESSION_ENABLE_TEST - -#include - -#include "ply-event-loop.h" -#include "ply-terminal-session.h" - -static void -on_finished (ply_event_loop_t *loop) -{ - ply_event_loop_exit (loop, 0); -} - -int -main (int argc, - char **argv) -{ - ply_event_loop_t *loop; - ply_terminal_session_t *session; - int exit_code; - ply_terminal_session_flags_t flags; - - exit_code = 0; - - loop = ply_event_loop_new (); - - session = ply_terminal_session_new ((const char * const *) (argv + 1)); - - flags = PLY_TERMINAL_SESSION_FLAGS_RUN_IN_PARENT; - flags |= PLY_TERMINAL_SESSION_FLAGS_LOOK_IN_PATH; - - ply_terminal_session_attach_to_event_loop (session, loop); - - if (!ply_terminal_session_run (session, flags, - (ply_terminal_session_begin_handler_t) NULL, - (ply_terminal_session_output_handler_t) NULL, - (ply_terminal_session_hangup_handler_t) - on_finished, loop)) - { - perror ("could not start terminal session"); - return errno; - } - - ply_terminal_session_open_log (session, "foo.log"); - - exit_code = ply_event_loop_run (loop); - - ply_terminal_session_free (session); - - return exit_code; -} - -#endif /* PLY_TERMINAL_SESSION_ENABLE_TEST */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/libply/tests/Makefile.am b/src/libply/tests/Makefile.am deleted file mode 100644 index bc4da58f..00000000 --- a/src/libply/tests/Makefile.am +++ /dev/null @@ -1,25 +0,0 @@ -INCLUDES = \ - -I$(top_srcdir) \ - -I$(srcdir)/.. \ - -I$(srcdir) -TESTS = - -if ENABLE_TESTS -include $(srcdir)/ply-terminal-session-test.am -include $(srcdir)/ply-logger-test.am -include $(srcdir)/ply-array-test.am -include $(srcdir)/ply-bitarray-test.am -include $(srcdir)/ply-list-test.am -include $(srcdir)/ply-hashtable-test.am -include $(srcdir)/ply-event-loop-test.am -include $(srcdir)/ply-command-parser-test.am -include $(srcdir)/ply-progress-test.am -include $(srcdir)/ply-region.am -endif - -noinst_PROGRAMS = $(TESTS) - -# Our tests aren't unit tests so clear for now -TESTS = - -MAINTAINERCLEANFILES = Makefile.in diff --git a/src/libply/tests/ply-array-test.am b/src/libply/tests/ply-array-test.am deleted file mode 100644 index 4f8ecc4e..00000000 --- a/src/libply/tests/ply-array-test.am +++ /dev/null @@ -1,16 +0,0 @@ -TESTS += ply-array-test - -ply_array_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_ARRAY_ENABLE_TEST -ply_array_test_LDADD = $(PLYMOUTH_LIBS) - -ply_array_test_SOURCES = \ - $(srcdir)/../ply-buffer.h \ - $(srcdir)/../ply-buffer.c \ - $(srcdir)/../ply-list.h \ - $(srcdir)/../ply-list.c \ - $(srcdir)/../ply-logger.h \ - $(srcdir)/../ply-logger.c \ - $(srcdir)/../ply-utils.h \ - $(srcdir)/../ply-utils.c \ - $(srcdir)/../ply-array.h \ - $(srcdir)/../ply-array.c diff --git a/src/libply/tests/ply-bitarray-test.am b/src/libply/tests/ply-bitarray-test.am deleted file mode 100644 index 85c36089..00000000 --- a/src/libply/tests/ply-bitarray-test.am +++ /dev/null @@ -1,8 +0,0 @@ -TESTS += ply-bitarray-test - -ply_bitarray_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_BITARRAY_ENABLE_TEST -ply_bitarray_test_LDADD = $(PLYMOUTH_LIBS) - -ply_bitarray_test_SOURCES = \ - $(srcdir)/../ply-bitarray.h \ - $(srcdir)/../ply-bitarray.c diff --git a/src/libply/tests/ply-command-parser-test.am b/src/libply/tests/ply-command-parser-test.am deleted file mode 100644 index 91649d5b..00000000 --- a/src/libply/tests/ply-command-parser-test.am +++ /dev/null @@ -1,18 +0,0 @@ -TESTS += ply-command-parser-test - -ply_command_parser_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_COMMAND_PARSER_ENABLE_TEST -ply_command_parser_test_LDADD = $(PLYMOUTH_LIBS) - -ply_command_parser_test_SOURCES = \ - $(srcdir)/../ply-buffer.h \ - $(srcdir)/../ply-buffer.c \ - $(srcdir)/../ply-event-loop.h \ - $(srcdir)/../ply-event-loop.c \ - $(srcdir)/../ply-list.h \ - $(srcdir)/../ply-list.c \ - $(srcdir)/../ply-logger.h \ - $(srcdir)/../ply-logger.c \ - $(srcdir)/../ply-utils.h \ - $(srcdir)/../ply-utils.c \ - $(srcdir)/../ply-command-parser.h \ - $(srcdir)/../ply-command-parser.c diff --git a/src/libply/tests/ply-event-loop-test.am b/src/libply/tests/ply-event-loop-test.am deleted file mode 100644 index c666ea6a..00000000 --- a/src/libply/tests/ply-event-loop-test.am +++ /dev/null @@ -1,14 +0,0 @@ -TESTS += ply-event-loop-test - -ply_event_loop_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_EVENT_LOOP_ENABLE_TEST -ply_event_loop_test_LDADD = $(PLYMOUTH_LIBS) - -ply_event_loop_test_SOURCES = \ - $(srcdir)/../ply-utils.h \ - $(srcdir)/../ply-utils.c \ - $(srcdir)/../ply-list.h \ - $(srcdir)/../ply-list.c \ - $(srcdir)/../ply-logger.h \ - $(srcdir)/../ply-logger.c \ - $(srcdir)/../ply-event-loop.h \ - $(srcdir)/../ply-event-loop.c diff --git a/src/libply/tests/ply-hashtable-test.am b/src/libply/tests/ply-hashtable-test.am deleted file mode 100644 index d3410fcd..00000000 --- a/src/libply/tests/ply-hashtable-test.am +++ /dev/null @@ -1,10 +0,0 @@ -TESTS += ply-hashtable-test - -ply_hashtable_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_HASHTABLE_ENABLE_TEST -ply_hashtable_test_LDADD = $(PLYMOUTH_LIBS) - -ply_hashtable_test_SOURCES = \ - $(srcdir)/../ply-hashtable.h \ - $(srcdir)/../ply-hashtable.c \ - $(srcdir)/../ply-bitarray.h \ - $(srcdir)/../ply-bitarray.c diff --git a/src/libply/tests/ply-list-test.am b/src/libply/tests/ply-list-test.am deleted file mode 100644 index 8beb5786..00000000 --- a/src/libply/tests/ply-list-test.am +++ /dev/null @@ -1,8 +0,0 @@ -TESTS += ply-list-test - -ply_list_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_LIST_ENABLE_TEST -ply_list_test_LDADD = $(PLYMOUTH_LIBS) - -ply_list_test_SOURCES = \ - $(srcdir)/../ply-list.h \ - $(srcdir)/../ply-list.c diff --git a/src/libply/tests/ply-logger-test.am b/src/libply/tests/ply-logger-test.am deleted file mode 100644 index a589fb92..00000000 --- a/src/libply/tests/ply-logger-test.am +++ /dev/null @@ -1,12 +0,0 @@ -TESTS += ply-logger-test - -ply_logger_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_LOGGER_ENABLE_TEST -ply_logger_test_LDADD = $(PLYMOUTH_LIBS) - -ply_logger_test_SOURCES = \ - $(srcdir)/../ply-list.h \ - $(srcdir)/../ply-list.c \ - $(srcdir)/../ply-utils.h \ - $(srcdir)/../ply-utils.c \ - $(srcdir)/../ply-logger.h \ - $(srcdir)/../ply-logger.c diff --git a/src/libply/tests/ply-progress-test.am b/src/libply/tests/ply-progress-test.am deleted file mode 100644 index 6279facf..00000000 --- a/src/libply/tests/ply-progress-test.am +++ /dev/null @@ -1,15 +0,0 @@ -TESTS += ply-progress-test - -ply_progress_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_PROGRESS_ENABLE_TEST \ - -DPLYMOUTH_TIME_DIRECTORY=\"$(localstatedir)/lib/plymouth/\" -ply_progress_test_LDADD = $(PLYMOUTH_LIBS) - -ply_progress_test_SOURCES = \ - $(srcdir)/../ply-progress.h \ - $(srcdir)/../ply-progress.c \ - $(srcdir)/../ply-list.h \ - $(srcdir)/../ply-list.c \ - $(srcdir)/../ply-logger.h \ - $(srcdir)/../ply-logger.c \ - $(srcdir)/../ply-utils.h \ - $(srcdir)/../ply-utils.c diff --git a/src/libply/tests/ply-region.am b/src/libply/tests/ply-region.am deleted file mode 100644 index 18838336..00000000 --- a/src/libply/tests/ply-region.am +++ /dev/null @@ -1,12 +0,0 @@ -TESTS += ply-region-test - -ply_region_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_REGION_ENABLE_TEST -ply_region_test_LDADD = $(PLYMOUTH_LIBS) - -ply_region_test_SOURCES = \ - $(srcdir)/../ply-region.h \ - $(srcdir)/../ply-region.c \ - $(srcdir)/../ply-rectangle.h \ - $(srcdir)/../ply-rectangle.c \ - $(srcdir)/../ply-list.h \ - $(srcdir)/../ply-list.c diff --git a/src/libply/tests/ply-terminal-session-test.am b/src/libply/tests/ply-terminal-session-test.am deleted file mode 100644 index decb531b..00000000 --- a/src/libply/tests/ply-terminal-session-test.am +++ /dev/null @@ -1,18 +0,0 @@ -TESTS += ply-terminal-session-test - -ply_terminal_session_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_TERMINAL_SESSION_ENABLE_TEST -ply_terminal_session_test_LDADD = $(PLYMOUTH_LIBS) - -ply_terminal_session_test_SOURCES = \ - $(srcdir)/../ply-utils.h \ - $(srcdir)/../ply-utils.c \ - $(srcdir)/../ply-buffer.h \ - $(srcdir)/../ply-buffer.c \ - $(srcdir)/../ply-logger.h \ - $(srcdir)/../ply-logger.c \ - $(srcdir)/../ply-list.h \ - $(srcdir)/../ply-list.c \ - $(srcdir)/../ply-event-loop.h \ - $(srcdir)/../ply-event-loop.c \ - $(srcdir)/../ply-terminal-session.h \ - $(srcdir)/../ply-terminal-session.c diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c index 2d2a5b85..3e67bfbf 100644 --- a/src/ply-boot-server.c +++ b/src/ply-boot-server.c @@ -831,183 +831,4 @@ ply_boot_server_attach_to_event_loop (ply_boot_server_t *server, server); } -#ifdef PLY_BOOT_SERVER_ENABLE_TEST - -#include - -#include "ply-event-loop.h" -#include "ply-boot-server.h" - -static void -on_update (ply_event_loop_t *loop, - const char *status) -{ - 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) -{ - printf ("got sysinit done request\n"); -} - -static void -on_show_splash (ply_event_loop_t *loop) -{ - printf ("got show splash request\n"); -} - -static void -on_hide_splash (ply_event_loop_t *loop) -{ - printf ("got hide splash request\n"); -} - -static void -on_deactivate (ply_event_loop_t *loop) -{ - printf ("got deactivate request\n"); -} - -static void -on_reactivate (ply_event_loop_t *loop) -{ - printf ("got reactivate request\n"); -} - -static void -on_quit (ply_event_loop_t *loop) -{ - printf ("got quit request, quiting...\n"); - ply_event_loop_exit (loop, 0); -} - -static void -on_error (ply_event_loop_t *loop) -{ - printf ("got error starting service\n"); -} - -static char * -on_ask_for_password (ply_event_loop_t *loop) -{ - printf ("got password request, returning 'password'...\n"); - - return strdup ("password"); -} - -static void -on_ask_question (ply_event_loop_t *loop) -{ - printf ("got question request\n"); - return; -} - -static void -on_display_message (ply_event_loop_t *loop) -{ - printf ("got display message request\n"); - return; -} - -static void -on_hide_message (ply_event_loop_t *loop) -{ - printf ("got hide message request\n"); - return; -} - -static void -on_watch_for_keystroke (ply_event_loop_t *loop) -{ - printf ("got keystroke request\n"); - - return; -} - -static void -on_progress_pause (ply_event_loop_t *loop) -{ - printf ("got progress pause request\n"); - - return; -} - -static void -on_progress_unpause (ply_event_loop_t *loop) -{ - printf ("got progress unpause request\n"); - - return; -} - -static void -on_ignore_keystroke (ply_event_loop_t *loop) -{ - printf ("got keystroke ignore request\n"); - - return; -} - -static bool -on_has_active_vt (ply_event_loop_t *loop) -{ - printf ("got has_active vt? request\n"); - return true; -} - -int -main (int argc, - char **argv) -{ - ply_event_loop_t *loop; - ply_boot_server_t *server; - int exit_code; - - exit_code = 0; - - loop = ply_event_loop_new (); - - server = ply_boot_server_new ((ply_boot_server_update_handler_t) on_update, - (ply_boot_server_change_mode_handler_t) on_change_mode, - (ply_boot_server_system_update_handler_t) on_system_update, - (ply_boot_server_ask_for_password_handler_t) on_ask_for_password, - (ply_boot_server_ask_question_handler_t) on_ask_question, - (ply_boot_server_display_message_handler_t) on_display_message, - (ply_boot_server_hide_message_handler_t) on_hide_message, - (ply_boot_server_watch_for_keystroke_handler_t) on_watch_for_keystroke, - (ply_boot_server_ignore_keystroke_handler_t) on_ignore_keystroke, - (ply_boot_server_progress_pause_handler_t) on_progress_pause, - (ply_boot_server_progress_unpause_handler_t) on_progress_unpause, - (ply_boot_server_show_splash_handler_t) on_show_splash, - (ply_boot_server_hide_splash_handler_t) on_hide_splash, - (ply_boot_server_newroot_handler_t) on_newroot, - (ply_boot_server_system_initialized_handler_t) on_system_initialized, - (ply_boot_server_error_handler_t) on_error, - (ply_boot_server_deactivate_handler_t) on_deactivate, - (ply_boot_server_reactivate_handler_t) on_reactivate, - (ply_boot_server_quit_handler_t) on_quit, - (ply_boot_server_has_active_vt_handler_t) on_has_active_vt, - loop); - - if (!ply_boot_server_listen (server)) - { - perror ("could not start boot status daemon"); - return errno; - } - - ply_boot_server_attach_to_event_loop (server, loop); - exit_code = ply_event_loop_run (loop); - ply_boot_server_free (server); - - return exit_code; -} - -#endif /* PLY_BOOT_SERVER_ENABLE_TEST */ /* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ diff --git a/src/tests/Makefile.am b/src/tests/Makefile.am deleted file mode 100644 index 86a8ea61..00000000 --- a/src/tests/Makefile.am +++ /dev/null @@ -1,18 +0,0 @@ -INCLUDES = \ - -I$(top_srcdir) \ - -I$(srcdir)/.. \ - -I$(srcdir)/../libply \ - -I$(srcdir)/../libply-splash-core \ - -I$(srcdir) -TESTS = - -if ENABLE_TESTS -include $(srcdir)/ply-boot-server-test.am -include $(srcdir)/ply-boot-splash-test.am -endif - -noinst_PROGRAMS = $(TESTS) - -# our tests aren't unit tests, so clear for now -TESTS = -MAINTAINERCLEANFILES = Makefile.in diff --git a/src/tests/ply-boot-server-test.am b/src/tests/ply-boot-server-test.am deleted file mode 100644 index cc283487..00000000 --- a/src/tests/ply-boot-server-test.am +++ /dev/null @@ -1,8 +0,0 @@ -TESTS += ply-boot-server-test - -ply_boot_server_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_BOOT_SERVER_ENABLE_TEST -ply_boot_server_test_LDADD = $(PLYMOUTH_LIBS) ../libply/libply.la - -ply_boot_server_test_SOURCES = \ - $(srcdir)/../ply-boot-server.h \ - $(srcdir)/../ply-boot-server.c diff --git a/src/tests/ply-boot-splash-test.am b/src/tests/ply-boot-splash-test.am deleted file mode 100644 index 9dd15989..00000000 --- a/src/tests/ply-boot-splash-test.am +++ /dev/null @@ -1,25 +0,0 @@ -TESTS += ply-boot-splash-test - -ply_boot_splash_test_CFLAGS = $(PLYMOUTH_CFLAGS) -DPLY_BOOT_SPLASH_ENABLE_TEST \ - -DPLYMOUTH_TIME_DIRECTORY=\"/var/lib/plymouth\" \ - -DPLYMOUTH_PLUGIN_PATH=\"$(PLYMOUTH_PLUGIN_PATH)\" \ - -DPLYMOUTH_THEME_PATH=\"$(PLYMOUTH_THEME_PATH)/\" - -ply_boot_splash_test_LDADD = $(PLYMOUTH_LIBS) ../libply/libply.la - -ply_boot_splash_test_SOURCES = \ - $(srcdir)/../libply-splash-core/ply-boot-splash-plugin.h \ - $(srcdir)/../libply-splash-core/ply-keyboard.h \ - $(srcdir)/../libply-splash-core/ply-keyboard.c \ - $(srcdir)/../libply-splash-core/ply-pixel-buffer.h \ - $(srcdir)/../libply-splash-core/ply-pixel-buffer.c \ - $(srcdir)/../libply-splash-core/ply-pixel-display.h \ - $(srcdir)/../libply-splash-core/ply-pixel-display.c \ - $(srcdir)/../libply-splash-core/ply-renderer.h \ - $(srcdir)/../libply-splash-core/ply-renderer.c \ - $(srcdir)/../libply-splash-core/ply-terminal.h \ - $(srcdir)/../libply-splash-core/ply-terminal.c \ - $(srcdir)/../libply-splash-core/ply-text-display.h \ - $(srcdir)/../libply-splash-core/ply-text-display.c \ - $(srcdir)/../libply-splash-core/ply-boot-splash.h \ - $(srcdir)/../libply-splash-core/ply-boot-splash.c From 68fd7da44cbc87f2058823fc325600385bf90409 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 5 Dec 2013 13:09:00 -0500 Subject: [PATCH 11/32] main: require /sys/class/tty/console/active to have plymouth on serial consoles This commit drops the aging fallback code for when /sys/class/tty/console/active is unavailable. This should have no impact for people running recent kernels, and minimal impact for people running old kernels. --- src/main.c | 47 +---------------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) diff --git a/src/main.c b/src/main.c index ab5438b1..283833cd 100644 --- a/src/main.c +++ b/src/main.c @@ -2061,50 +2061,6 @@ add_consoles_from_file (state_t *state, return num_consoles; } -static int -add_consoles_from_kernel_command_line (state_t *state) -{ - const char *console_string; - const char *remaining_command_line; - char *console; - int num_consoles; - - remaining_command_line = state->kernel_command_line; - - num_consoles = 0; - console = NULL; - while ((console_string = command_line_get_string_after_prefix (remaining_command_line, - "console=")) != NULL) - { - char *end; - size_t console_length; - const char *console_device; - ply_terminal_t *terminal; - - remaining_command_line = console_string; - - state->should_force_details = true; - - console = strdup (console_string); - - end = strpbrk (console, " \n\t\v,"); - - if (end != NULL) - *end = '\0'; - - console_length = strlen (console); - - terminal = get_terminal (state, console); - console_device = ply_terminal_get_name (terminal); - - ply_trace ("console %s found!", console_device); - num_consoles++; - remaining_command_line += console_length; - } - - return num_consoles; -} - static void check_for_consoles (state_t *state) { @@ -2124,8 +2080,7 @@ check_for_consoles (state_t *state) if (num_consoles == 0) { - ply_trace ("falling back to kernel command line"); - num_consoles = add_consoles_from_kernel_command_line (state); + ply_trace ("ignoring all consoles but default console because /sys/class/tty/console/active could not be read"); } } else From 7bdd4fc0e132792e446d431cc111e95e7d3448e9 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 3 Dec 2013 16:51:38 -0500 Subject: [PATCH 12/32] main: don't unredirect /dev/console from on_show_splash The code that's there, doesn't make much sense, so this commit removes it. --- src/main.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/main.c b/src/main.c index 283833cd..fb0b90e0 100644 --- a/src/main.c +++ b/src/main.c @@ -949,12 +949,6 @@ on_show_splash (state_t *state) if (!state->is_attached && state->should_be_attached && has_display) attach_to_running_session (state); - if (!has_display) - { - ply_trace ("no open seats"); - detach_from_running_session (state); - } - if (plymouth_should_show_default_splash (state)) { show_default_splash (state); From 6e99200ce23e8a1ae586f803c8baaf9056b4e253 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 5 Dec 2013 14:39:50 -0500 Subject: [PATCH 13/32] main: split start_boot_splash up into two functions Right now start_boot_splash loads the theme, then shows it. It's going to be useful in the future to preload the theme, so this commit breaks the two operations out into two functions, load_theme and show_theme, and makes start_boot_splash just call those two functions. --- src/main.c | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/main.c b/src/main.c index fb0b90e0..b6fd805e 100644 --- a/src/main.c +++ b/src/main.c @@ -125,6 +125,11 @@ typedef struct int number_of_errors; } state_t; +static ply_boot_splash_t *load_theme (state_t *state, + const char *theme_path, + bool fall_back_if_neccessary); +static void show_theme (state_t *state, + ply_boot_splash_t *splash); static ply_boot_splash_t *start_boot_splash (state_t *state, const char *theme_path, bool fall_back_if_neccessary); @@ -1664,12 +1669,11 @@ tell_systemd_to_stop_printing_details (state_t *state) #endif static ply_boot_splash_t * -start_boot_splash (state_t *state, - const char *theme_path, - bool fall_back_if_neccessary) +load_theme (state_t *state, + const char *theme_path, + bool fall_back_if_neccessary) { ply_boot_splash_t *splash; - ply_boot_splash_mode_t splash_mode; bool is_loaded; ply_trace ("Loading boot splash theme '%s'", @@ -1702,7 +1706,14 @@ start_boot_splash (state_t *state, ply_trace ("attaching progress to plugin"); ply_boot_splash_attach_progress (splash, state->progress); - add_displays_and_keyboard_to_boot_splash (state, splash); + return splash; +} + +static void +show_theme (state_t *state, + ply_boot_splash_t *splash) +{ + ply_boot_splash_mode_t splash_mode; ply_trace ("showing plugin"); if (state->mode == PLY_MODE_SHUTDOWN) @@ -1716,7 +1727,7 @@ start_boot_splash (state_t *state, ply_boot_splash_unset_keyboard (splash); ply_boot_splash_free (splash); ply_restore_errno (); - return NULL; + return; } #ifdef PLY_ENABLE_SYSTEMD_INTEGRATION @@ -1728,6 +1739,19 @@ start_boot_splash (state_t *state, ply_keyboard_watch_for_input (state->keyboard); update_display (state); +} + +static ply_boot_splash_t * +start_boot_splash (state_t *state, + const char *theme_path, + bool fall_back_if_necessary) +{ + ply_boot_splash_t *splash; + + splash = load_theme (state, theme_path, fall_back_if_necessary); + add_displays_and_keyboard_to_boot_splash (state, splash); + show_theme (state, splash); + return splash; } From 731db96ca3bb2f3f6654dc51e96299a24fa94161 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 5 Dec 2013 14:51:13 -0500 Subject: [PATCH 14/32] main: load built-in theme instead of details plugin We already have the details theme "built" in, so there's little point in loading the details.so plugin when we want details internally. This commit fixes that. --- src/main.c | 46 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/src/main.c b/src/main.c index b6fd805e..db5d293b 100644 --- a/src/main.c +++ b/src/main.c @@ -125,6 +125,7 @@ typedef struct int number_of_errors; } state_t; +static ply_boot_splash_t *load_built_in_theme (state_t *state); static ply_boot_splash_t *load_theme (state_t *state, const char *theme_path, bool fall_back_if_neccessary); @@ -311,18 +312,24 @@ show_messages (state_t *state) static void show_detailed_splash (state_t *state) { + ply_boot_splash_t *splash; + if (state->boot_splash != NULL) return; ply_trace ("Showing detailed splash screen"); - state->boot_splash = start_boot_splash (state, - PLYMOUTH_THEME_PATH "details/details.plymouth", - true); + splash = load_built_in_theme (state); - if (state->boot_splash == NULL) + if (splash == NULL) { ply_trace ("Could not start detailed splash screen, this could be a problem."); + return; } + + state->boot_splash = splash; + + add_displays_and_keyboard_to_boot_splash (state, state->boot_splash); + show_theme (state, state->boot_splash); } static const char * @@ -1668,6 +1675,37 @@ tell_systemd_to_stop_printing_details (state_t *state) } #endif +static ply_boot_splash_t * +load_built_in_theme (state_t *state) +{ + ply_boot_splash_t *splash; + bool is_loaded; + + ply_trace ("Loading built-in theme"); + + splash = ply_boot_splash_new ("", + PLYMOUTH_PLUGIN_PATH, + state->boot_buffer); + + is_loaded = ply_boot_splash_load_built_in (splash); + + if (!is_loaded) + { + ply_save_errno (); + ply_boot_splash_free (splash); + ply_restore_errno (); + return NULL; + } + + ply_trace ("attaching plugin to event loop"); + ply_boot_splash_attach_to_event_loop (splash, state->loop); + + ply_trace ("attaching progress to plugin"); + ply_boot_splash_attach_progress (splash, state->progress); + + return splash; +} + static ply_boot_splash_t * load_theme (state_t *state, const char *theme_path, From 09428a1b012f50b0ffdc3e683d0670e3d908fcca Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 5 Dec 2013 14:58:19 -0500 Subject: [PATCH 15/32] main: drop fall back feature of load_theme load_theme currently takes a boolean that if true, will make it load the built-in "details" plugin if the main plugin fails to load. Boolean arguments are hard to read, so this commit drops it. --- src/main.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/main.c b/src/main.c index db5d293b..0f2372f6 100644 --- a/src/main.c +++ b/src/main.c @@ -127,8 +127,7 @@ typedef struct static ply_boot_splash_t *load_built_in_theme (state_t *state); static ply_boot_splash_t *load_theme (state_t *state, - const char *theme_path, - bool fall_back_if_neccessary); + const char *theme_path); static void show_theme (state_t *state, ply_boot_splash_t *splash); static ply_boot_splash_t *start_boot_splash (state_t *state, @@ -1708,8 +1707,7 @@ load_built_in_theme (state_t *state) static ply_boot_splash_t * load_theme (state_t *state, - const char *theme_path, - bool fall_back_if_neccessary) + const char *theme_path) { ply_boot_splash_t *splash; bool is_loaded; @@ -1722,13 +1720,6 @@ load_theme (state_t *state, state->boot_buffer); is_loaded = ply_boot_splash_load (splash); - if (!is_loaded && fall_back_if_neccessary) - { - ply_trace ("Splash couldn't be loaded: %m"); - - ply_trace ("Loading built in splash"); - is_loaded = ply_boot_splash_load_built_in (splash); - } if (!is_loaded) { @@ -1786,7 +1777,14 @@ start_boot_splash (state_t *state, { ply_boot_splash_t *splash; - splash = load_theme (state, theme_path, fall_back_if_necessary); + splash = load_theme (state, theme_path); + + if (splash == NULL && fall_back_if_neccessary) + splash = load_built_in_theme (state); + + if (splash == NULL) + return NULL; + add_displays_and_keyboard_to_boot_splash (state, splash); show_theme (state, splash); From a6eddfd839dbf2a5aa6784d81d11d781bf27d8e9 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Thu, 5 Dec 2013 15:02:35 -0500 Subject: [PATCH 16/32] main: get rid of start_boot_splash start_boot_splash is a convenience function that's going to get in the way in the future. It also has the annoying "boolean argument" problem that load_theme had. This commit gets rid of start_boot_splash entirely. --- src/main.c | 62 +++++++++++++++--------------------------------------- 1 file changed, 17 insertions(+), 45 deletions(-) diff --git a/src/main.c b/src/main.c index 0f2372f6..561396bf 100644 --- a/src/main.c +++ b/src/main.c @@ -130,14 +130,13 @@ static ply_boot_splash_t *load_theme (state_t *state, const char *theme_path); static void show_theme (state_t *state, ply_boot_splash_t *splash); -static ply_boot_splash_t *start_boot_splash (state_t *state, - const char *theme_path, - bool fall_back_if_neccessary); static void add_display_and_keyboard_for_terminal (state_t *state, ply_terminal_t *terminal); static void add_default_displays_and_keyboard (state_t *state); +static void add_displays_and_keyboard_to_boot_splash (state_t *state, + ply_boot_splash_t *splash); static bool attach_to_running_session (state_t *state); static void detach_from_running_session (state_t *state); @@ -327,7 +326,6 @@ show_detailed_splash (state_t *state) state->boot_splash = splash; - add_displays_and_keyboard_to_boot_splash (state, state->boot_splash); show_theme (state, state->boot_splash); } @@ -463,9 +461,7 @@ show_default_splash (state_t *state) if (state->override_splash_path != NULL) { ply_trace ("Trying override splash at '%s'", state->override_splash_path); - state->boot_splash = start_boot_splash (state, - state->override_splash_path, - false); + state->boot_splash = load_theme (state, state->override_splash_path); } find_system_default_splash (state); @@ -473,9 +469,7 @@ show_default_splash (state_t *state) state->system_default_splash_path != NULL) { ply_trace ("Trying system default splash"); - state->boot_splash = start_boot_splash (state, - state->system_default_splash_path, - false); + state->boot_splash = load_theme (state, state->system_default_splash_path); } find_distribution_default_splash (state); @@ -483,39 +477,36 @@ show_default_splash (state_t *state) state->distribution_default_splash_path != NULL) { ply_trace ("Trying distribution default splash"); - state->boot_splash = start_boot_splash (state, - state->distribution_default_splash_path, - false); + state->boot_splash = load_theme (state, state->distribution_default_splash_path); } if (state->boot_splash == NULL) { ply_trace ("Trying old scheme for default splash"); - state->boot_splash = start_boot_splash (state, - PLYMOUTH_THEME_PATH "default.plymouth", - false); + state->boot_splash = load_theme (state, PLYMOUTH_THEME_PATH "default.plymouth"); } if (state->boot_splash == NULL) { ply_trace ("Could not start default splash screen," "showing text splash screen"); - state->boot_splash = start_boot_splash (state, - PLYMOUTH_THEME_PATH "text/text.plymouth", - false); + state->boot_splash = load_theme (state, PLYMOUTH_THEME_PATH "text/text.plymouth"); } if (state->boot_splash == NULL) { ply_trace ("Could not start text splash screen," - "showing built-in fallback"); - state->boot_splash = start_boot_splash (state, - PLYMOUTH_THEME_PATH "text/text.plymouth", - true); + "showing built-in splash screen"); + state->boot_splash = load_built_in_theme (state); } if (state->boot_splash == NULL) - ply_error ("plymouthd: could not start boot splash: %m"); + { + ply_error ("plymouthd: could not start boot splash: %m"); + return; + } + + show_theme (state, state->boot_splash); } static void @@ -1744,6 +1735,8 @@ show_theme (state_t *state, { ply_boot_splash_mode_t splash_mode; + add_displays_and_keyboard_to_boot_splash (state, state->boot_splash); + ply_trace ("showing plugin"); if (state->mode == PLY_MODE_SHUTDOWN) splash_mode = PLY_BOOT_SPLASH_MODE_SHUTDOWN; @@ -1770,27 +1763,6 @@ show_theme (state_t *state, update_display (state); } -static ply_boot_splash_t * -start_boot_splash (state_t *state, - const char *theme_path, - bool fall_back_if_necessary) -{ - ply_boot_splash_t *splash; - - splash = load_theme (state, theme_path); - - if (splash == NULL && fall_back_if_neccessary) - splash = load_built_in_theme (state); - - if (splash == NULL) - return NULL; - - add_displays_and_keyboard_to_boot_splash (state, splash); - show_theme (state, splash); - - return splash; -} - static bool attach_to_running_session (state_t *state) { From a36c0bec2b24d50770fde1880e181de1fcc1f4dc Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Fri, 29 Nov 2013 11:03:14 -0500 Subject: [PATCH 17/32] splash-core: add new seat object Right now we maintain parallel lists of displays in several different layers of code. This commit introduces a "seat" object to encapsulate a set of displays, and associated input device. A subsequently commit will actually change the code over to use the seat object. --- src/libply-splash-core/Makefile.am | 2 + src/libply-splash-core/ply-seat.c | 347 +++++++++++++++++++++++++++++ src/libply-splash-core/ply-seat.h | 61 +++++ 3 files changed, 410 insertions(+) create mode 100644 src/libply-splash-core/ply-seat.c create mode 100644 src/libply-splash-core/ply-seat.h diff --git a/src/libply-splash-core/Makefile.am b/src/libply-splash-core/Makefile.am index 1758556a..e05dcb33 100644 --- a/src/libply-splash-core/Makefile.am +++ b/src/libply-splash-core/Makefile.am @@ -20,6 +20,7 @@ libply_splash_core_HEADERS = \ ply-pixel-display.h \ ply-renderer.h \ ply-renderer-plugin.h \ + ply-seat.h \ ply-terminal.h \ ply-text-display.h \ ply-text-progress-bar.h \ @@ -44,6 +45,7 @@ libply_splash_core_la_SOURCES = \ ply-terminal.c \ ply-pixel-buffer.c \ ply-renderer.c \ + ply-seat.c \ ply-boot-splash.c MAINTAINERCLEANFILES = Makefile.in diff --git a/src/libply-splash-core/ply-seat.c b/src/libply-splash-core/ply-seat.c new file mode 100644 index 00000000..82bbb894 --- /dev/null +++ b/src/libply-splash-core/ply-seat.c @@ -0,0 +1,347 @@ +/* ply-seat.c - APIs for encapsulating a keyboard and one or more displays + * + * Copyright (C) 2013 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written by: Ray Strode + */ +#include "config.h" +#include "ply-seat.h" + +#include +#include +#include +#include +#include +#include + +#include "ply-event-loop.h" +#include "ply-keyboard.h" +#include "ply-pixel-display.h" +#include "ply-text-display.h" +#include "ply-list.h" +#include "ply-logger.h" +#include "ply-utils.h" + +struct _ply_seat +{ + ply_event_loop_t *loop; + + ply_terminal_t *terminal; + ply_renderer_t *renderer; + ply_keyboard_t *keyboard; + ply_list_t *text_displays; + ply_list_t *pixel_displays; + + uint32_t renderer_active : 1; + uint32_t keyboard_active : 1; +}; + +ply_seat_t * +ply_seat_new (ply_terminal_t *terminal) +{ + ply_seat_t *seat; + + seat = calloc (1, sizeof (ply_seat_t)); + + seat->loop = ply_event_loop_get_default (); + seat->terminal = terminal; + seat->text_displays = ply_list_new (); + seat->pixel_displays = ply_list_new (); + + return seat; +} + +static void +add_pixel_displays (ply_seat_t *seat) +{ + ply_list_t *heads; + ply_list_node_t *node; + + heads = ply_renderer_get_heads (seat->renderer); + + ply_trace ("Adding displays for %d heads", + ply_list_get_length (heads)); + + node = ply_list_get_first_node (heads); + while (node != NULL) + { + ply_list_node_t *next_node; + ply_renderer_head_t *head; + ply_pixel_display_t *display; + + head = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (heads, node); + + display = ply_pixel_display_new (seat->renderer, head); + + ply_list_append_data (seat->pixel_displays, display); + + node = next_node; + } +} + +static void +add_text_displays (ply_seat_t *seat) +{ + ply_text_display_t *display; + + display = ply_text_display_new (seat->terminal); + ply_list_append_data (seat->text_displays, display); +} + +bool +ply_seat_open (ply_seat_t *seat, + ply_renderer_type_t renderer_type, + const char *device) +{ + if (renderer_type != PLY_RENDERER_TYPE_NONE) + { + ply_renderer_t *renderer; + + renderer = ply_renderer_new (renderer_type, device, seat->terminal); + + if (!ply_renderer_open (renderer) && renderer_type != PLY_RENDERER_TYPE_AUTO) + { + ply_trace ("could not open renderer for %s", device); + ply_renderer_free (renderer); + return false; + } + + seat->renderer = renderer; + seat->renderer_active = true; + } + + if (seat->renderer != NULL) + { + seat->keyboard = ply_keyboard_new_for_renderer (seat->renderer); + add_pixel_displays (seat); + + } + else + { + seat->keyboard = ply_keyboard_new_for_terminal (seat->terminal); + add_text_displays (seat); + } + seat->keyboard_active = true; + + return true; +} + +bool +ply_seat_is_open (ply_seat_t *seat) +{ + return ply_list_get_length (seat->pixel_displays) > 0 || + ply_list_get_length (seat->text_displays) > 0; +} + +void +ply_seat_deactivate_keyboard (ply_seat_t *seat) +{ + if (!seat->keyboard_active) + return; + + seat->keyboard_active = false; + + if (seat->keyboard == NULL) + return; + + ply_trace ("deactivating keybord"); + ply_keyboard_stop_watching_for_input (seat->keyboard); +} + +void +ply_seat_deactivate_renderer (ply_seat_t *seat) +{ + if (!seat->renderer_active) + return; + + seat->renderer_active = false; + + if (seat->renderer == NULL) + return; + + ply_trace ("deactivating renderer"); + ply_renderer_deactivate (seat->renderer); +} + +void +ply_seat_activate_keyboard (ply_seat_t *seat) +{ + if (seat->keyboard_active) + return; + + if (seat->keyboard == NULL) + return; + + ply_trace ("activating keyboard"); + ply_keyboard_watch_for_input (seat->keyboard); + + seat->keyboard_active = true; +} + +void +ply_seat_activate_renderer (ply_seat_t *seat) +{ + if (seat->renderer_active) + return; + + if (seat->renderer == NULL) + return; + + ply_trace ("activating renderer"); + ply_renderer_activate (seat->renderer); + + seat->renderer_active = true; +} + +void +ply_seat_refresh_displays (ply_seat_t *seat) +{ + ply_list_node_t *node; + + node = ply_list_get_first_node (seat->pixel_displays); + while (node != NULL) + { + ply_pixel_display_t *display; + ply_list_node_t *next_node; + unsigned long width, height; + + display = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (seat->pixel_displays, node); + + width = ply_pixel_display_get_width (display); + height = ply_pixel_display_get_height (display); + + ply_pixel_display_draw_area (display, 0, 0, width, height); + node = next_node; + } + + node = ply_list_get_first_node (seat->text_displays); + while (node != NULL) + { + ply_text_display_t *display; + ply_list_node_t *next_node; + int number_of_columns, number_of_rows; + + display = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (seat->text_displays, node); + + number_of_columns = ply_text_display_get_number_of_columns (display); + number_of_rows = ply_text_display_get_number_of_rows (display); + + ply_text_display_draw_area (display, 0, 0, + number_of_columns, + number_of_rows); + node = next_node; + } +} + +void +ply_seat_close (ply_seat_t *seat) +{ + if (seat->renderer == NULL) + return; + + ply_trace ("destroying renderer"); + ply_renderer_close (seat->renderer); + ply_renderer_free (seat->renderer); + seat->renderer = NULL; +} + +static void +free_pixel_displays (ply_seat_t *seat) +{ + ply_list_node_t *node; + + ply_trace ("freeing %d pixel displays", ply_list_get_length (seat->pixel_displays)); + node = ply_list_get_first_node (seat->pixel_displays); + while (node != NULL) + { + ply_list_node_t *next_node; + ply_pixel_display_t *display; + + next_node = ply_list_get_next_node (seat->pixel_displays, node); + display = ply_list_node_get_data (node); + ply_pixel_display_free (display); + + ply_list_remove_node (seat->pixel_displays, node); + + node = next_node; + } +} + +static void +free_text_displays (ply_seat_t *seat) +{ + ply_list_node_t *node; + + ply_trace ("freeing %d text displays", ply_list_get_length (seat->text_displays)); + node = ply_list_get_first_node (seat->text_displays); + while (node != NULL) + { + ply_list_node_t *next_node; + ply_text_display_t *display; + + next_node = ply_list_get_next_node (seat->text_displays, node); + display = ply_list_node_get_data (node); + ply_text_display_free (display); + + ply_list_remove_node (seat->text_displays, node); + + node = next_node; + } +} + +void +ply_seat_free (ply_seat_t *seat) +{ + if (seat == NULL) + return; + + free_pixel_displays (seat); + free_text_displays (seat); + ply_keyboard_free (seat->keyboard); + + free (seat); +} + +ply_list_t * +ply_seat_get_pixel_displays (ply_seat_t *seat) +{ + return seat->pixel_displays; +} + +ply_list_t * +ply_seat_get_text_displays (ply_seat_t *seat) +{ + return seat->text_displays; +} + +ply_keyboard_t * +ply_seat_get_keyboard (ply_seat_t *seat) +{ + return seat->keyboard; +} + +ply_renderer_t * +ply_seat_get_renderer (ply_seat_t *seat) +{ + return seat->renderer; +} + +/* vim: set ts=4 sw=4 et ai ci cino={.5s,^-2,+.5s,t0,g0,e-2,n-2,p2s,(0,=.5s,:.5s */ diff --git a/src/libply-splash-core/ply-seat.h b/src/libply-splash-core/ply-seat.h new file mode 100644 index 00000000..73927789 --- /dev/null +++ b/src/libply-splash-core/ply-seat.h @@ -0,0 +1,61 @@ +/* ply-seat.h - APIs for encapsulating a keyboard and one or more displays + * + * Copyright (C) 2013 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * Written By: Ray Strode + */ +#ifndef PLY_SEAT_H +#define PLY_SEAT_H + +#include +#include +#include +#include + +#include "ply-buffer.h" +#include "ply-event-loop.h" +#include "ply-keyboard.h" +#include "ply-list.h" +#include "ply-pixel-display.h" +#include "ply-terminal.h" +#include "ply-text-display.h" + +typedef struct _ply_seat ply_seat_t; + +#ifndef PLY_HIDE_FUNCTION_DECLARATIONS +ply_seat_t *ply_seat_new (ply_terminal_t *terminal); + +void ply_seat_free (ply_seat_t *seat); +bool ply_seat_open (ply_seat_t *seat, + ply_renderer_type_t renderer_type, + const char *device); +bool ply_seat_is_open (ply_seat_t *seat); +void ply_seat_deactivate_keyboard (ply_seat_t *seat); +void ply_seat_activate_keyboard (ply_seat_t *seat); +void ply_seat_deactivate_renderer (ply_seat_t *seat); +void ply_seat_activate_renderer (ply_seat_t *seat); +void ply_seat_refresh_displays (ply_seat_t *seat); +void ply_seat_close (ply_seat_t *seat); +ply_list_t *ply_seat_get_pixel_displays (ply_seat_t *seat); +ply_list_t *ply_seat_get_text_displays (ply_seat_t *seat); +ply_keyboard_t *ply_seat_get_keyboard (ply_seat_t *seat); +ply_renderer_t *ply_seat_get_renderer (ply_seat_t *seat); +#endif + +#endif /* PLY_SEAT_H */ +/* vim: set ts=4 sw=4 et ai ci cino={.5s,^-2,+.5s,t0,g0,e-2,n-2,p2s,(0,=.5s,:.5s */ From 24a21ee0f3aaeb6f648dab429c5df6b910f89002 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Fri, 29 Nov 2013 11:28:52 -0500 Subject: [PATCH 18/32] boot-splash: add support for seat objects ply_boot_splash_t currently gets notified about displays and keyboard objects to pass along to the splash plugins. Now that we have a ply_seat_t object that can encapsulate display and keyboard objects, we should add support to ply_boot_splash_t for using it. This commit does that. For now, it does it without changing the plugin interface (which is still in terms of displays and keyboards). Note, this commit only adds support for seat objects to ply_boot_splash_t. It doesn't actually change any of the calling code to use that support. That will come in a subsequent commit. --- src/libply-splash-core/ply-boot-splash.c | 191 +++++++++++++++++++++++ src/libply-splash-core/ply-boot-splash.h | 6 + src/libply-splash-core/ply-seat.c | 18 +++ src/libply-splash-core/ply-seat.h | 5 + 4 files changed, 220 insertions(+) diff --git a/src/libply-splash-core/ply-boot-splash.c b/src/libply-splash-core/ply-boot-splash.c index cf052915..86708374 100644 --- a/src/libply-splash-core/ply-boot-splash.c +++ b/src/libply-splash-core/ply-boot-splash.c @@ -58,6 +58,7 @@ struct _ply_boot_splash ply_keyboard_t *keyboard; ply_buffer_t *boot_buffer; ply_trigger_t *idle_trigger; + ply_list_t *seats; ply_list_t *pixel_displays; ply_list_t *text_displays; @@ -98,6 +99,7 @@ ply_boot_splash_new (const char *theme_path, splash->boot_buffer = boot_buffer; splash->pixel_displays = ply_list_new (); splash->text_displays = ply_list_new (); + splash->seats = ply_list_new (); return splash; } @@ -117,6 +119,9 @@ ply_boot_splash_set_keyboard (ply_boot_splash_t *splash, void ply_boot_splash_unset_keyboard (ply_boot_splash_t *splash) { + if (splash->keyboard == NULL) + return; + if (splash->plugin_interface->set_keyboard == NULL) return; @@ -171,6 +176,165 @@ ply_boot_splash_remove_text_display (ply_boot_splash_t *splash, splash->plugin_interface->remove_text_display (splash->plugin, display); } +static void +detach_from_seat (ply_boot_splash_t *splash, + ply_seat_t *seat) +{ + ply_keyboard_t *keyboard; + ply_list_t *displays; + ply_list_node_t *node, *next_node; + + ply_trace ("removing keyboard"); + if (splash->plugin_interface->unset_keyboard != NULL) + { + keyboard = ply_seat_get_keyboard (seat); + splash->plugin_interface->unset_keyboard (splash->plugin, keyboard); + } + + ply_trace ("removing pixel displays"); + displays = ply_seat_get_pixel_displays (seat); + + node = ply_list_get_first_node (displays); + while (node != NULL) + { + ply_pixel_display_t *display; + ply_list_node_t *next_node; + unsigned long width, height; + + display = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (displays, node); + + width = ply_pixel_display_get_width (display); + height = ply_pixel_display_get_height (display); + + ply_trace ("Removing %lux%lu pixel display", width, height); + + if (splash->plugin_interface->remove_pixel_display != NULL) + splash->plugin_interface->remove_pixel_display (splash->plugin, display); + + node = next_node; + } + + ply_trace ("removing text displays"); + displays = ply_seat_get_text_displays (seat); + + node = ply_list_get_first_node (displays); + while (node != NULL) + { + ply_text_display_t *display; + int number_of_columns, number_of_rows; + + display = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (displays, node); + + number_of_columns = ply_text_display_get_number_of_columns (display); + number_of_rows = ply_text_display_get_number_of_rows (display); + + ply_trace ("Removing %dx%d text display", number_of_columns, number_of_rows); + + if (splash->plugin_interface->remove_text_display != NULL) + splash->plugin_interface->remove_text_display (splash->plugin, display); + + node = next_node; + } +} + +static void +attach_to_seat (ply_boot_splash_t *splash, + ply_seat_t *seat) +{ + ply_keyboard_t *keyboard; + ply_list_t *displays; + ply_list_node_t *node, *next_node; + + if (splash->plugin_interface->set_keyboard != NULL) + { + keyboard = ply_seat_get_keyboard (seat); + splash->plugin_interface->set_keyboard (splash->plugin, keyboard); + } + + if (splash->plugin_interface->add_pixel_display != NULL) + { + displays = ply_seat_get_pixel_displays (seat); + + ply_trace ("adding pixel displays"); + node = ply_list_get_first_node (displays); + while (node != NULL) + { + ply_pixel_display_t *display; + ply_list_node_t *next_node; + unsigned long width, height; + + display = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (displays, node); + + width = ply_pixel_display_get_width (display); + height = ply_pixel_display_get_height (display); + + ply_trace ("Adding %lux%lu pixel display", width, height); + + splash->plugin_interface->add_pixel_display (splash->plugin, display); + + node = next_node; + } + } + + if (splash->plugin_interface->add_text_display != NULL) + { + displays = ply_seat_get_text_displays (seat); + + ply_trace ("adding text displays"); + node = ply_list_get_first_node (displays); + while (node != NULL) + { + ply_text_display_t *display; + int number_of_columns, number_of_rows; + + display = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (displays, node); + + number_of_columns = ply_text_display_get_number_of_columns (display); + number_of_rows = ply_text_display_get_number_of_rows (display); + + ply_trace ("Adding %dx%d text display", number_of_columns, number_of_rows); + + splash->plugin_interface->add_text_display (splash->plugin, display); + + node = next_node; + } + } +} + +void +ply_boot_splash_attach_to_seat (ply_boot_splash_t *splash, + ply_seat_t *seat) +{ + ply_list_node_t *node; + + node = ply_list_find_node (splash->seats, seat); + + if (node != NULL) + return; + + ply_list_append_data (splash->seats, seat); + attach_to_seat (splash, seat); +} + +void +ply_boot_splash_detach_from_seat (ply_boot_splash_t *splash, + ply_seat_t *seat) +{ + ply_list_node_t *node; + + node = ply_list_find_node (splash->seats, seat); + + if (node == NULL) + return; + + ply_list_remove_data (splash->seats, seat); + detach_from_seat (splash, seat); +} + bool ply_boot_splash_load (ply_boot_splash_t *splash) { @@ -359,6 +523,30 @@ remove_displays (ply_boot_splash_t *splash) } } +static void +detach_from_seats (ply_boot_splash_t *splash) +{ + ply_list_node_t *node; + + ply_trace ("detaching from seats"); + + node = ply_list_get_first_node (splash->seats); + while (node != NULL) + { + ply_seat_t *seat; + ply_list_node_t *next_node; + + seat = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (splash->seats, node); + + detach_from_seat (splash, seat); + + ply_list_remove_node (splash->seats, node); + + node = next_node; + } +} + void ply_boot_splash_free (ply_boot_splash_t *splash) { @@ -384,6 +572,9 @@ ply_boot_splash_free (ply_boot_splash_t *splash) ply_list_free (splash->pixel_displays); ply_list_free (splash->text_displays); + detach_from_seats (splash); + ply_list_free (splash->seats); + if (splash->module_handle != NULL) ply_boot_splash_unload (splash); diff --git a/src/libply-splash-core/ply-boot-splash.h b/src/libply-splash-core/ply-boot-splash.h index a79e9396..3f66b70d 100644 --- a/src/libply-splash-core/ply-boot-splash.h +++ b/src/libply-splash-core/ply-boot-splash.h @@ -33,10 +33,12 @@ #include "ply-pixel-display.h" #include "ply-text-display.h" #include "ply-progress.h" +#include "ply-seat.h" #include "ply-boot-splash-plugin.h" typedef struct _ply_boot_splash ply_boot_splash_t; +typedef struct _ply_seat ply_seat_t; typedef void (* ply_boot_splash_on_idle_handler_t) (void *user_data); @@ -48,6 +50,10 @@ ply_boot_splash_t *ply_boot_splash_new (const char * theme_path, bool ply_boot_splash_load (ply_boot_splash_t *splash); bool ply_boot_splash_load_built_in (ply_boot_splash_t *splash); void ply_boot_splash_unload (ply_boot_splash_t *splash); +void ply_boot_splash_attach_to_seat (ply_boot_splash_t *splash, + ply_seat_t *seat); +void ply_boot_splash_detach_from_seat (ply_boot_splash_t *splash, + ply_seat_t *seat); void ply_boot_splash_set_keyboard (ply_boot_splash_t *splash, ply_keyboard_t *keyboard); void ply_boot_splash_unset_keyboard (ply_boot_splash_t *splash); diff --git a/src/libply-splash-core/ply-seat.c b/src/libply-splash-core/ply-seat.c index 82bbb894..d1493a71 100644 --- a/src/libply-splash-core/ply-seat.c +++ b/src/libply-splash-core/ply-seat.c @@ -29,6 +29,7 @@ #include #include +#include "ply-boot-splash.h" #include "ply-event-loop.h" #include "ply-keyboard.h" #include "ply-pixel-display.h" @@ -41,6 +42,7 @@ struct _ply_seat { ply_event_loop_t *loop; + ply_boot_splash_t *splash; ply_terminal_t *terminal; ply_renderer_t *renderer; ply_keyboard_t *keyboard; @@ -263,6 +265,22 @@ ply_seat_close (ply_seat_t *seat) seat->renderer = NULL; } +void +ply_seat_set_splash (ply_seat_t *seat, + ply_boot_splash_t *splash) +{ + if (seat->splash == splash) + return; + + if (seat->splash != NULL) + ply_boot_splash_detach_from_seat (splash, seat); + + if (splash != NULL) + ply_boot_splash_attach_to_seat (splash, seat); + + seat->splash = splash; +} + static void free_pixel_displays (ply_seat_t *seat) { diff --git a/src/libply-splash-core/ply-seat.h b/src/libply-splash-core/ply-seat.h index 73927789..d5d33978 100644 --- a/src/libply-splash-core/ply-seat.h +++ b/src/libply-splash-core/ply-seat.h @@ -27,6 +27,7 @@ #include #include +#include "ply-boot-splash.h" #include "ply-buffer.h" #include "ply-event-loop.h" #include "ply-keyboard.h" @@ -35,6 +36,7 @@ #include "ply-terminal.h" #include "ply-text-display.h" +typedef struct _ply_boot_splash ply_boot_splash_t; typedef struct _ply_seat ply_seat_t; #ifndef PLY_HIDE_FUNCTION_DECLARATIONS @@ -51,6 +53,9 @@ void ply_seat_deactivate_renderer (ply_seat_t *seat); void ply_seat_activate_renderer (ply_seat_t *seat); void ply_seat_refresh_displays (ply_seat_t *seat); void ply_seat_close (ply_seat_t *seat); +void ply_seat_set_splash (ply_seat_t *seat, + ply_boot_splash_t *splash); + ply_list_t *ply_seat_get_pixel_displays (ply_seat_t *seat); ply_list_t *ply_seat_get_text_displays (ply_seat_t *seat); ply_keyboard_t *ply_seat_get_keyboard (ply_seat_t *seat); From b8883565dd9ae831ec0337129632565cb71a66f9 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Fri, 29 Nov 2013 22:45:19 -0500 Subject: [PATCH 19/32] main: port over to seat objects We create one seat object for the main display and one seat for each serial console. --- src/main.c | 475 +++++++++++++++++++++++------------------------------ 1 file changed, 208 insertions(+), 267 deletions(-) diff --git a/src/main.c b/src/main.c index 561396bf..3de6ac62 100644 --- a/src/main.c +++ b/src/main.c @@ -47,6 +47,7 @@ #include "ply-hashtable.h" #include "ply-list.h" #include "ply-logger.h" +#include "ply-renderer.h" #include "ply-terminal-session.h" #include "ply-trigger.h" #include "ply-utils.h" @@ -85,9 +86,7 @@ typedef struct ply_event_loop_t *loop; ply_boot_server_t *boot_server; ply_hashtable_t *terminals; - ply_list_t *pixel_displays; - ply_list_t *text_displays; - ply_keyboard_t *keyboard; + ply_hashtable_t *seats; ply_boot_splash_t *boot_splash; ply_terminal_session_t *session; ply_buffer_t *boot_buffer; @@ -98,7 +97,6 @@ typedef struct ply_list_t *messages; ply_command_parser_t *command_parser; ply_mode_t mode; - ply_renderer_t *renderer; ply_terminal_t *local_console_terminal; ply_trigger_t *deactivate_trigger; @@ -115,6 +113,7 @@ typedef struct uint32_t should_retain_splash : 1; uint32_t is_inactive : 1; uint32_t is_shown : 1; + uint32_t has_open_seats : 1; uint32_t should_force_details : 1; char *override_splash_path; @@ -131,10 +130,6 @@ static ply_boot_splash_t *load_theme (state_t *state, static void show_theme (state_t *state, ply_boot_splash_t *splash); -static void add_display_and_keyboard_for_terminal (state_t *state, - ply_terminal_t *terminal); - -static void add_default_displays_and_keyboard (state_t *state); static void add_displays_and_keyboard_to_boot_splash (state_t *state, ply_boot_splash_t *splash); @@ -157,6 +152,116 @@ static void tell_systemd_to_print_details (state_t *state); static void tell_systemd_to_stop_printing_details (state_t *state); #endif static const char * get_cache_file_for_mode (ply_mode_t mode); +static void on_escape_pressed (state_t *state); +static void on_enter (state_t *state, + const char *line); +static void on_keyboard_input (state_t *state, + const char *keyboard_input, + size_t character_size); +static void on_backspace (state_t *state); + +static void +detach_from_seat (const char *device_path, + ply_seat_t *seat, + state_t *state) +{ + ply_hashtable_remove (state->seats, (void *) device_path); + ply_seat_free (seat); +} + +static void +detach_from_seats (state_t *state) +{ + ply_trace ("removing seats"); + ply_hashtable_foreach (state->seats, + (ply_hashtable_foreach_func_t *) + detach_from_seat, + state); +} + +static void +ensure_seat_for_terminal_and_renderer_type (state_t *state, + const char *device_path, + ply_terminal_t *terminal, + ply_renderer_type_t renderer_type) +{ + ply_seat_t *seat; + bool has_seat; + ply_keyboard_t *keyboard; + + seat = ply_hashtable_lookup (state->seats, (void *) device_path); + + if (seat != NULL) + { + has_seat = true; + } + else + { + has_seat = false; + seat = ply_seat_new (terminal); + } + + if (!ply_seat_is_open (seat)) + state->has_open_seats = ply_seat_open (seat, renderer_type, NULL); + + keyboard = ply_seat_get_keyboard (seat); + ply_keyboard_add_escape_handler (keyboard, + (ply_keyboard_escape_handler_t) + on_escape_pressed, state); + ply_trace ("listening for keystrokes"); + ply_keyboard_add_input_handler (keyboard, + (ply_keyboard_input_handler_t) + on_keyboard_input, state); + ply_trace ("listening for backspace"); + ply_keyboard_add_backspace_handler (keyboard, + (ply_keyboard_backspace_handler_t) + on_backspace, state); + ply_trace ("listening for enter"); + ply_keyboard_add_enter_handler (keyboard, + (ply_keyboard_enter_handler_t) + on_enter, state); + + if (!has_seat) + ply_hashtable_insert (state->seats, strdup (device_path), seat); +} + +static void +ensure_seat_for_terminal (const char *device_path, + ply_terminal_t *terminal, + state_t *state) +{ + ensure_seat_for_terminal_and_renderer_type (state, + device_path, + terminal, + PLY_RENDERER_TYPE_NONE); +} + +static void +open_closed_seats (state_t *state) +{ + int number_of_terminals; + ply_terminal_t *default_terminal; + + number_of_terminals = ply_hashtable_get_size (state->terminals); + default_terminal = ply_hashtable_lookup (state->terminals, (void *) state->default_tty); + + if ((number_of_terminals == 0) || + ((number_of_terminals == 1) && + (default_terminal != NULL))) + { + ensure_seat_for_terminal_and_renderer_type (state, + state->default_tty, + default_terminal, + PLY_RENDERER_TYPE_AUTO); + } + else + { + ply_hashtable_foreach (state->terminals, + (ply_hashtable_foreach_func_t *) + ensure_seat_for_terminal, + state); + } +} static void free_terminal (char *device, @@ -203,6 +308,9 @@ get_terminal (state_t *state, { terminal = ply_terminal_new (full_name); + if (strcmp (full_name, state->default_tty) == 0) + state->local_console_terminal = terminal; + ply_hashtable_insert (state->terminals, (void *) ply_terminal_get_name (terminal), terminal); } free (full_name); @@ -871,57 +979,9 @@ plymouth_should_show_default_splash (state_t *state) return false; } -static void -remove_displays_and_keyboard (state_t *state) -{ - ply_list_node_t *node; - ply_trace ("removing displays and keyboard"); - - node = ply_list_get_first_node (state->pixel_displays); - while (node != NULL) - { - ply_list_node_t *next_node; - ply_pixel_display_t *display; - - ply_trace ("removing pixel display"); - next_node = ply_list_get_next_node (state->pixel_displays, node); - display = ply_list_node_get_data (node); - ply_pixel_display_free (display); - - ply_list_remove_node (state->pixel_displays, node); - - node = next_node; - } - - node = ply_list_get_first_node (state->text_displays); - while (node != NULL) - { - ply_list_node_t *next_node; - ply_text_display_t *display; - - ply_trace ("removing text display"); - next_node = ply_list_get_next_node (state->text_displays, node); - display = ply_list_node_get_data (node); - ply_text_display_free (display); - - ply_list_remove_node (state->text_displays, node); - - node = next_node; - } - - if (state->keyboard != NULL) - { - ply_trace ("removing keyboard"); - ply_keyboard_free (state->keyboard); - state->keyboard = NULL; - } -} - static void on_show_splash (state_t *state) { - bool has_display; - if (state->is_shown) { ply_trace ("show splash called while already shown"); @@ -944,11 +1004,9 @@ on_show_splash (state_t *state) state->is_shown = true; check_for_consoles (state); + open_closed_seats (state); - has_display = ply_list_get_length (state->pixel_displays) > 0 || - ply_list_get_length (state->text_displays) > 0; - - if (!state->is_attached && state->should_be_attached && has_display) + if (!state->is_attached && state->should_be_attached && state->has_open_seats) attach_to_running_session (state); if (plymouth_should_show_default_splash (state)) @@ -976,14 +1034,7 @@ quit_splash (state_t *state) } ply_trace ("removing displays and keyboard"); - remove_displays_and_keyboard (state); - - if (state->renderer != NULL) - { - ply_renderer_close (state->renderer); - ply_renderer_free (state->renderer); - state->renderer = NULL; - } + detach_from_seats (state); if (state->local_console_terminal != NULL) { @@ -1000,6 +1051,24 @@ quit_splash (state_t *state) detach_from_running_session (state); } +static void +deactivate_renderer (const char *device_path, + ply_seat_t *seat, + state_t *state) +{ + ply_seat_deactivate_renderer (seat); +} + +static void +deactivate_renderers (state_t *state) +{ + ply_trace ("removing seats"); + ply_hashtable_foreach (state->seats, + (ply_hashtable_foreach_func_t *) + deactivate_renderer, + state); +} + static void hide_splash (state_t *state) { @@ -1018,9 +1087,7 @@ dump_details_and_quit_splash (state_t *state) state->showing_details = false; toggle_between_splash_and_details (state); - if (state->renderer != NULL) - ply_renderer_deactivate (state->renderer); - + deactivate_renderers (state); hide_splash (state); state->is_shown = false; @@ -1090,11 +1157,7 @@ deactivate_splash (state_t *state) { assert (!state->is_inactive); - if (state->renderer != NULL) - { - ply_trace ("deactivating renderer"); - ply_renderer_deactivate (state->renderer); - } + deactivate_renderers (state); detach_from_running_session (state); @@ -1132,9 +1195,7 @@ on_boot_splash_idle (state_t *state) if (!state->should_retain_splash) { ply_trace ("hiding splash"); - if (state->renderer != NULL) - ply_renderer_deactivate (state->renderer); - + deactivate_renderers (state); hide_splash (state); state->is_shown = false; @@ -1152,6 +1213,23 @@ on_boot_splash_idle (state_t *state) } } +static void +deactivate_keyboard (const char *device_path, + ply_seat_t *seat, + state_t *state) +{ + ply_seat_deactivate_keyboard (seat); +} + +static void +deactivate_keyboards (state_t *state) +{ + ply_trace ("deactivating keyboards"); + ply_hashtable_foreach (state->seats, + (ply_hashtable_foreach_func_t *) + deactivate_keyboard, + state); +} static void on_deactivate (state_t *state, @@ -1175,12 +1253,7 @@ on_deactivate (state_t *state, state->deactivate_trigger = deactivate_trigger; ply_trace ("deactivating"); - - if (state->keyboard != NULL) - { - ply_trace ("deactivating keyboard"); - ply_keyboard_stop_watching_for_input (state->keyboard); - } + deactivate_keyboards (state); if (state->boot_splash != NULL) { @@ -1196,6 +1269,42 @@ on_deactivate (state_t *state, } } +static void +activate_keyboard (const char *device_path, + ply_seat_t *seat, + state_t *state) +{ + ply_seat_activate_keyboard (seat); +} + +static void +activate_keyboards (state_t *state) +{ + ply_trace ("activating keyboards"); + ply_hashtable_foreach (state->seats, + (ply_hashtable_foreach_func_t *) + activate_keyboard, + state); +} + +static void +activate_renderer (const char *device_path, + ply_seat_t *seat, + state_t *state) +{ + ply_seat_activate_renderer (seat); +} + +static void +activate_renderers (state_t *state) +{ + ply_trace ("removing seats"); + ply_hashtable_foreach (state->seats, + (ply_hashtable_foreach_func_t *) + activate_renderer, + state); +} + static void on_reactivate (state_t *state) { @@ -1216,17 +1325,8 @@ on_reactivate (state_t *state) attach_to_running_session (state); } - if (state->keyboard != NULL) - { - ply_trace ("activating keyboard"); - ply_keyboard_watch_for_input (state->keyboard); - } - - if (state->renderer != NULL) - { - ply_trace ("activating renderer"); - ply_renderer_activate (state->renderer); - } + activate_keyboards (state); + activate_renderers (state); state->is_inactive = false; @@ -1262,11 +1362,8 @@ on_quit (state_t *state, if (state->session != NULL) ply_terminal_session_close_log (state->session); - if (state->keyboard != NULL) - { - ply_trace ("deactivating keyboard"); - ply_keyboard_stop_watching_for_input (state->keyboard); - } + ply_trace ("deactivating keyboard"); + deactivate_keyboards (state); ply_trace ("unloading splash"); if (state->is_inactive && !retain_splash) @@ -1508,143 +1605,21 @@ on_enter (state_t *state, } static void -set_keyboard (state_t *state, - ply_keyboard_t *keyboard) +add_seat_to_boot_splash (const char *device_path, + ply_seat_t *seat, + ply_boot_splash_t *splash) { - state->keyboard = keyboard; - - ply_keyboard_add_escape_handler (keyboard, (ply_keyboard_escape_handler_t) - on_escape_pressed, state); - ply_trace ("listening for keystrokes"); - ply_keyboard_add_input_handler (keyboard, - (ply_keyboard_input_handler_t) - on_keyboard_input, state); - ply_trace ("listening for backspace"); - ply_keyboard_add_backspace_handler (keyboard, - (ply_keyboard_backspace_handler_t) - on_backspace, state); - ply_trace ("listening for enter"); - ply_keyboard_add_enter_handler (keyboard, - (ply_keyboard_enter_handler_t) - on_enter, state); -} -static void -add_display_and_keyboard_for_terminal (state_t *state, - ply_terminal_t *terminal) -{ - ply_text_display_t *display; - ply_keyboard_t *keyboard; - - keyboard = ply_keyboard_new_for_terminal (terminal); - display = ply_text_display_new (terminal); - - ply_list_append_data (state->text_displays, display); - set_keyboard (state, keyboard); -} - -static void -add_pixel_displays_from_renderer (state_t *state, - ply_renderer_t *renderer) -{ - ply_list_t *heads; - ply_list_node_t *node; - - heads = ply_renderer_get_heads (renderer); - - ply_trace ("Adding displays for %d heads", - ply_list_get_length (heads)); - - node = ply_list_get_first_node (heads); - while (node != NULL) - { - ply_list_node_t *next_node; - ply_renderer_head_t *head; - ply_pixel_display_t *display; - - head = ply_list_node_get_data (node); - next_node = ply_list_get_next_node (heads, node); - - display = ply_pixel_display_new (renderer, head); - - ply_list_append_data (state->pixel_displays, display); - - node = next_node; - } - -} - -static void -add_default_displays_and_keyboard (state_t *state) -{ - ply_renderer_t *renderer; - ply_keyboard_t *keyboard; - ply_text_display_t *text_display; - - ply_trace ("adding default displays and keyboard"); - - state->local_console_terminal = get_terminal (state, state->default_tty); - - renderer = ply_renderer_new (PLY_RENDERER_TYPE_AUTO, NULL, state->local_console_terminal); - - if (!ply_renderer_open (renderer)) - { - ply_trace ("could not open renderer /dev/fb"); - ply_renderer_free (renderer); - - ply_trace ("adding text display and keyboard for %s", state->default_tty); - add_display_and_keyboard_for_terminal (state, state->local_console_terminal); - return; - } - - keyboard = ply_keyboard_new_for_renderer (renderer); - set_keyboard (state, keyboard); - - add_pixel_displays_from_renderer (state, renderer); - - text_display = ply_text_display_new (state->local_console_terminal); - ply_list_append_data (state->text_displays, text_display); - - state->renderer = renderer; + ply_boot_splash_attach_to_seat (splash, seat); } static void add_displays_and_keyboard_to_boot_splash (state_t *state, ply_boot_splash_t *splash) { - ply_list_node_t *node; - - ply_trace ("setting keyboard on boot splash"); - if (state->keyboard != NULL) - ply_boot_splash_set_keyboard (splash, state->keyboard); - - node = ply_list_get_first_node (state->pixel_displays); - while (node != NULL) - { - ply_pixel_display_t *display; - ply_list_node_t *next_node; - - display = ply_list_node_get_data (node); - next_node = ply_list_get_next_node (state->pixel_displays, node); - ply_trace ("adding pixel display on boot splash"); - ply_boot_splash_add_pixel_display (splash, display); - - node = next_node; - } - - node = ply_list_get_first_node (state->text_displays); - while (node != NULL) - { - ply_text_display_t *display; - ply_list_node_t *next_node; - - display = ply_list_node_get_data (node); - next_node = ply_list_get_next_node (state->text_displays, node); - - ply_trace ("adding text display on boot splash"); - ply_boot_splash_add_text_display (splash, display); - - node = next_node; - } + ply_hashtable_foreach (state->seats, + (ply_hashtable_foreach_func_t *) + add_seat_to_boot_splash, + splash); } #ifdef PLY_ENABLE_SYSTEMD_INTEGRATION @@ -1746,7 +1721,6 @@ show_theme (state_t *state, if (!ply_boot_splash_show (splash, splash_mode)) { ply_save_errno (); - ply_boot_splash_unset_keyboard (splash); ply_boot_splash_free (splash); ply_restore_errno (); return; @@ -1757,9 +1731,7 @@ show_theme (state_t *state, tell_systemd_to_print_details (state); #endif - if (state->keyboard != NULL) - ply_keyboard_watch_for_input (state->keyboard); - + activate_keyboards (state); update_display (state); } @@ -1993,18 +1965,6 @@ check_logging (state_t *state) } } -static void -add_display_and_keyboard_for_console (const char *name, - ply_terminal_t *terminal, - state_t *state) -{ - if (strcmp (name, state->default_tty) == 0) - state->local_console_terminal = terminal; - - ply_trace ("adding display and keyboard for console %s", name); - add_display_and_keyboard_for_terminal (state, terminal); -} - static int add_consoles_from_file (state_t *state, const char *path) @@ -2114,23 +2074,6 @@ check_for_consoles (state_t *state) ply_trace ("ignoring all consoles but default console because of plymouth.ignore-serial-consoles"); get_terminal (state, state->default_tty); } - - if (state->is_shown) - { - /* Do a full graphical splash if there's no weird serial console - * stuff going on, otherwise just prepare text splashes - */ - if (num_consoles <= 1) - add_default_displays_and_keyboard (state); - else - ply_hashtable_foreach (state->terminals, - (ply_hashtable_foreach_func_t *) - add_display_and_keyboard_for_console, - state); - } - - ply_trace ("After processing serial consoles there are now %d text displays", - ply_list_get_length (state->text_displays)); } static bool @@ -2215,10 +2158,8 @@ initialize_environment (state_t *state) state->entry_triggers = ply_list_new (); state->entry_buffer = ply_buffer_new(); state->terminals = ply_hashtable_new (ply_hashtable_string_hash, ply_hashtable_string_compare); - state->pixel_displays = ply_list_new (); - state->text_displays = ply_list_new (); + state->seats = ply_hashtable_new (ply_hashtable_string_hash, ply_hashtable_string_compare); state->messages = ply_list_new (); - state->keyboard = NULL; redirect_standard_io_to_dev_null (); From df6708ef3d32247feaf2325795d2e411127e72f4 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 2 Dec 2013 22:37:30 -0500 Subject: [PATCH 20/32] boot-splash: strip out old api Now that main.c is attaching seat objects to the boot splash, instead of the seat's individual components, we can drop the apis that allow doing things piecewise. --- src/libply-splash-core/ply-boot-splash.c | 137 ----------------------- src/libply-splash-core/ply-boot-splash.h | 11 -- 2 files changed, 148 deletions(-) diff --git a/src/libply-splash-core/ply-boot-splash.c b/src/libply-splash-core/ply-boot-splash.c index 86708374..160ce45e 100644 --- a/src/libply-splash-core/ply-boot-splash.c +++ b/src/libply-splash-core/ply-boot-splash.c @@ -55,12 +55,9 @@ struct _ply_boot_splash const ply_boot_splash_plugin_interface_t *plugin_interface; ply_boot_splash_plugin_t *plugin; ply_boot_splash_mode_t mode; - ply_keyboard_t *keyboard; ply_buffer_t *boot_buffer; ply_trigger_t *idle_trigger; ply_list_t *seats; - ply_list_t *pixel_displays; - ply_list_t *text_displays; char *theme_path; char *plugin_dir; @@ -97,85 +94,11 @@ ply_boot_splash_new (const char *theme_path, splash->mode = PLY_BOOT_SPLASH_MODE_INVALID; splash->boot_buffer = boot_buffer; - splash->pixel_displays = ply_list_new (); - splash->text_displays = ply_list_new (); splash->seats = ply_list_new (); return splash; } -void -ply_boot_splash_set_keyboard (ply_boot_splash_t *splash, - ply_keyboard_t *keyboard) -{ - splash->keyboard = keyboard; - - if (splash->plugin_interface->set_keyboard == NULL) - return; - - splash->plugin_interface->set_keyboard (splash->plugin, keyboard); -} - -void -ply_boot_splash_unset_keyboard (ply_boot_splash_t *splash) -{ - if (splash->keyboard == NULL) - return; - - if (splash->plugin_interface->set_keyboard == NULL) - return; - - splash->plugin_interface->unset_keyboard (splash->plugin, splash->keyboard); -} - -void -ply_boot_splash_add_pixel_display (ply_boot_splash_t *splash, - ply_pixel_display_t *display) -{ - ply_list_append_data (splash->pixel_displays, display); - - if (splash->plugin_interface->add_pixel_display == NULL) - return; - - splash->plugin_interface->add_pixel_display (splash->plugin, display); -} - -void -ply_boot_splash_remove_pixel_display (ply_boot_splash_t *splash, - ply_pixel_display_t *display) -{ - ply_list_remove_data (splash->pixel_displays, display); - - if (splash->plugin_interface->remove_pixel_display == NULL) - return; - - splash->plugin_interface->remove_pixel_display (splash->plugin, display); -} - -void -ply_boot_splash_add_text_display (ply_boot_splash_t *splash, - ply_text_display_t *display) -{ - ply_list_append_data (splash->text_displays, display); - - if (splash->plugin_interface->add_text_display == NULL) - return; - - splash->plugin_interface->add_text_display (splash->plugin, display); -} - -void -ply_boot_splash_remove_text_display (ply_boot_splash_t *splash, - ply_text_display_t *display) -{ - ply_list_remove_data (splash->text_displays, display); - - if (splash->plugin_interface->remove_pixel_display == NULL) - return; - - splash->plugin_interface->remove_text_display (splash->plugin, display); -} - static void detach_from_seat (ply_boot_splash_t *splash, ply_seat_t *seat) @@ -467,62 +390,6 @@ ply_boot_splash_unload (ply_boot_splash_t *splash) splash->is_loaded = false; } -static void -remove_displays (ply_boot_splash_t *splash) -{ - ply_list_node_t *node, *next_node; - - ply_trace ("removing pixel displays"); - - node = ply_list_get_first_node (splash->pixel_displays); - while (node != NULL) - { - ply_pixel_display_t *display; - ply_list_node_t *next_node; - unsigned long width, height; - - display = ply_list_node_get_data (node); - next_node = ply_list_get_next_node (splash->pixel_displays, node); - - width = ply_pixel_display_get_width (display); - height = ply_pixel_display_get_height (display); - - ply_trace ("Removing %lux%lu pixel display", width, height); - - if (splash->plugin_interface->remove_pixel_display != NULL) - splash->plugin_interface->remove_pixel_display (splash->plugin, display); - - ply_trace ("Removing node"); - ply_list_remove_node (splash->pixel_displays, node); - - node = next_node; - } - - ply_trace ("removing text displays"); - node = ply_list_get_first_node (splash->text_displays); - while (node != NULL) - { - ply_text_display_t *display; - int number_of_columns, number_of_rows; - - display = ply_list_node_get_data (node); - next_node = ply_list_get_next_node (splash->text_displays, node); - - number_of_columns = ply_text_display_get_number_of_columns (display); - number_of_rows = ply_text_display_get_number_of_rows (display); - - ply_trace ("Removing %dx%d text display", number_of_columns, number_of_rows); - - if (splash->plugin_interface->remove_text_display != NULL) - splash->plugin_interface->remove_text_display (splash->plugin, display); - - ply_trace ("Removing node"); - ply_list_remove_node (splash->text_displays, node); - - node = next_node; - } -} - static void detach_from_seats (ply_boot_splash_t *splash) { @@ -568,10 +435,6 @@ ply_boot_splash_free (ply_boot_splash_t *splash) splash); } - remove_displays (splash); - ply_list_free (splash->pixel_displays); - ply_list_free (splash->text_displays); - detach_from_seats (splash); ply_list_free (splash->seats); diff --git a/src/libply-splash-core/ply-boot-splash.h b/src/libply-splash-core/ply-boot-splash.h index 3f66b70d..335039ba 100644 --- a/src/libply-splash-core/ply-boot-splash.h +++ b/src/libply-splash-core/ply-boot-splash.h @@ -54,17 +54,6 @@ void ply_boot_splash_attach_to_seat (ply_boot_splash_t *splash, ply_seat_t *seat); void ply_boot_splash_detach_from_seat (ply_boot_splash_t *splash, ply_seat_t *seat); -void ply_boot_splash_set_keyboard (ply_boot_splash_t *splash, - ply_keyboard_t *keyboard); -void ply_boot_splash_unset_keyboard (ply_boot_splash_t *splash); -void ply_boot_splash_add_pixel_display (ply_boot_splash_t *splash, - ply_pixel_display_t *display); -void ply_boot_splash_remove_pixel_display (ply_boot_splash_t *splash, - ply_pixel_display_t *display); -void ply_boot_splash_add_text_display (ply_boot_splash_t *splash, - ply_text_display_t *display); -void ply_boot_splash_remove_text_display (ply_boot_splash_t *splash, - ply_text_display_t *display); void ply_boot_splash_free (ply_boot_splash_t *splash); bool ply_boot_splash_show (ply_boot_splash_t *splash, ply_boot_splash_mode_t mode); From c203bb1250d7e258b81c2be0d565418223561c9a Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 9 Dec 2013 10:37:51 -0500 Subject: [PATCH 21/32] main: refactor show_*_splash Right now show_default_splash and show_detailed_splash, load the relevant splash and then show it. This commit drops the "show" part and renames the functions to load_default_splash and load_detailed_splash, respectively. It, of course, also updates the callers to call show_theme explicitly. This refactorization will make it easier to later move device management out of main.c --- src/main.c | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/main.c b/src/main.c index 3de6ac62..7729d9ce 100644 --- a/src/main.c +++ b/src/main.c @@ -416,7 +416,7 @@ show_messages (state_t *state) } static void -show_detailed_splash (state_t *state) +load_detailed_splash (state_t *state) { ply_boot_splash_t *splash; @@ -433,8 +433,6 @@ show_detailed_splash (state_t *state) } state->boot_splash = splash; - - show_theme (state, state->boot_splash); } static const char * @@ -559,7 +557,7 @@ find_distribution_default_splash (state_t *state) } static void -show_default_splash (state_t *state) +load_default_splash (state_t *state) { if (state->boot_splash != NULL) return; @@ -613,8 +611,6 @@ show_default_splash (state_t *state) ply_error ("plymouthd: could not start boot splash: %m"); return; } - - show_theme (state, state->boot_splash); } static void @@ -1011,14 +1007,15 @@ on_show_splash (state_t *state) if (plymouth_should_show_default_splash (state)) { - show_default_splash (state); + load_default_splash (state); state->showing_details = false; } else { - show_detailed_splash (state); + load_detailed_splash (state); state->showing_details = true; } + show_theme (state, state->boot_splash); show_messages (state); } @@ -1484,14 +1481,15 @@ toggle_between_splash_and_details (state_t *state) if (!state->showing_details) { - show_detailed_splash (state); + load_detailed_splash (state); state->showing_details = true; } else { - show_default_splash (state); + load_default_splash (state); state->showing_details = false; } + show_theme (state, state->boot_splash); update_display (state); show_messages (state); } From 1c715945f22a964ef5fdce8b487d9e41d7647a40 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 9 Dec 2013 11:56:17 -0500 Subject: [PATCH 22/32] main: refactor on_show_splash Now that showing the theme is separated out, this commit refactors on_show_splash to move the splash loading specific bits to its own function. --- src/main.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main.c b/src/main.c index 7729d9ce..822400b0 100644 --- a/src/main.c +++ b/src/main.c @@ -124,6 +124,7 @@ typedef struct int number_of_errors; } state_t; +static void load_splash (state_t *state); static ply_boot_splash_t *load_built_in_theme (state_t *state); static ply_boot_splash_t *load_theme (state_t *state, const char *theme_path); @@ -1005,6 +1006,17 @@ on_show_splash (state_t *state) if (!state->is_attached && state->should_be_attached && state->has_open_seats) attach_to_running_session (state); + load_splash (state); + show_theme (state, state->boot_splash); + show_messages (state); +} + +static void +load_splash (state_t *state) +{ + if (state->boot_splash != NULL) + return; + if (plymouth_should_show_default_splash (state)) { load_default_splash (state); @@ -1015,8 +1027,6 @@ on_show_splash (state_t *state) load_detailed_splash (state); state->showing_details = true; } - show_theme (state, state->boot_splash); - show_messages (state); } static void From 321d553c9ce84f64e19f56fa8d40214f05650b0f Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 9 Dec 2013 10:42:45 -0500 Subject: [PATCH 23/32] main: move show_messages into show_theme Everywhere we call show_theme we call show_messages immediately, afterward. Since showing the messages on the theme is arguable part of showing it, this commit moves show_messages into the show_theme function. --- src/main.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main.c b/src/main.c index 822400b0..2c088cf4 100644 --- a/src/main.c +++ b/src/main.c @@ -1008,7 +1008,6 @@ on_show_splash (state_t *state) load_splash (state); show_theme (state, state->boot_splash); - show_messages (state); } static void @@ -1500,8 +1499,6 @@ toggle_between_splash_and_details (state_t *state) state->showing_details = false; } show_theme (state, state->boot_splash); - update_display (state); - show_messages (state); } static void @@ -1740,6 +1737,7 @@ show_theme (state_t *state, #endif activate_keyboards (state); + show_messages (state); update_display (state); } From edd0335d458592cce4de4de93ba7c5df8938bb2b Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Sun, 8 Dec 2013 21:03:46 -0500 Subject: [PATCH 24/32] splash-core: add device manager class There's quite a bit of logic for managing input and output in main.c right now. That code is already a bit too complicated, but will get even more complicated going forward if we want to add udev support, etc. In an effort to keep things from getting too unwieldly, this commit breaks out a lot of the logic into a new ply-device-manager class. A subsequent commit will make main.c use the new class. --- src/libply-splash-core/Makefile.am | 2 + src/libply-splash-core/ply-device-manager.c | 468 ++++++++++++++++++++ src/libply-splash-core/ply-device-manager.h | 55 +++ 3 files changed, 525 insertions(+) create mode 100644 src/libply-splash-core/ply-device-manager.c create mode 100644 src/libply-splash-core/ply-device-manager.h diff --git a/src/libply-splash-core/Makefile.am b/src/libply-splash-core/Makefile.am index e05dcb33..287b11b2 100644 --- a/src/libply-splash-core/Makefile.am +++ b/src/libply-splash-core/Makefile.am @@ -15,6 +15,7 @@ libply_splash_coredir = $(includedir)/plymouth-1/ply-splash-core libply_splash_core_HEADERS = \ ply-boot-splash.h \ ply-boot-splash-plugin.h \ + ply-device-manager.h \ ply-keyboard.h \ ply-pixel-buffer.h \ ply-pixel-display.h \ @@ -37,6 +38,7 @@ libply_splash_core_la_LDFLAGS = -export-symbols-regex '^[^_].*' \ -no-undefined libply_splash_core_la_SOURCES = \ $(libply_splash_core_HEADERS) \ + ply-device-manager.c \ ply-keyboard.c \ ply-pixel-display.c \ ply-text-display.c \ diff --git a/src/libply-splash-core/ply-device-manager.c b/src/libply-splash-core/ply-device-manager.c new file mode 100644 index 00000000..f53c0446 --- /dev/null +++ b/src/libply-splash-core/ply-device-manager.c @@ -0,0 +1,468 @@ +/* ply-device-manager.c - device manager + * + * Copyright (C) 2013 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#include "config.h" +#include "ply-device-manager.h" + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "ply-logger.h" +#include "ply-event-loop.h" +#include "ply-hashtable.h" +#include "ply-list.h" +#include "ply-utils.h" + +struct _ply_device_manager +{ + ply_device_manager_flags_t flags; + ply_event_loop_t *loop; + ply_hashtable_t *terminals; + ply_terminal_t *local_console_terminal; + ply_list_t *seats; + + ply_seat_added_handler_t seat_added_handler; + ply_seat_removed_handler_t seat_removed_handler; + void *seat_event_handler_data; +}; + +static void +detach_from_event_loop (ply_device_manager_t *manager) +{ + assert (manager != NULL); + + manager->loop = NULL; +} + +static void +attach_to_event_loop (ply_device_manager_t *manager, + ply_event_loop_t *loop) +{ + assert (manager != NULL); + assert (loop != NULL); + assert (manager->loop == NULL); + + manager->loop = loop; + + ply_event_loop_watch_for_exit (loop, (ply_event_loop_exit_handler_t) + detach_from_event_loop, + manager); +} + +static void +free_seats (ply_device_manager_t *manager) +{ + ply_list_node_t *node; + + ply_trace ("removing seats"); + node = ply_list_get_first_node (manager->seats); + while (node != NULL) + { + ply_seat_t *seat; + ply_list_node_t *next_node; + + seat = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (manager->seats, node); + + if (manager->seat_removed_handler != NULL) + manager->seat_removed_handler (manager->seat_event_handler_data, seat); + + ply_seat_free (seat); + ply_list_remove_node (manager->seats, node); + + node = next_node; + } +} + +static void +free_terminal (char *device, + ply_terminal_t *terminal, + ply_device_manager_t *manager) +{ + ply_hashtable_remove (manager->terminals, device); + + ply_terminal_close (terminal); + ply_terminal_free (terminal); +} + +static void +free_terminals (ply_device_manager_t *manager) +{ + ply_hashtable_foreach (manager->terminals, + (ply_hashtable_foreach_func_t *) + free_terminal, + manager); +} + +static ply_terminal_t * +get_terminal (ply_device_manager_t *manager, + const char *device_name) +{ + char *full_name = NULL; + ply_terminal_t *terminal; + + if (strncmp (device_name, "/dev/", strlen ("/dev/")) == 0) + full_name = strdup (device_name); + else + asprintf (&full_name, "/dev/%s", device_name); + + if (strcmp (full_name, "/dev/tty0") == 0 || + strcmp (full_name, "/dev/tty") == 0) + { + terminal = manager->local_console_terminal; + goto done; + } + + terminal = ply_hashtable_lookup (manager->terminals, full_name); + + if (terminal == NULL) + { + terminal = ply_terminal_new (full_name); + + ply_hashtable_insert (manager->terminals, + (void *) ply_terminal_get_name (terminal), + terminal); + } + +done: + free (full_name); + return terminal; +} + +ply_device_manager_t * +ply_device_manager_new (const char *default_tty, + ply_device_manager_flags_t flags) +{ + ply_device_manager_t *manager; + + manager = calloc (1, sizeof (ply_device_manager_t)); + manager->loop = NULL; + manager->terminals = ply_hashtable_new (ply_hashtable_string_hash, ply_hashtable_string_compare); + manager->local_console_terminal = ply_terminal_new (default_tty); + ply_hashtable_insert (manager->terminals, + (void *) ply_terminal_get_name (manager->local_console_terminal), + manager->local_console_terminal); + manager->seats = ply_list_new (); + manager->flags = flags; + + attach_to_event_loop (manager, ply_event_loop_get_default ()); + + return manager; +} + +void +ply_device_manager_free (ply_device_manager_t *manager) +{ + ply_trace ("freeing device manager"); + + if (manager == NULL) + return; + + free_seats (manager); + ply_list_free (manager->seats); + + free_terminals (manager); + ply_hashtable_free (manager->terminals); + + free (manager); +} + +static int +add_consoles_from_file (ply_device_manager_t *manager, + const char *path) +{ + int fd; + char contents[512] = ""; + ssize_t contents_length; + int num_consoles; + const char *remaining_file_contents; + + ply_trace ("opening %s", path); + fd = open (path, O_RDONLY); + + if (fd < 0) + { + ply_trace ("couldn't open it: %m"); + return 0; + } + + ply_trace ("reading file"); + contents_length = read (fd, contents, sizeof (contents) - 1); + + if (contents_length <= 0) + { + ply_trace ("couldn't read it: %m"); + close (fd); + return 0; + } + close (fd); + + remaining_file_contents = contents; + num_consoles = 0; + + while (remaining_file_contents < contents + contents_length) + { + char *console; + size_t console_length; + const char *console_device; + ply_terminal_t *terminal; + + /* Advance past any leading whitespace */ + remaining_file_contents += strspn (remaining_file_contents, " \n\t\v"); + + if (*remaining_file_contents == '\0') + { + /* There's nothing left after the whitespace, we're done */ + break; + } + + /* Find trailing whitespace and NUL terminate. If strcspn + * doesn't find whitespace, it gives us the length of the string + * until the next NUL byte, which we'll just overwrite with + * another NUL byte anyway. */ + console_length = strcspn (remaining_file_contents, " \n\t\v"); + console = strndup (remaining_file_contents, console_length); + + terminal = get_terminal (manager, console); + console_device = ply_terminal_get_name (terminal); + + free (console); + + ply_trace ("console %s found!", console_device); + num_consoles++; + + /* Move past the parsed console string, and the whitespace we + * may have found above. If we found a NUL above and not whitespace, + * then we're going to jump past the end of the buffer and the loop + * will terminate + */ + remaining_file_contents += console_length + 1; + } + + return num_consoles; +} + +static void +create_seat_for_terminal_and_renderer_type (ply_device_manager_t *manager, + const char *device_path, + ply_terminal_t *terminal, + ply_renderer_type_t renderer_type) +{ + ply_seat_t *seat; + + ply_trace ("creating seat for %s (renderer type: %u) (terminal: %s)", + device_path? : "", renderer_type, terminal? ply_terminal_get_name (terminal): "none"); + seat = ply_seat_new (terminal); + + if (!ply_seat_open (seat, renderer_type, device_path)) + { + ply_trace ("could not create seat"); + ply_seat_free (seat); + return; + } + + ply_list_append_data (manager->seats, seat); + + if (manager->seat_added_handler != NULL) + manager->seat_added_handler (manager->seat_event_handler_data, seat); +} + +static void +create_seat_for_terminal (const char *device_path, + ply_terminal_t *terminal, + ply_device_manager_t *manager) +{ + create_seat_for_terminal_and_renderer_type (manager, + device_path, + terminal, + PLY_RENDERER_TYPE_NONE); +} +static void +create_seats_from_terminals (ply_device_manager_t *manager) +{ + int num_consoles; + + ply_trace ("checking for consoles"); + + if (manager->flags & PLY_DEVICE_MANAGER_FLAGS_IGNORE_SERIAL_CONSOLES) + { + num_consoles = 0; + ply_trace ("ignoring all consoles but default console because explicitly told to."); + } + else + { + num_consoles = add_consoles_from_file (manager, "/sys/class/tty/console/active"); + + if (num_consoles == 0) + ply_trace ("ignoring all consoles but default console because /sys/class/tty/console/active could not be read"); + } + + if (num_consoles > 1) + { + ply_hashtable_foreach (manager->terminals, + (ply_hashtable_foreach_func_t *) + create_seat_for_terminal, + manager); + } + else + { + create_seat_for_terminal_and_renderer_type (manager, + ply_terminal_get_name (manager->local_console_terminal), + manager->local_console_terminal, + PLY_RENDERER_TYPE_AUTO); + } +} + +void +ply_device_manager_watch_seats (ply_device_manager_t *manager, + ply_seat_added_handler_t seat_added_handler, + ply_seat_removed_handler_t seat_removed_handler, + void *data) +{ + manager->seat_added_handler = seat_added_handler; + manager->seat_removed_handler = seat_removed_handler; + manager->seat_event_handler_data = data; + + create_seats_from_terminals (manager); +} + +bool +ply_device_manager_has_open_seats (ply_device_manager_t *manager) +{ + ply_list_node_t *node; + + node = ply_list_get_first_node (manager->seats); + while (node != NULL) + { + ply_seat_t *seat; + ply_list_node_t *next_node; + + seat = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (manager->seats, node); + + if (ply_seat_is_open (seat)) + return true; + + node = next_node; + } + + return false; +} + +ply_list_t * +ply_device_manager_get_seats (ply_device_manager_t *manager) +{ + return manager->seats; +} + +ply_terminal_t * +ply_device_manager_get_default_terminal (ply_device_manager_t *manager) +{ + return manager->local_console_terminal; +} + +void +ply_device_manager_activate_renderers (ply_device_manager_t *manager) +{ + ply_list_node_t *node; + + ply_trace ("activating renderers"); + node = ply_list_get_first_node (manager->seats); + while (node != NULL) + { + ply_seat_t *seat; + ply_list_node_t *next_node; + + seat = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (manager->seats, node); + + ply_seat_activate_renderer (seat); + + node = next_node; + } +} + +void +ply_device_manager_deactivate_renderers (ply_device_manager_t *manager) +{ + ply_list_node_t *node; + + ply_trace ("deactivating renderers"); + node = ply_list_get_first_node (manager->seats); + while (node != NULL) + { + ply_seat_t *seat; + ply_list_node_t *next_node; + + seat = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (manager->seats, node); + + ply_seat_deactivate_renderer (seat); + + node = next_node; + } +} + +void +ply_device_manager_activate_keyboards (ply_device_manager_t *manager) +{ + ply_list_node_t *node; + + ply_trace ("activating keyboards"); + node = ply_list_get_first_node (manager->seats); + while (node != NULL) + { + ply_seat_t *seat; + ply_list_node_t *next_node; + + seat = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (manager->seats, node); + + ply_seat_activate_keyboard (seat); + + node = next_node; + } +} + +void +ply_device_manager_deactivate_keyboards (ply_device_manager_t *manager) +{ + ply_list_node_t *node; + + ply_trace ("deactivating keyboards"); + node = ply_list_get_first_node (manager->seats); + while (node != NULL) + { + ply_seat_t *seat; + ply_list_node_t *next_node; + + seat = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (manager->seats, node); + + ply_seat_deactivate_keyboard (seat); + + node = next_node; + } +} diff --git a/src/libply-splash-core/ply-device-manager.h b/src/libply-splash-core/ply-device-manager.h new file mode 100644 index 00000000..28d66750 --- /dev/null +++ b/src/libply-splash-core/ply-device-manager.h @@ -0,0 +1,55 @@ +/* ply-device-manager.h - udev monitor + * + * Copyright (C) 2013 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + */ +#ifndef PLY_DEVICE_MANAGER_H +#define PLY_DEVICE_MANAGER_H + +#include +#include "ply-seat.h" + +typedef enum +{ + PLY_DEVICE_MANAGER_FLAGS_NONE = 0, + PLY_DEVICE_MANAGER_FLAGS_IGNORE_SERIAL_CONSOLES = 1 << 0 +} ply_device_manager_flags_t; + +typedef struct _ply_device_manager ply_device_manager_t; +typedef void (* ply_seat_added_handler_t) (void *, ply_seat_t *); +typedef void (* ply_seat_removed_handler_t) (void *, ply_seat_t *); + +#ifndef PLY_HIDE_FUNCTION_DECLARATIONS +ply_device_manager_t *ply_device_manager_new (const char *default_tty, + ply_device_manager_flags_t flags); +void ply_device_manager_watch_seats (ply_device_manager_t *manager, + ply_seat_added_handler_t seat_added_handler, + ply_seat_removed_handler_t seat_removed_handler, + void *data); +bool ply_device_manager_has_open_seats (ply_device_manager_t *manager); +ply_list_t *ply_device_manager_get_seats (ply_device_manager_t *manager); +void ply_device_manager_free (ply_device_manager_t *manager); +void ply_device_manager_activate_keyboards (ply_device_manager_t *manager); +void ply_device_manager_deactivate_keyboards (ply_device_manager_t *manager); +void ply_device_manager_activate_renderers (ply_device_manager_t *manager); +void ply_device_manager_deactivate_renderers (ply_device_manager_t *manager); +ply_terminal_t *ply_device_manager_get_default_terminal (ply_device_manager_t *manager); + +#endif + +#endif +/* vim: set ts=4 sw=4 expandtab autoindent cindent cino={.5s,(0: */ From c17a836b77d34fec94ebbc9410763974edaa88bd Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Sun, 8 Dec 2013 21:09:15 -0500 Subject: [PATCH 25/32] main: use new device manager class Now that we have a class for managing our seats, let's use it. This gets a lot of the nitty gritty logic out of main.c and paves the way for us to do smartcard device management going forward. --- src/main.c | 521 ++++++++++++++--------------------------------------- 1 file changed, 137 insertions(+), 384 deletions(-) diff --git a/src/main.c b/src/main.c index 2c088cf4..b1dee587 100644 --- a/src/main.c +++ b/src/main.c @@ -43,6 +43,7 @@ #include "ply-command-parser.h" #include "ply-boot-server.h" #include "ply-boot-splash.h" +#include "ply-device-manager.h" #include "ply-event-loop.h" #include "ply-hashtable.h" #include "ply-list.h" @@ -85,8 +86,6 @@ typedef struct { ply_event_loop_t *loop; ply_boot_server_t *boot_server; - ply_hashtable_t *terminals; - ply_hashtable_t *seats; ply_boot_splash_t *boot_splash; ply_terminal_session_t *session; ply_buffer_t *boot_buffer; @@ -98,6 +97,7 @@ typedef struct ply_command_parser_t *command_parser; ply_mode_t mode; ply_terminal_t *local_console_terminal; + ply_device_manager_t *device_manager; ply_trigger_t *deactivate_trigger; ply_trigger_t *quit_trigger; @@ -113,7 +113,6 @@ typedef struct uint32_t should_retain_splash : 1; uint32_t is_inactive : 1; uint32_t is_shown : 1; - uint32_t has_open_seats : 1; uint32_t should_force_details : 1; char *override_splash_path; @@ -131,9 +130,7 @@ static ply_boot_splash_t *load_theme (state_t *state, static void show_theme (state_t *state, ply_boot_splash_t *splash); -static void add_displays_and_keyboard_to_boot_splash (state_t *state, - ply_boot_splash_t *splash); - +static void attach_splash_to_seats (state_t *state); static bool attach_to_running_session (state_t *state); static void detach_from_running_session (state_t *state); static void on_escape_pressed (state_t *state); @@ -146,7 +143,6 @@ static void on_error_message (ply_buffer_t *debug_buffer, static ply_buffer_t *debug_buffer; static char *debug_buffer_path = NULL; static char *pid_file = NULL; -static void check_for_consoles (state_t *state); static void toggle_between_splash_and_details (state_t *state); #ifdef PLY_ENABLE_SYSTEMD_INTEGRATION static void tell_systemd_to_print_details (state_t *state); @@ -161,164 +157,6 @@ static void on_keyboard_input (state_t *state, size_t character_size); static void on_backspace (state_t *state); -static void -detach_from_seat (const char *device_path, - ply_seat_t *seat, - state_t *state) -{ - ply_hashtable_remove (state->seats, (void *) device_path); - ply_seat_free (seat); -} - -static void -detach_from_seats (state_t *state) -{ - ply_trace ("removing seats"); - ply_hashtable_foreach (state->seats, - (ply_hashtable_foreach_func_t *) - detach_from_seat, - state); -} - -static void -ensure_seat_for_terminal_and_renderer_type (state_t *state, - const char *device_path, - ply_terminal_t *terminal, - ply_renderer_type_t renderer_type) -{ - ply_seat_t *seat; - bool has_seat; - ply_keyboard_t *keyboard; - - seat = ply_hashtable_lookup (state->seats, (void *) device_path); - - if (seat != NULL) - { - has_seat = true; - } - else - { - has_seat = false; - seat = ply_seat_new (terminal); - } - - if (!ply_seat_is_open (seat)) - state->has_open_seats = ply_seat_open (seat, renderer_type, NULL); - - keyboard = ply_seat_get_keyboard (seat); - ply_keyboard_add_escape_handler (keyboard, - (ply_keyboard_escape_handler_t) - on_escape_pressed, state); - ply_trace ("listening for keystrokes"); - ply_keyboard_add_input_handler (keyboard, - (ply_keyboard_input_handler_t) - on_keyboard_input, state); - ply_trace ("listening for backspace"); - ply_keyboard_add_backspace_handler (keyboard, - (ply_keyboard_backspace_handler_t) - on_backspace, state); - ply_trace ("listening for enter"); - ply_keyboard_add_enter_handler (keyboard, - (ply_keyboard_enter_handler_t) - on_enter, state); - - if (!has_seat) - ply_hashtable_insert (state->seats, strdup (device_path), seat); -} - -static void -ensure_seat_for_terminal (const char *device_path, - ply_terminal_t *terminal, - state_t *state) -{ - ensure_seat_for_terminal_and_renderer_type (state, - device_path, - terminal, - PLY_RENDERER_TYPE_NONE); -} - -static void -open_closed_seats (state_t *state) -{ - int number_of_terminals; - ply_terminal_t *default_terminal; - - number_of_terminals = ply_hashtable_get_size (state->terminals); - default_terminal = ply_hashtable_lookup (state->terminals, (void *) state->default_tty); - - if ((number_of_terminals == 0) || - ((number_of_terminals == 1) && - (default_terminal != NULL))) - { - ensure_seat_for_terminal_and_renderer_type (state, - state->default_tty, - default_terminal, - PLY_RENDERER_TYPE_AUTO); - } - else - { - ply_hashtable_foreach (state->terminals, - (ply_hashtable_foreach_func_t *) - ensure_seat_for_terminal, - state); - } -} - -static void -free_terminal (char *device, - ply_terminal_t *terminal, - state_t *state) -{ - ply_hashtable_remove (state->terminals, device); - - ply_terminal_close (terminal); - ply_terminal_free (terminal); -} - -static void -free_terminals (state_t *state) -{ - ply_hashtable_foreach (state->terminals, - (ply_hashtable_foreach_func_t *) - free_terminal, - state); -} - -static ply_terminal_t * -get_terminal (state_t *state, - const char *device_name) -{ - char *full_name; - ply_terminal_t *terminal; - - if (strncmp (device_name, "/dev/", strlen ("/dev/")) == 0) - full_name = strdup (device_name); - else - asprintf (&full_name, "/dev/%s", device_name); - - if (strcmp (full_name, "/dev/tty0") == 0 || - strcmp (full_name, "/dev/tty") == 0) - { - free (full_name); - full_name = strdup (state->default_tty); - } - - terminal = ply_hashtable_lookup (state->terminals, full_name); - - if (terminal == NULL) - { - terminal = ply_terminal_new (full_name); - - if (strcmp (full_name, state->default_tty) == 0) - state->local_console_terminal = terminal; - - ply_hashtable_insert (state->terminals, (void *) ply_terminal_get_name (terminal), terminal); - } - free (full_name); - - return terminal; -} - static void on_session_output (state_t *state, const char *output, @@ -979,6 +817,8 @@ plymouth_should_show_default_splash (state_t *state) static void on_show_splash (state_t *state) { + bool has_open_seats; + if (state->is_shown) { ply_trace ("show splash called while already shown"); @@ -999,15 +839,50 @@ on_show_splash (state_t *state) } state->is_shown = true; + has_open_seats = ply_device_manager_has_open_seats (state->device_manager); - check_for_consoles (state); - open_closed_seats (state); - - if (!state->is_attached && state->should_be_attached && state->has_open_seats) + if (!state->is_attached && state->should_be_attached && has_open_seats) attach_to_running_session (state); - load_splash (state); - show_theme (state, state->boot_splash); + if (has_open_seats) + { + ply_trace ("at least one seat already open, so loading splash"); + load_splash (state); + show_theme (state, state->boot_splash); + } + else + { + ply_trace ("no seats available to show splash on, waiting..."); + } +} + +static void +on_seat_removed (state_t *state, + ply_seat_t *seat) +{ + ply_keyboard_t *keyboard; + + keyboard = ply_seat_get_keyboard (seat); + + ply_trace ("no longer listening for keystrokes"); + ply_keyboard_remove_input_handler (keyboard, + (ply_keyboard_input_handler_t) + on_keyboard_input); + ply_trace ("no longer listening for escape"); + ply_keyboard_remove_escape_handler (keyboard, + (ply_keyboard_escape_handler_t) + on_escape_pressed); + ply_trace ("no longer listening for backspace"); + ply_keyboard_remove_backspace_handler (keyboard, + (ply_keyboard_backspace_handler_t) + on_backspace); + ply_trace ("no longer listening for enter"); + ply_keyboard_remove_enter_handler (keyboard, + (ply_keyboard_enter_handler_t) + on_enter); + + if (state->boot_splash != NULL) + ply_boot_splash_detach_from_seat (state->boot_splash, seat); } static void @@ -1028,6 +903,60 @@ load_splash (state_t *state) } } +static void +on_seat_added (state_t *state, + ply_seat_t *seat) +{ + ply_keyboard_t *keyboard; + + if (state->boot_splash == NULL) + { + ply_trace ("seat added before splash loaded, so loading splash now"); + load_splash (state); + } + + if (state->boot_splash != NULL && state->is_shown) + { + ply_trace ("show-splash already requested, so showing splash now"); + show_theme (state, state->boot_splash); + } + + keyboard = ply_seat_get_keyboard (seat); + + ply_trace ("listening for keystrokes"); + ply_keyboard_add_input_handler (keyboard, + (ply_keyboard_input_handler_t) + on_keyboard_input, state); + ply_trace ("listening for escape"); + ply_keyboard_add_escape_handler (keyboard, + (ply_keyboard_escape_handler_t) + on_escape_pressed, state); + ply_trace ("listening for backspace"); + ply_keyboard_add_backspace_handler (keyboard, + (ply_keyboard_backspace_handler_t) + on_backspace, state); + ply_trace ("listening for enter"); + ply_keyboard_add_enter_handler (keyboard, + (ply_keyboard_enter_handler_t) + on_enter, state); + +} + +static void +load_devices (state_t *state, + ply_device_manager_flags_t flags) +{ + state->device_manager = ply_device_manager_new (state->default_tty, flags); + state->local_console_terminal = ply_device_manager_get_default_terminal (state->device_manager); + + ply_device_manager_watch_seats (state->device_manager, + (ply_seat_added_handler_t) + on_seat_added, + (ply_seat_removed_handler_t) + on_seat_removed, + state); +} + static void quit_splash (state_t *state) { @@ -1039,9 +968,6 @@ quit_splash (state_t *state) state->boot_splash = NULL; } - ply_trace ("removing displays and keyboard"); - detach_from_seats (state); - if (state->local_console_terminal != NULL) { if (!state->should_retain_splash) @@ -1052,29 +978,9 @@ quit_splash (state_t *state) state->local_console_terminal = NULL; } - free_terminals (state); - detach_from_running_session (state); } -static void -deactivate_renderer (const char *device_path, - ply_seat_t *seat, - state_t *state) -{ - ply_seat_deactivate_renderer (seat); -} - -static void -deactivate_renderers (state_t *state) -{ - ply_trace ("removing seats"); - ply_hashtable_foreach (state->seats, - (ply_hashtable_foreach_func_t *) - deactivate_renderer, - state); -} - static void hide_splash (state_t *state) { @@ -1093,7 +999,7 @@ dump_details_and_quit_splash (state_t *state) state->showing_details = false; toggle_between_splash_and_details (state); - deactivate_renderers (state); + ply_device_manager_deactivate_renderers (state->device_manager); hide_splash (state); state->is_shown = false; @@ -1128,6 +1034,9 @@ tell_gdm_to_transition (void) static void quit_program (state_t *state) { + ply_trace ("cleaning up devices"); + ply_device_manager_free (state->device_manager); + ply_trace ("exiting event loop"); ply_event_loop_exit (state->loop, 0); @@ -1163,7 +1072,7 @@ deactivate_splash (state_t *state) { assert (!state->is_inactive); - deactivate_renderers (state); + ply_device_manager_deactivate_renderers (state->device_manager); detach_from_running_session (state); @@ -1201,7 +1110,7 @@ on_boot_splash_idle (state_t *state) if (!state->should_retain_splash) { ply_trace ("hiding splash"); - deactivate_renderers (state); + ply_device_manager_deactivate_renderers (state->device_manager); hide_splash (state); state->is_shown = false; @@ -1219,24 +1128,6 @@ on_boot_splash_idle (state_t *state) } } -static void -deactivate_keyboard (const char *device_path, - ply_seat_t *seat, - state_t *state) -{ - ply_seat_deactivate_keyboard (seat); -} - -static void -deactivate_keyboards (state_t *state) -{ - ply_trace ("deactivating keyboards"); - ply_hashtable_foreach (state->seats, - (ply_hashtable_foreach_func_t *) - deactivate_keyboard, - state); -} - static void on_deactivate (state_t *state, ply_trigger_t *deactivate_trigger) @@ -1259,7 +1150,7 @@ on_deactivate (state_t *state, state->deactivate_trigger = deactivate_trigger; ply_trace ("deactivating"); - deactivate_keyboards (state); + ply_device_manager_deactivate_keyboards (state->device_manager); if (state->boot_splash != NULL) { @@ -1275,42 +1166,6 @@ on_deactivate (state_t *state, } } -static void -activate_keyboard (const char *device_path, - ply_seat_t *seat, - state_t *state) -{ - ply_seat_activate_keyboard (seat); -} - -static void -activate_keyboards (state_t *state) -{ - ply_trace ("activating keyboards"); - ply_hashtable_foreach (state->seats, - (ply_hashtable_foreach_func_t *) - activate_keyboard, - state); -} - -static void -activate_renderer (const char *device_path, - ply_seat_t *seat, - state_t *state) -{ - ply_seat_activate_renderer (seat); -} - -static void -activate_renderers (state_t *state) -{ - ply_trace ("removing seats"); - ply_hashtable_foreach (state->seats, - (ply_hashtable_foreach_func_t *) - activate_renderer, - state); -} - static void on_reactivate (state_t *state) { @@ -1331,8 +1186,8 @@ on_reactivate (state_t *state) attach_to_running_session (state); } - activate_keyboards (state); - activate_renderers (state); + ply_device_manager_activate_keyboards (state->device_manager); + ply_device_manager_activate_renderers (state->device_manager); state->is_inactive = false; @@ -1368,8 +1223,7 @@ on_quit (state_t *state, if (state->session != NULL) ply_terminal_session_close_log (state->session); - ply_trace ("deactivating keyboard"); - deactivate_keyboards (state); + ply_device_manager_deactivate_keyboards (state->device_manager); ply_trace ("unloading splash"); if (state->is_inactive && !retain_splash) @@ -1610,21 +1464,26 @@ on_enter (state_t *state, } static void -add_seat_to_boot_splash (const char *device_path, - ply_seat_t *seat, - ply_boot_splash_t *splash) +attach_splash_to_seats (state_t *state) { - ply_boot_splash_attach_to_seat (splash, seat); -} -static void -add_displays_and_keyboard_to_boot_splash (state_t *state, - ply_boot_splash_t *splash) -{ - ply_hashtable_foreach (state->seats, - (ply_hashtable_foreach_func_t *) - add_seat_to_boot_splash, - splash); + ply_list_t *seats; + ply_list_node_t *node; + + seats = ply_device_manager_get_seats (state->device_manager); + node = ply_list_get_first_node (seats); + while (node != NULL) + { + ply_seat_t *seat; + ply_list_node_t *next_node; + + seat = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (seats, node); + + ply_boot_splash_attach_to_seat (state->boot_splash, seat); + + node = next_node; + } } #ifdef PLY_ENABLE_SYSTEMD_INTEGRATION @@ -1715,7 +1574,8 @@ show_theme (state_t *state, { ply_boot_splash_mode_t splash_mode; - add_displays_and_keyboard_to_boot_splash (state, state->boot_splash); + attach_splash_to_seats (state); + ply_device_manager_activate_renderers (state->device_manager); ply_trace ("showing plugin"); if (state->mode == PLY_MODE_SHUTDOWN) @@ -1736,7 +1596,7 @@ show_theme (state_t *state, tell_systemd_to_print_details (state); #endif - activate_keyboards (state); + ply_device_manager_activate_keyboards (state->device_manager); show_messages (state); update_display (state); } @@ -1971,117 +1831,6 @@ check_logging (state_t *state) } } -static int -add_consoles_from_file (state_t *state, - const char *path) -{ - int fd; - char contents[512] = ""; - ssize_t contents_length; - int num_consoles; - const char *remaining_file_contents; - - ply_trace ("opening %s", path); - fd = open (path, O_RDONLY); - - if (fd < 0) - { - ply_trace ("couldn't open it: %m"); - return 0; - } - - ply_trace ("reading file"); - contents_length = read (fd, contents, sizeof (contents) - 1); - - if (contents_length <= 0) - { - ply_trace ("couldn't read it: %m"); - close (fd); - return 0; - } - close (fd); - - remaining_file_contents = contents; - num_consoles = 0; - - while (remaining_file_contents < contents + contents_length) - { - char *console; - size_t console_length; - const char *console_device; - ply_terminal_t *terminal; - - /* Advance past any leading whitespace */ - remaining_file_contents += strspn (remaining_file_contents, " \n\t\v"); - - if (*remaining_file_contents == '\0') - { - /* There's nothing left after the whitespace, we're done */ - break; - } - - /* Find trailing whitespace and NUL terminate. If strcspn - * doesn't find whitespace, it gives us the length of the string - * until the next NUL byte, which we'll just overwrite with - * another NUL byte anyway. */ - console_length = strcspn (remaining_file_contents, " \n\t\v"); - console = strndup (remaining_file_contents, console_length); - - /* If this console is anything besides tty0, then the user is sort - * of a weird case (uses a serial console or whatever) and they - * most likely don't want a graphical splash, so force details. - */ - if (strcmp (console, "tty0") != 0) - state->should_force_details = true; - - terminal = get_terminal (state, console); - console_device = ply_terminal_get_name (terminal); - - free (console); - - ply_trace ("console %s found!", console_device); - num_consoles++; - - /* Move past the parsed console string, and the whitespace we - * may have found above. If we found a NUL above and not whitespace, - * then we're going to jump past the end of the buffer and the loop - * will terminate - */ - remaining_file_contents += console_length + 1; - } - - return num_consoles; -} - -static void -check_for_consoles (state_t *state) -{ - int num_consoles; - bool ignore_serial_consoles; - - ply_trace ("checking for consoles%s", - state->is_shown? " and adding displays": ""); - - ignore_serial_consoles = command_line_has_argument (state->kernel_command_line, "plymouth.ignore-serial-consoles"); - - num_consoles = 0; - - if (!ignore_serial_consoles) - { - num_consoles = add_consoles_from_file (state, "/sys/class/tty/console/active"); - - if (num_consoles == 0) - { - ply_trace ("ignoring all consoles but default console because /sys/class/tty/console/active could not be read"); - } - } - else - { - ply_trace ("ignoring all consoles but default console because of plymouth.ignore-serial-consoles"); - get_terminal (state, state->default_tty); - } -} - static bool redirect_standard_io_to_dev_null (void) { @@ -2163,8 +1912,6 @@ initialize_environment (state_t *state) state->keystroke_triggers = ply_list_new (); state->entry_triggers = ply_list_new (); state->entry_buffer = ply_buffer_new(); - state->terminals = ply_hashtable_new (ply_hashtable_string_hash, ply_hashtable_string_compare); - state->seats = ply_hashtable_new (ply_hashtable_string_hash, ply_hashtable_string_compare); state->messages = ply_list_new (); redirect_standard_io_to_dev_null (); @@ -2275,6 +2022,7 @@ main (int argc, char *mode_string = NULL; char *kernel_command_line = NULL; char *tty = NULL; + ply_device_manager_flags_t device_manager_flags = PLY_DEVICE_MANAGER_FLAGS_NONE; state.command_parser = ply_command_parser_new ("plymouthd", "Splash server"); @@ -2449,6 +2197,11 @@ main (int argc, return EX_UNAVAILABLE; } + if (command_line_has_argument (state.kernel_command_line, "plymouth.ignore-serial-consoles")) + device_manager_flags |= PLY_DEVICE_MANAGER_FLAGS_IGNORE_SERIAL_CONSOLES; + + load_devices (&state, device_manager_flags); + ply_trace ("entering event loop"); exit_code = ply_event_loop_run (state.loop); ply_trace ("exited event loop"); From 27f6e5f3f856568873b4a4a193d53bad497f0563 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 9 Dec 2013 14:28:42 -0500 Subject: [PATCH 26/32] drm: support activating without terminal If there are multiple DRM devices, only one can really be reading from the terminal at a time. We currently punt this issue by ignoring all but the first drm device. In preparation for supporting more than one DRM device, we need to come up with a solution. This commit changes the DRM renderer plugin to allow getting a NULL terminal. In this way, we can assign the terminal to one of the DRM cards, but still output to the others. Note, we never pass NULL for a terminal yet, that comes later. --- src/plugins/renderers/drm/plugin.c | 45 ++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/plugins/renderers/drm/plugin.c b/src/plugins/renderers/drm/plugin.c index 945f15e6..6677279d 100644 --- a/src/plugins/renderers/drm/plugin.c +++ b/src/plugins/renderers/drm/plugin.c @@ -522,6 +522,9 @@ open_device (ply_renderer_backend_t *backend) if (!load_driver (backend)) return false; + if (backend->terminal == NULL) + return true; + if (!ply_terminal_open (backend->terminal)) { ply_trace ("could not open terminal: %m"); @@ -550,10 +553,11 @@ close_device (ply_renderer_backend_t *backend) free_heads (backend); - ply_terminal_stop_watching_for_active_vt_change (backend->terminal, - (ply_terminal_active_vt_changed_handler_t) - on_active_vt_changed, - backend); + if (backend->terminal != NULL) + ply_terminal_stop_watching_for_active_vt_change (backend->terminal, + (ply_terminal_active_vt_changed_handler_t) + on_active_vt_changed, + backend); unload_driver (backend); } @@ -888,10 +892,17 @@ map_to_device (ply_renderer_backend_t *backend) node = next_node; } - if (ply_terminal_is_active (backend->terminal)) - activate (backend); + if (backend->terminal != NULL) + { + if (ply_terminal_is_active (backend->terminal)) + activate (backend); + else + ply_terminal_activate_vt (backend->terminal); + } else - ply_terminal_activate_vt (backend->terminal); + { + activate (backend); + } return head_mapped; } @@ -1019,8 +1030,11 @@ reset_scan_out_buffer_if_needed (ply_renderer_backend_t *backend, drmModeCrtc *controller; bool did_reset = false; - if (!ply_terminal_is_active (backend->terminal)) - return false; + if (backend->terminal != NULL) + { + if (!ply_terminal_is_active (backend->terminal)) + return false; + } controller = drmModeGetCrtc (backend->device_fd, head->controller_id); @@ -1054,8 +1068,11 @@ flush_head (ply_renderer_backend_t *backend, if (!backend->is_active) return; - ply_terminal_set_mode (backend->terminal, PLY_TERMINAL_MODE_GRAPHICS); - ply_terminal_set_unbuffered_input (backend->terminal); + if (backend->terminal != NULL) + { + ply_terminal_set_mode (backend->terminal, PLY_TERMINAL_MODE_GRAPHICS); + ply_terminal_set_unbuffered_input (backend->terminal); + } pixel_buffer = head->pixel_buffer; updated_region = ply_pixel_buffer_get_updated_areas (pixel_buffer); areas_to_flush = ply_region_get_sorted_rectangle_list (updated_region); @@ -1163,6 +1180,9 @@ open_input_source (ply_renderer_backend_t *backend, assert (backend != NULL); assert (has_input_source (backend, input_source)); + if (backend->terminal == NULL) + return false; + terminal_fd = ply_terminal_get_fd (backend->terminal); input_source->backend = backend; @@ -1193,6 +1213,9 @@ close_input_source (ply_renderer_backend_t *backend, assert (backend != NULL); assert (has_input_source (backend, input_source)); + if (backend->terminal == NULL) + return; + ply_event_loop_stop_watching_fd (backend->loop, input_source->terminal_input_watch); input_source->terminal_input_watch = NULL; input_source->backend = NULL; From f1f54ff1be292acb2391a46a8bffab34d5889ad9 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 9 Dec 2013 14:35:31 -0500 Subject: [PATCH 27/32] frame-buffer: support activating without a terminal This is the same as the previous drm commit, but for the frame-buffer backend. --- src/plugins/renderers/frame-buffer/plugin.c | 42 +++++++++++++++------ 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/src/plugins/renderers/frame-buffer/plugin.c b/src/plugins/renderers/frame-buffer/plugin.c index 0e079431..dd73a0f7 100644 --- a/src/plugins/renderers/frame-buffer/plugin.c +++ b/src/plugins/renderers/frame-buffer/plugin.c @@ -351,6 +351,9 @@ open_device (ply_renderer_backend_t *backend) return false; } + if (backend->terminal == NULL) + return true; + if (!ply_terminal_open (backend->terminal)) { ply_trace ("could not open terminal: %m"); @@ -376,10 +379,11 @@ static void close_device (ply_renderer_backend_t *backend) { - ply_terminal_stop_watching_for_active_vt_change (backend->terminal, - (ply_terminal_active_vt_changed_handler_t) - on_active_vt_changed, - backend); + if (backend->terminal != NULL) + ply_terminal_stop_watching_for_active_vt_change (backend->terminal, + (ply_terminal_active_vt_changed_handler_t) + on_active_vt_changed, + backend); uninitialize_head (backend, &backend->head); close (backend->device_fd); @@ -546,15 +550,22 @@ map_to_device (ply_renderer_backend_t *backend) return false; } - if (ply_terminal_is_active (backend->terminal)) + if (backend->terminal != NULL) { - ply_trace ("already on right vt, activating"); - activate (backend); + if (ply_terminal_is_active (backend->terminal)) + { + ply_trace ("already on right vt, activating"); + activate (backend); + } + else + { + ply_trace ("on wrong vt, changing vts"); + ply_terminal_activate_vt (backend->terminal); + } } else { - ply_trace ("on wrong vt, changing vts"); - ply_terminal_activate_vt (backend->terminal); + activate (backend); } return true; @@ -590,8 +601,11 @@ flush_head (ply_renderer_backend_t *backend, if (!backend->is_active) return; - ply_terminal_set_mode (backend->terminal, PLY_TERMINAL_MODE_GRAPHICS); - ply_terminal_set_unbuffered_input (backend->terminal); + if (backend->terminal != NULL) + { + ply_terminal_set_mode (backend->terminal, PLY_TERMINAL_MODE_GRAPHICS); + ply_terminal_set_unbuffered_input (backend->terminal); + } pixel_buffer = head->pixel_buffer; updated_region = ply_pixel_buffer_get_updated_areas (pixel_buffer); areas_to_flush = ply_region_get_sorted_rectangle_list (updated_region); @@ -685,6 +699,9 @@ open_input_source (ply_renderer_backend_t *backend, assert (backend != NULL); assert (has_input_source (backend, input_source)); + if (backend->terminal == NULL) + return false; + terminal_fd = ply_terminal_get_fd (backend->terminal); input_source->backend = backend; @@ -715,6 +732,9 @@ close_input_source (ply_renderer_backend_t *backend, assert (backend != NULL); assert (has_input_source (backend, input_source)); + if (backend->terminal == NULL) + return; + ply_event_loop_stop_watching_fd (backend->loop, input_source->terminal_input_watch); input_source->terminal_input_watch = NULL; input_source->backend = NULL; From 42d885c83b6be5104fd397f412662922d9641a01 Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Tue, 19 Nov 2013 21:22:58 -0500 Subject: [PATCH 28/32] configure: add libudev dependency We're going to want to support multiple graphics devices, as specified by udev. This first commit, merely adds the libudev dependency to the build goo. --- configure.ac | 4 ++++ src/Makefile.am | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index 7bdfd821..7b0f68cd 100644 --- a/configure.ac +++ b/configure.ac @@ -38,6 +38,10 @@ PKG_CHECK_MODULES(IMAGE, [libpng >= 1.2.16 ]) AC_SUBST(IMAGE_CFLAGS) AC_SUBST(IMAGE_LIBS) +PKG_CHECK_MODULES(UDEV, [libudev]); +AC_SUBST(UDEV_CFLAGS) +AC_SUBST(UDEV_LIBS) + PLYMOUTH_CFLAGS="" PLYMOUTH_LIBS="-lm -lrt -ldl" diff --git a/src/Makefile.am b/src/Makefile.am index 150e959c..c535f21c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -15,12 +15,13 @@ plymouthdbindir = $(plymouthdaemondir) plymouthdbin_PROGRAMS = plymouthd plymouthd_CFLAGS = $(PLYMOUTH_CFLAGS) \ + $(UDEV_CFLAGS) \ -DPLYMOUTH_PLUGIN_PATH=\"$(PLYMOUTH_PLUGIN_PATH)\" \ -DPLYMOUTH_THEME_PATH=\"$(PLYMOUTH_THEME_PATH)/\" \ -DPLYMOUTH_POLICY_DIR=\"$(PLYMOUTH_POLICY_DIR)/\" \ -DPLYMOUTH_RUNTIME_DIR=\"$(PLYMOUTH_RUNTIME_DIR)\" \ -DPLYMOUTH_CONF_DIR=\"$(PLYMOUTH_CONF_DIR)/\" -plymouthd_LDADD = $(PLYMOUTH_LIBS) libply/libply.la libply-splash-core/libply-splash-core.la +plymouthd_LDADD = $(PLYMOUTH_LIBS) $(UDEV_LIBS) libply/libply.la libply-splash-core/libply-splash-core.la plymouthd_SOURCES = \ ply-boot-protocol.h \ ply-boot-server.h \ From 83c59f344ee67950e66eaa214600e24df900c54d Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 9 Dec 2013 21:13:13 -0500 Subject: [PATCH 29/32] renderer: add way to get device_name that was passed to constructor It's useful to be able to figure out which renderer a given renderer is, by examining the device that is associated with it. This commit adds and accessor function to return the device that was passed to ply_renderer_new. At the moment, it does not return the device name if NULL was passed to the constructor and the device was figured out automatically. A future commit may add that ability if it becomes necessary. --- src/libply-splash-core/ply-renderer.c | 6 ++++++ src/libply-splash-core/ply-renderer.h | 1 + 2 files changed, 7 insertions(+) diff --git a/src/libply-splash-core/ply-renderer.c b/src/libply-splash-core/ply-renderer.c index 39fbf9ab..04a99cef 100644 --- a/src/libply-splash-core/ply-renderer.c +++ b/src/libply-splash-core/ply-renderer.c @@ -97,6 +97,12 @@ ply_renderer_free (ply_renderer_t *renderer) free (renderer); } +const char * +ply_renderer_get_device_name (ply_renderer_t *renderer) +{ + return renderer->device_name; +} + static bool ply_renderer_load_plugin (ply_renderer_t *renderer, const char *module_path) diff --git a/src/libply-splash-core/ply-renderer.h b/src/libply-splash-core/ply-renderer.h index 75c39fab..3d483413 100644 --- a/src/libply-splash-core/ply-renderer.h +++ b/src/libply-splash-core/ply-renderer.h @@ -57,6 +57,7 @@ bool ply_renderer_open (ply_renderer_t *renderer); void ply_renderer_close (ply_renderer_t *renderer); void ply_renderer_activate (ply_renderer_t *renderer); void ply_renderer_deactivate (ply_renderer_t *renderer); +const char *ply_renderer_get_device_name (ply_renderer_t *renderer); ply_list_t *ply_renderer_get_heads (ply_renderer_t *renderer); ply_pixel_buffer_t *ply_renderer_get_buffer_for_head (ply_renderer_t *renderer, ply_renderer_head_t *head); From c66c207d2e25ae77d118a6037db35454678a49dc Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 9 Dec 2013 13:13:38 -0500 Subject: [PATCH 30/32] device-manager: add support for udev device enumeration At the moment, we hardcode /dev/dri/card0 for the DRM device. This works well enough in the lion's share of cases, but there are cases where it falls over. Namely, machines with multiple GPUs, such as optimus hardware, sometimes end up with the kernel fb console going to /dev/dri/card1. Rather than trying /dev/dri/card0 then /dev/dri/card1 etc in succession, this commit, instead, adds support for querying udev for the information. --- src/libply-splash-core/ply-device-manager.c | 309 +++++++++++++++++++- src/libply-splash-core/ply-device-manager.h | 3 +- 2 files changed, 308 insertions(+), 4 deletions(-) diff --git a/src/libply-splash-core/ply-device-manager.c b/src/libply-splash-core/ply-device-manager.c index f53c0446..9a66988b 100644 --- a/src/libply-splash-core/ply-device-manager.c +++ b/src/libply-splash-core/ply-device-manager.c @@ -29,12 +29,18 @@ #include #include +#include + #include "ply-logger.h" #include "ply-event-loop.h" #include "ply-hashtable.h" #include "ply-list.h" #include "ply-utils.h" +static void create_seat_for_terminal_and_renderer_type (ply_device_manager_t *manager, + const char *device_path, + ply_terminal_t *terminal, + ply_renderer_type_t renderer_type); struct _ply_device_manager { ply_device_manager_flags_t flags; @@ -42,6 +48,8 @@ struct _ply_device_manager ply_hashtable_t *terminals; ply_terminal_t *local_console_terminal; ply_list_t *seats; + struct udev *udev_context; + struct udev_monitor *udev_monitor; ply_seat_added_handler_t seat_added_handler; ply_seat_removed_handler_t seat_removed_handler; @@ -71,6 +79,268 @@ attach_to_event_loop (ply_device_manager_t *manager, manager); } +static bool +device_is_for_local_console (ply_device_manager_t *manager, + struct udev_device *device) +{ + const char *device_path; + struct udev_device *bus_device; + char *bus_device_path; + const char *boot_vga; + bool for_local_console; + + /* Look at the associated bus device to see if this card is the + * card the kernel is using for its console. */ + device_path = udev_device_get_syspath (device); + asprintf (&bus_device_path, "%s/device", device_path); + bus_device = udev_device_new_from_syspath (manager->udev_context, bus_device_path); + + boot_vga = udev_device_get_sysattr_value (bus_device, "boot_vga"); + free (bus_device_path); + + if (boot_vga != NULL && strcmp (boot_vga, "1") == 0) + for_local_console = true; + else + for_local_console = false; + + return for_local_console; +} + +static char * +get_drm_device_node_path_from_fb_device (ply_device_manager_t *manager, + struct udev_device *fb_device) +{ + struct udev_enumerate *card_matches; + struct udev_list_entry *card_entry; + const char *id_path; + char *device_node_path = NULL; + + /* We want to see if the framebuffer is associated with a DRM-capable + * graphics card, if it is, we'll use the DRM device */ + card_matches = udev_enumerate_new (manager->udev_context); + udev_enumerate_add_match_is_initialized(card_matches); + udev_enumerate_add_match_parent (card_matches, udev_device_get_parent (fb_device)); + udev_enumerate_add_match_subsystem (card_matches, "drm"); + id_path = udev_device_get_property_value (fb_device, "ID_PATH"); + udev_enumerate_add_match_property (card_matches, "ID_PATH", id_path); + + udev_enumerate_scan_devices (card_matches); + + /* there should only ever be at most one match so we don't iterate through + * the list, but just look at the first entry */ + card_entry = udev_enumerate_get_list_entry (card_matches); + + if (card_entry != NULL) + { + struct udev_device *card_device = NULL; + const char *card_node; + const char *card_path; + + card_path = udev_list_entry_get_name (card_entry); + card_device = udev_device_new_from_syspath (manager->udev_context, card_path); + card_node = udev_device_get_devnode (card_device); + if (card_node != NULL) + device_node_path = strdup (card_node); + + udev_device_unref (card_device); + } + + udev_enumerate_unref (card_matches); + return device_node_path; +} + +static void +create_seat_for_udev_device (ply_device_manager_t *manager, + struct udev_device *device) +{ + bool for_local_console; + char *card_path; + ply_terminal_t *terminal = NULL; + + for_local_console = device_is_for_local_console (manager, device); + + if (for_local_console) + terminal = manager->local_console_terminal; + + card_path = get_drm_device_node_path_from_fb_device (manager, device); + + if (card_path != NULL) + { + create_seat_for_terminal_and_renderer_type (manager, + card_path, + terminal, + PLY_RENDERER_TYPE_DRM); + free (card_path); + } + else + { + const char *fb_device_node_path; + + fb_device_node_path = udev_device_get_devnode (device); + if (fb_device_node_path != NULL) + create_seat_for_terminal_and_renderer_type (manager, + fb_device_node_path, + terminal, + PLY_RENDERER_TYPE_FRAME_BUFFER); + } +} + +static void +free_seat_from_device_path (ply_device_manager_t *manager, + const char *device_path) +{ + ply_list_node_t *node; + + node = ply_list_get_first_node (manager->seats); + while (node != NULL) + { + ply_seat_t *seat; + ply_renderer_t *renderer; + ply_list_node_t *next_node; + const char *renderer_device_path; + + seat = ply_list_node_get_data (node); + next_node = ply_list_get_next_node (manager->seats, node); + renderer = ply_seat_get_renderer (seat); + + if (renderer != NULL) + { + renderer_device_path = ply_renderer_get_device_name (renderer); + + if (renderer_device_path != NULL) + { + if (strcmp (device_path, renderer_device_path) == 0) + { + ply_trace ("removing seat associated with %s", device_path); + + if (manager->seat_removed_handler != NULL) + manager->seat_removed_handler (manager->seat_event_handler_data, seat); + + ply_seat_free (seat); + ply_list_remove_node (manager->seats, node); + break; + } + } + } + + node = next_node; + } +} + +static void +free_seat_for_udev_device (ply_device_manager_t *manager, + struct udev_device *device) +{ + char *card_path; + + card_path = get_drm_device_node_path_from_fb_device (manager, device); + + if (card_path != NULL) + { + free_seat_from_device_path (manager, card_path); + free (card_path); + } + else + { + const char *fb_device_node_path; + + fb_device_node_path = udev_device_get_devnode (device); + + if (fb_device_node_path != NULL) + free_seat_from_device_path (manager, fb_device_node_path); + } +} + +static void +scan_graphics_devices (ply_device_manager_t *manager) +{ + struct udev_enumerate *fb_matches; + struct udev_list_entry *fb_entry; + + ply_trace ("scanning for graphics devices"); + /* graphics subsystem is for /dev/fb devices. kms drivers provide /dev/fb for backward + * compatibility, and do so at the end of their initialization, so we can be confident + * that when this subsystem is available the drm device is fully initialized */ + fb_matches = udev_enumerate_new (manager->udev_context); + udev_enumerate_add_match_is_initialized(fb_matches); + udev_enumerate_add_match_subsystem (fb_matches, "graphics"); + + /* We only care about devices assigned to a (any) seat. Floating + * devices should be ignored. As a side-effect, this conveniently + * filters out the fbcon device which we don't care about. + */ + udev_enumerate_add_match_tag (fb_matches, "seat"); + udev_enumerate_scan_devices (fb_matches); + + udev_list_entry_foreach (fb_entry, udev_enumerate_get_list_entry (fb_matches)) + { + struct udev_device *fb_device = NULL; + const char *fb_node; + const char *fb_path; + + fb_path = udev_list_entry_get_name (fb_entry); + fb_device = udev_device_new_from_syspath (manager->udev_context, fb_path); + fb_node = udev_device_get_devnode (fb_device); + if (fb_node != NULL) + create_seat_for_udev_device (manager, fb_device); + + udev_device_unref (fb_device); + } + + udev_enumerate_unref (fb_matches); +} + +static void +on_udev_graphics_event (ply_device_manager_t *manager) +{ + struct udev_device *device; + const char *action; + + device = udev_monitor_receive_device (manager->udev_monitor); + if (device == NULL) + return; + + action = udev_device_get_action (device); + + if (action == NULL) + return; + + if (strcmp (action, "add") == 0) + create_seat_for_udev_device (manager, device); + else if (strcmp (action, "remove") == 0) + free_seat_for_udev_device (manager, device); + + udev_device_unref (device); +} + +static void +watch_for_udev_events (ply_device_manager_t *manager) +{ + int fd; + assert (manager != NULL); + assert (manager->udev_monitor == NULL); + + ply_trace ("watching for udev graphics device add and remove events"); + manager->udev_monitor = udev_monitor_new_from_netlink (manager->udev_context, "udev"); + + /* The filter matching here mimics the matching done in scan_graphics_devices. + * See the comments in that function, for an explanation of what we're doing. + */ + udev_monitor_filter_add_match_subsystem_devtype (manager->udev_monitor, "graphics", NULL); + udev_monitor_filter_add_match_tag (manager->udev_monitor, "seat"); + udev_monitor_enable_receiving (manager->udev_monitor); + + fd = udev_monitor_get_fd (manager->udev_monitor); + ply_event_loop_watch_fd (manager->loop, + fd, + PLY_EVENT_LOOP_FD_STATUS_HAS_DATA, + (ply_event_handler_t) + on_udev_graphics_event, + NULL, + manager); + +} + static void free_seats (ply_device_manager_t *manager) { @@ -167,6 +437,9 @@ ply_device_manager_new (const char *default_tty, manager->seats = ply_list_new (); manager->flags = flags; + if (!(flags & PLY_DEVICE_MANAGER_FLAGS_IGNORE_UDEV)) + manager->udev_context = udev_new (); + attach_to_event_loop (manager, ply_event_loop_get_default ()); return manager; @@ -186,6 +459,12 @@ ply_device_manager_free (ply_device_manager_t *manager) free_terminals (manager); ply_hashtable_free (manager->terminals); + if (manager->udev_monitor != NULL) + udev_monitor_unref (manager->udev_monitor); + + if (manager->udev_context != NULL) + udev_unref (manager->udev_context); + free (manager); } @@ -299,10 +578,11 @@ create_seat_for_terminal (const char *device_path, terminal, PLY_RENDERER_TYPE_NONE); } -static void +static bool create_seats_from_terminals (ply_device_manager_t *manager) { int num_consoles; + bool seats_created; ply_trace ("checking for consoles"); @@ -321,18 +601,29 @@ create_seats_from_terminals (ply_device_manager_t *manager) if (num_consoles > 1) { + ply_trace ("serial consoles detected, managing them with details forced"); ply_hashtable_foreach (manager->terminals, (ply_hashtable_foreach_func_t *) create_seat_for_terminal, manager); + seats_created = true; } - else + else if (num_consoles <= 1 && (manager->flags & PLY_DEVICE_MANAGER_FLAGS_IGNORE_UDEV)) { + ply_trace ("udev disabled, managing seat right away"); create_seat_for_terminal_and_renderer_type (manager, ply_terminal_get_name (manager->local_console_terminal), manager->local_console_terminal, PLY_RENDERER_TYPE_AUTO); + seats_created = true; } + else + { + ply_trace ("will manage seat when ready"); + seats_created = false; + } + + return seats_created; } void @@ -341,11 +632,23 @@ ply_device_manager_watch_seats (ply_device_manager_t *manager, ply_seat_removed_handler_t seat_removed_handler, void *data) { + bool seats_created; + manager->seat_added_handler = seat_added_handler; manager->seat_removed_handler = seat_removed_handler; manager->seat_event_handler_data = data; - create_seats_from_terminals (manager); + /* Try to create seats for each terminal device right away, if possible + */ + seats_created = create_seats_from_terminals (manager); + + /* In most cases, though, we need to create devices based on udev device topology + */ + if (!seats_created) + { + watch_for_udev_events (manager); + scan_graphics_devices (manager); + } } bool diff --git a/src/libply-splash-core/ply-device-manager.h b/src/libply-splash-core/ply-device-manager.h index 28d66750..d9c58e87 100644 --- a/src/libply-splash-core/ply-device-manager.h +++ b/src/libply-splash-core/ply-device-manager.h @@ -26,7 +26,8 @@ typedef enum { PLY_DEVICE_MANAGER_FLAGS_NONE = 0, - PLY_DEVICE_MANAGER_FLAGS_IGNORE_SERIAL_CONSOLES = 1 << 0 + PLY_DEVICE_MANAGER_FLAGS_IGNORE_SERIAL_CONSOLES = 1 << 0, + PLY_DEVICE_MANAGER_FLAGS_IGNORE_UDEV = 1 << 1 } ply_device_manager_flags_t; typedef struct _ply_device_manager ply_device_manager_t; From 487092edd46358beea32314cc33e2fd24f66a24a Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 9 Dec 2013 21:07:16 -0500 Subject: [PATCH 31/32] main: provide way to toggle udev device enumeration off We don't want to use udev for device enumeration if: 1) DISPLAY is set (since we're going to use the X11 renderer) 2) if it's disabled explicitly on the kernel command line This commit adds support for those two things. --- src/main.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main.c b/src/main.c index b1dee587..50062951 100644 --- a/src/main.c +++ b/src/main.c @@ -2200,6 +2200,10 @@ main (int argc, if (command_line_has_argument (state.kernel_command_line, "plymouth.ignore-serial-consoles")) device_manager_flags |= PLY_DEVICE_MANAGER_FLAGS_IGNORE_SERIAL_CONSOLES; + if (command_line_has_argument (state.kernel_command_line, "plymouth.ignore-udev") || + (getenv ("DISPLAY") != NULL)) + device_manager_flags |= PLY_DEVICE_MANAGER_FLAGS_IGNORE_UDEV; + load_devices (&state, device_manager_flags); ply_trace ("entering event loop"); From 90a23b832d1f113d679be1dfa60cba448a07a8ce Mon Sep 17 00:00:00 2001 From: Ray Strode Date: Mon, 9 Dec 2013 21:50:07 -0500 Subject: [PATCH 32/32] systemd: don't call udevadm settle before show-splash Since we're monitoring udev explicitly now, we have no need to block the client show-splash request until graphics devices settle. This commit removes the udevadm calls from plymouth-start.service. --- systemd-units/plymouth-start.service.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemd-units/plymouth-start.service.in b/systemd-units/plymouth-start.service.in index 446fb32b..078840c7 100644 --- a/systemd-units/plymouth-start.service.in +++ b/systemd-units/plymouth-start.service.in @@ -8,7 +8,7 @@ ConditionKernelCommandLine=!plymouth.enable=0 [Service] ExecStart=@PLYMOUTH_DAEMON_DIR@/plymouthd --mode=boot --pid-file=@plymouthruntimedir@/pid --attach-to-session -ExecStartPost=-@UDEVADM@ settle --timeout=30 --exit-if-exists=/sys/class/drm/card0/dev ; -@UDEVADM@ settle --timeout=30 --exit-if-exists=/sys/class/graphics/fb0/dev ; -@PLYMOUTH_CLIENT_DIR@/plymouth show-splash +ExecStartPost=-@PLYMOUTH_CLIENT_DIR@/plymouth show-splash Type=forking KillMode=none SendSIGKILL=no