From 63b97c7852d1eb153bc2013c3747249dcc41494f Mon Sep 17 00:00:00 2001
From: Didier Roche <didrocks@ubuntu.com>
Date: Mon, 26 Jan 2015 16:29:30 +0100
Subject: [PATCH 05/13] 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:<nb_devices>:<progress>:<string>

* nb_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)
* string is a translated message ready to be displayed by the plymouth theme
  displaying both data above. It can be overriden by plymouth themes supporting
  i18n.
---
 src/fsckd/fsckd.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/src/fsckd/fsckd.c b/src/fsckd/fsckd.c
index 19c899c..c418e49 100644
--- a/src/fsckd/fsckd.c
+++ b/src/fsckd/fsckd.c
@@ -34,6 +34,7 @@
 #include "log.h"
 #include "list.h"
 #include "macro.h"
+#include "plymouth.h"
 #include "sd-daemon.h"
 #include "time-util.h"
 #include "util.h"
@@ -111,7 +112,7 @@ static int treat_requests(int socket_fd) {
                 int new_client_fd = 0;
                 bool remove_previous = false;
                 Clients *current, *to_remove;
-                _cleanup_free_ char *console_message = NULL;
+                _cleanup_free_ char *console_message = NULL, *fsck_message = NULL;
                 int current_nbdevices = 0, m = 0;
                 double current_minpercent = 100;
                 usec_t t;
@@ -200,6 +201,7 @@ static int treat_requests(int socket_fd) {
 
                         asprintf(&console_message, "Checking in progress on %d disks (%3.1f%% complete)",
                                  nbdevices, minpercent);
+                        asprintf(&fsck_message, "fsckd:%d:%3.1f:%s", nbdevices, minpercent, console_message);
 
                         /* write to console */
                         if (show_progress) {
@@ -207,6 +209,9 @@ static int treat_requests(int socket_fd) {
                                 fflush(console);
                         }
 
+                        /* send to plymouth */
+                        plymouth_update(fsck_message);
+
                         if (m > clear)
                                 clear = m;
                 }
@@ -232,6 +237,7 @@ static int treat_requests(int socket_fd) {
                 fputc('\r', console);
                 fflush(console);
         }
+        plymouth_disconnect();
 
         return 0;
 }
-- 
2.1.4

