]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/fsck/fsck.c
update TODO
[thirdparty/systemd.git] / src / fsck / fsck.c
index ba39f596fc75b4a320a5ec3d127fc927cd3d14b0..80f7107b9d9758aaac1445de1487b68ffd6a924b 100644 (file)
@@ -6,7 +6,6 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdbool.h>
-#include <stdio.h>
 #include <sys/file.h>
 #include <sys/prctl.h>
 #include <sys/stat.h>
@@ -22,6 +21,7 @@
 #include "device-util.h"
 #include "fd-util.h"
 #include "fs-util.h"
+#include "fsck-util.h"
 #include "main-func.h"
 #include "parse-util.h"
 #include "path-util.h"
 #include "stdio-util.h"
 #include "util.h"
 
-/* exit codes as defined in fsck(8) */
-enum {
-        FSCK_SUCCESS                 = 0,
-        FSCK_ERROR_CORRECTED         = 1 << 0,
-        FSCK_SYSTEM_SHOULD_REBOOT    = 1 << 1,
-        FSCK_ERRORS_LEFT_UNCORRECTED = 1 << 2,
-        FSCK_OPERATIONAL_ERROR       = 1 << 3,
-        FSCK_USAGE_OR_SYNTAX_ERROR   = 1 << 4,
-        FSCK_USER_CANCELLED          = 1 << 5,
-        FSCK_SHARED_LIB_ERROR        = 1 << 7,
-};
-
 static bool arg_skip = false;
 static bool arg_force = false;
 static bool arg_show_progress = false;
@@ -167,8 +155,8 @@ static double percent(int pass, unsigned long cur, unsigned long max) {
                 (double) cur / (double) max;
 }
 
-static int process_progress(int fd) {
-        _cleanup_fclose_ FILE *console = NULL, *f = NULL;
+static int process_progress(int fd, FILE* console) {
+        _cleanup_fclose_ FILE *f = NULL;
         usec_t last = 0;
         bool locked = false;
         int clear = 0, r;
@@ -180,13 +168,9 @@ static int process_progress(int fd) {
         f = fdopen(fd, "r");
         if (!f) {
                 safe_close(fd);
-                return -errno;
+                return log_debug_errno(errno, "Failed to use pipe: %m");
         }
 
-        console = fopen("/dev/console", "we");
-        if (!console)
-                return -ENOMEM;
-
         for (;;) {
                 int pass, m;
                 unsigned long cur, max;
@@ -200,10 +184,9 @@ static int process_progress(int fd) {
                                 r = log_warning_errno(errno, "Failed to read from progress pipe: %m");
                         else if (feof(f))
                                 r = 0;
-                        else {
-                                log_warning("Failed to parse progress pipe data");
-                                r = -EBADMSG;
-                        }
+                        else
+                                r = log_warning_errno(SYNTHETIC_ERRNO(errno), "Failed to parse progress pipe data");
+
                         break;
                 }
 
@@ -265,6 +248,8 @@ static int fsck_progress_socket(void) {
 static int run(int argc, char *argv[]) {
         _cleanup_close_pair_ int progress_pipe[2] = { -1, -1 };
         _cleanup_(sd_device_unrefp) sd_device *dev = NULL;
+        _cleanup_free_ char *dpath = NULL;
+        _cleanup_fclose_ FILE *console = NULL;
         const char *device, *type;
         bool root_directory;
         struct stat st;
@@ -290,7 +275,11 @@ static int run(int argc, char *argv[]) {
                 return 0;
 
         if (argc > 1) {
-                device = argv[1];
+                dpath = strdup(argv[1]);
+                if (!dpath)
+                        return log_oom();
+
+                device = dpath;
 
                 if (stat(device, &st) < 0)
                         return log_error_errno(errno, "Failed to stat %s: %m", device);
@@ -349,7 +338,9 @@ static int run(int argc, char *argv[]) {
                 }
         }
 
-        if (arg_show_progress &&
+        console = fopen("/dev/console", "we");
+        if (console &&
+            arg_show_progress &&
             pipe(progress_pipe) < 0)
                 return log_error_errno(errno, "pipe(): %m");
 
@@ -408,13 +399,15 @@ static int run(int argc, char *argv[]) {
                 _exit(FSCK_OPERATIONAL_ERROR);
         }
 
-        progress_pipe[1] = safe_close(progress_pipe[1]);
-        (void) process_progress(TAKE_FD(progress_pipe[0]));
+        if (console) {
+                progress_pipe[1] = safe_close(progress_pipe[1]);
+                (void) process_progress(TAKE_FD(progress_pipe[0]), console);
+        }
 
         exit_status = wait_for_terminate_and_check("fsck", pid, WAIT_LOG_ABNORMAL);
         if (exit_status < 0)
                 return exit_status;
-        if (exit_status & ~1) {
+        if ((exit_status & ~FSCK_ERROR_CORRECTED) != FSCK_SUCCESS) {
                 log_error("fsck failed with exit status %i.", exit_status);
 
                 if ((exit_status & FSCK_SYSTEM_SHOULD_REBOOT) && root_directory) {