chiark / gitweb /
core/mount: modernize style
[elogind.git] / src / core / mount.c
index 09a5d286d36549870c6f97c243d21a59cdec5677..7cadd9fcb44a29430e23574a418a9e289bd5026a 100644 (file)
@@ -30,6 +30,7 @@
 #include "load-fragment.h"
 #include "load-dropin.h"
 #include "log.h"
+#include "sd-messages.h"
 #include "strv.h"
 #include "mkdir.h"
 #include "path-util.h"
@@ -221,9 +222,11 @@ static int mount_add_swap_links(Mount *m) {
 
         assert(m);
 
-        LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_SWAP])
-                if ((r = swap_add_one_mount_link(SWAP(other), m)) < 0)
+        LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_SWAP]) {
+                r = swap_add_one_mount_link(SWAP(other), m);
+                if (r < 0)
                         return r;
+        }
 
         return 0;
 }
@@ -234,9 +237,11 @@ static int mount_add_path_links(Mount *m) {
 
         assert(m);
 
-        LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_PATH])
-                if ((r = path_add_one_mount_link(PATH(other), m)) < 0)
+        LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_PATH]) {
+                r = path_add_one_mount_link(PATH(other), m);
+                if (r < 0)
                         return r;
+        }
 
         return 0;
 }
@@ -247,9 +252,11 @@ static int mount_add_automount_links(Mount *m) {
 
         assert(m);
 
-        LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_AUTOMOUNT])
-                if ((r = automount_add_one_mount_link(AUTOMOUNT(other), m)) < 0)
+        LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_AUTOMOUNT]) {
+                r = automount_add_one_mount_link(AUTOMOUNT(other), m);
+                if (r < 0)
                         return r;
+        }
 
         return 0;
 }
@@ -260,9 +267,11 @@ static int mount_add_socket_links(Mount *m) {
 
         assert(m);
 
-        LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_SOCKET])
-                if ((r = socket_add_one_mount_link(SOCKET(other), m)) < 0)
+        LIST_FOREACH(units_by_type, other, UNIT(m)->manager->units_by_type[UNIT_SOCKET]) {
+                r = socket_add_one_mount_link(SOCKET(other), m);
+                if (r < 0)
                         return r;
+        }
 
         return 0;
 }
@@ -927,6 +936,18 @@ fail:
                 set_free(pid_set);
 }
 
+void warn_if_dir_nonempty(const char *unit, const char* where) {
+        if (dir_is_empty(where) > 0)
+                return;
+        log_struct(LOG_NOTICE,
+                   "MESSAGE=%s: Directory %s to mount over is not empty, mounting anyway.",
+                   unit, where,
+                   "WHERE=%s", where,
+                   "_SYSTEMD_UNIT=%s", unit,
+                   MESSAGE_ID(SD_MESSAGE_OVERMOUNTING),
+                   NULL);
+}
+
 static void mount_enter_unmounting(Mount *m) {
         int r;
 
@@ -967,8 +988,7 @@ static void mount_enter_mounting(Mount *m) {
 
         mkdir_p_label(m->where, m->directory_mode);
 
-        if (dir_is_empty(m->where) <= 0)
-                log_notice("%s: Directory %s to mount over is not empty, mounting anyway. (To see the over-mounted files, please manually mount the underlying file system to a secondary location.)", m->meta.id, m->where);
+        warn_if_dir_nonempty(m->meta.id, m->where);
 
         /* Create the source directory for bind-mounts if needed */
         p = get_mount_parameters_fragment(m);
@@ -1658,7 +1678,8 @@ void mount_fd_event(Manager *m, int events) {
          * /proc/self/mountinfo file, which informs us about mounting
          * table changes */
 
-        if ((r = mount_load_proc_self_mountinfo(m, true)) < 0) {
+        r = mount_load_proc_self_mountinfo(m, true);
+        if (r < 0) {
                 log_error("Failed to reread /proc/self/mountinfo: %s", strerror(-r));
 
                 /* Reset flags, just in case, for later calls */