mount: rework find_loop_device() to log about no errors
authorLennart Poettering <lennart@poettering.net>
Mon, 10 Jul 2017 19:39:23 +0000 (21:39 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 10 Jul 2017 19:39:23 +0000 (21:39 +0200)
We should either log about all errors in a function, or about none (and
then leave the logging about it to the caller who we propagate the error
to). Given that the callers of find_loop_device() already log about the
returned errors let's hence suppress the log messages in
find_loop_device() itself.

src/mount/mount-tool.c

index 9d56b40..21c3b13 100644 (file)
@@ -759,11 +759,8 @@ static int find_loop_device(const char *backing_file, char **loop_dev) {
         assert(loop_dev);
 
         d = opendir("/sys/devices/virtual/block");
-        if (!d) {
-                if (errno == ENOENT)
-                        return -ENOENT;
-                return log_error_errno(errno, "Can't open directory /sys/devices/virtual/block: %m");
-        }
+        if (!d)
+                return -errno;
 
         FOREACH_DIRENT(de, d, return -errno) {
                 _cleanup_free_ char *sys = NULL, *fname = NULL;
@@ -779,7 +776,7 @@ static int find_loop_device(const char *backing_file, char **loop_dev) {
 
                 sys = strjoin("/sys/devices/virtual/block/", de->d_name, "/loop/backing_file");
                 if (!sys)
-                        return log_oom();
+                        return -ENOMEM;
 
                 r = read_one_line_file(sys, &fname);
                 if (r < 0)
@@ -790,7 +787,7 @@ static int find_loop_device(const char *backing_file, char **loop_dev) {
 
                 l = strjoin("/dev/", de->d_name);
                 if (!l)
-                        return log_oom();
+                        return -ENOMEM;
 
                 break;
         }