[systemd-devel] [PATCH 05/12] Connect and send to plymouth progress report

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Wed Jan 28 06:47:58 PST 2015


On Wed, Jan 28, 2015 at 02:22:30PM +0100, Didier Roche wrote:
> 

> From c60d4f41e279dd5ed7134d97d95549aac1f38e69 Mon Sep 17 00:00:00 2001
> From: Didier Roche <didrocks at ubuntu.com>
> Date: Mon, 26 Jan 2015 16:29:30 +0100
> Subject: [PATCH 05/12] Connect and send to plymouth progress report
> 
> Try to connect and send to plymouth (if running) some check report progress,
> using libplymouth.
> 
> Update message is the following:
> fsckd:<num_devices>:<progress>:<string>
> 
> * num_devices corresponds to the current number of devices being checked (int)
> * progress corresponds to the current minimum percentage of all devices being
>   checking (float, from 0 to 100)
checked

> * string is a translated message ready to be displayed by the plymouth theme
>   displaying the information above. It can be overriden by plymouth themes
>   supporting i18n.
> ---
>  src/fsckd/fsckd.c     | 23 ++++++++++++++++++++++-
>  src/shared/plymouth.c | 15 +++++++++++++++
>  src/shared/plymouth.h |  2 ++
>  3 files changed, 39 insertions(+), 1 deletion(-)
> 
> diff --git a/src/fsckd/fsckd.c b/src/fsckd/fsckd.c
> index e27cd6d..b516193 100644
> --- a/src/fsckd/fsckd.c
> +++ b/src/fsckd/fsckd.c
> @@ -39,6 +39,9 @@
>  #include "log.h"
>  #include "list.h"
>  #include "macro.h"
> +#ifdef HAVE_PLYMOUTH
> +#include "plymouth.h"
> +#endif
>  #include "sd-daemon.h"
>  #include "time-util.h"
>  #include "util.h"
> @@ -95,6 +98,9 @@ static int handle_requests(int socket_fd) {
>                  int new_client_fd = 0;
>                  Clients *current;
>                  _cleanup_free_ char *console_message = NULL;
> +#ifdef HAVE_PLYMOUTH
> +                _cleanup_free_ char *fsck_message = NULL;
> +#endif
>                  double current_percent = 100;
>                  int current_numdevices = 0, m = 0;
>                  usec_t t;
> @@ -155,6 +161,9 @@ static int handle_requests(int socket_fd) {
>  
>                          asprintf(&console_message, "Checking in progress on %d disks (%3.1f%% complete)",
>                                   numdevices, percent);
> +#ifdef HAVE_PLYMOUTH
> +                        asprintf(&fsck_message, "fsckd:%d:%3.1f:%s", numdevices, percent, console_message);
> +#endif
oom check.

>  
>                          /* write to console */
>                          if (show_progress) {
> @@ -162,6 +171,11 @@ static int handle_requests(int socket_fd) {
>                                  fflush(console);
>                          }
>  
> +#ifdef HAVE_PLYMOUTH
> +                        /* send to plymouth */
> +                        plymouth_update(fsck_message);
> +#endif
> +
>                          if (m > clear)
>                                  clear = m;
>                  }
> @@ -187,6 +201,9 @@ static int handle_requests(int socket_fd) {
>                  fputc('\r', console);
>                  fflush(console);
>          }
> +#ifdef HAVE_PLYMOUTH
> +        plymouth_disconnect();
> +#endif
>  
>          return 0;
>  }
> @@ -218,7 +235,11 @@ static int create_socket(void) {
>  
>  static void help(void) {
>          printf("%s [OPTIONS...]\n\n"
> -               "Capture fsck progress and forward one stream to plymouth\n\n"
> +#ifdef HAVE_PLYMOUTH
> +               "Capture fsck progress, log to console and forward one stream to plymouth\n\n"
> +#else
> +               "Capture fsck progress and log to console\n\n"
> +#endif
>                 "  -h --help             Show this help\n"
>                 "     --version          Show package version\n",
>                 program_invocation_short_name);
> diff --git a/src/shared/plymouth.c b/src/shared/plymouth.c
> index f7155c4..b43d355 100644
> --- a/src/shared/plymouth.c
> +++ b/src/shared/plymouth.c
> @@ -92,6 +92,21 @@ void plymouth_update(const char *message) {
>          ply_boot_client_flush(plymouth_client);
>  }
>  
> +static void plymouth_key_pressed(void *callback, const char *pressed_key, ply_boot_client_t *client) {
> +        ((keypress_callback)callback)();
> +}
> +
> +bool plymouth_watch_key(const char *keys, const char *message, keypress_callback callback) {
> +        if (!plymouth_running() || !plymouth_connect())
> +                return false;
> +
> +        ply_boot_client_tell_daemon_to_display_message (plymouth_client, message, NULL,
> +                                                        plymouth_update_failed, NULL);
> +        ply_boot_client_ask_daemon_to_watch_for_keystroke (plymouth_client, keys, plymouth_key_pressed,
> +                                                           NULL, callback);
> +        return true;
> +}
> +
>  void plymouth_delete_message(void) {
>          if (!plymouth_running() || !plymouth_client)
>                  return;
> diff --git a/src/shared/plymouth.h b/src/shared/plymouth.h
> index 15cecb7..f5ea00c 100644
> --- a/src/shared/plymouth.h
> +++ b/src/shared/plymouth.h
> @@ -30,5 +30,7 @@ bool plymouth_connect(void);
>  void plymouth_disconnect(void);
>  void plymouth_update(const char *message);
>  
> +typedef void (*keypress_callback)(void);
>  void plymouth_delete_message(void);
> +bool plymouth_watch_key(const char *keys, const char *message, keypress_callback callback);
>  #endif

Zbyszek


More information about the systemd-devel mailing list