From e4b0fdd10764483e5ba750158189384215d87384 Mon Sep 17 00:00:00 2001
From: Didier Roche <didrocks@ubuntu.com>
Date: Mon, 26 Jan 2015 16:01:11 +0100
Subject: [PATCH 03/13] systemd-fsck: always connect to systemd-fsckd

Remove the plymouth running or show-status checks from systemd-fsck. Instead,
always connect to systemd-fsckd socket, and let this one decides if we display
progress or not.
---
 src/fsck/fsck.c   | 12 ++++--------
 src/fsckd/fsckd.c | 12 ++++++++++--
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/src/fsck/fsck.c b/src/fsck/fsck.c
index 7276682..2298cd5 100644
--- a/src/fsck/fsck.c
+++ b/src/fsck/fsck.c
@@ -45,7 +45,6 @@
 
 static bool arg_skip = false;
 static bool arg_force = false;
-static bool arg_show_progress = false;
 static const char *arg_repair = "-a";
 
 static void start_target(const char *target) {
@@ -131,8 +130,6 @@ static void test_files(void) {
         }
 #endif
 
-        if (access("/run/systemd/show-status", F_OK) >= 0 || plymouth_running())
-                arg_show_progress = true;
 }
 
 static double percent(int pass, unsigned long cur, unsigned long max) {
@@ -311,11 +308,10 @@ int main(int argc, char *argv[]) {
                         log_warning_errno(r, "fsck.%s cannot be used for %s: %m", type, device);
         }
 
-        if (arg_show_progress)
-                if (pipe(progress_pipe) < 0) {
-                        log_error_errno(errno, "pipe(): %m");
-                        return EXIT_FAILURE;
-                }
+        if (pipe(progress_pipe) < 0) {
+                log_error_errno(errno, "pipe(): %m");
+                return EXIT_FAILURE;
+        }
 
         cmdline[i++] = "/sbin/fsck";
         cmdline[i++] =  arg_repair;
diff --git a/src/fsckd/fsckd.c b/src/fsckd/fsckd.c
index 3fc1053..19c899c 100644
--- a/src/fsckd/fsckd.c
+++ b/src/fsckd/fsckd.c
@@ -42,6 +42,8 @@
 #define IDLE_TIME_MINUTES 1
 #define ERROR_FORMAT_MSG "We expected that the sent format would be of form: \"/dev/<device>:(double progress)\\n\". Received: %s"
 
+static bool show_progress = false;
+
 typedef struct Clients {
         int fd;
         double percentage;
@@ -200,8 +202,10 @@ static int treat_requests(int socket_fd) {
                                  nbdevices, minpercent);
 
                         /* write to console */
-                        fprintf(console, "\r%s\r%n", console_message, &m);
-                        fflush(console);
+                        if (show_progress) {
+                                fprintf(console, "\r%s\r%n", console_message, &m);
+                                fflush(console);
+                        }
 
                         if (m > clear)
                                 clear = m;
@@ -336,5 +340,9 @@ int main(int argc, char *argv[]) {
                 if (fd <= 0)
                         return EXIT_FAILURE;
         }
+
+        if (access("/run/systemd/show-status", F_OK) >= 0)
+                show_progress = true;
+
         return treat_requests(fd) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
 }
-- 
2.1.4

