chiark / gitweb /
fstab-generator: properly detect bind mounts
[elogind.git] / src / fstab-generator / fstab-generator.c
index 7b3bf11eda1ff3319bc00b04331f1a33dfc8c88e..23e5051925429ed48fa5adbf0dcbdec2849641ae 100644 (file)
@@ -111,7 +111,10 @@ static int add_swap(const char *what, struct mntent *me) {
         f = fopen(unit, "wxe");
         if (!f) {
                 r = -errno;
-                log_error("Failed to create unit file %s: %m", unit);
+                if (errno == EEXIST)
+                        log_error("Failed to create swap unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
+                else
+                        log_error("Failed to create unit file %s: %m", unit);
                 goto finish;
         }
 
@@ -191,6 +194,14 @@ finish:
         return r;
 }
 
+static bool mount_is_bind(struct mntent *me) {
+        assert(me);
+
+        return
+                hasmntopt(me, "bind") ||
+                streq(me->mnt_type, "bind");
+}
+
 static bool mount_is_network(struct mntent *me) {
         assert(me);
 
@@ -223,7 +234,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
                 return 0;
 
         isnetwork = mount_is_network(me);
-        isbind = !!hasmntopt(me, "bind");
+        isbind = mount_is_bind(me);
 
         noauto = !!hasmntopt(me, "noauto");
         nofail = !!hasmntopt(me, "nofail");
@@ -254,7 +265,10 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
         f = fopen(unit, "wxe");
         if (!f) {
                 r = -errno;
-                log_error("Failed to create unit file %s: %m", unit);
+                if (errno == EEXIST)
+                        log_error("Failed to create mount unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
+                else
+                        log_error("Failed to create unit file %s: %m", unit);
                 goto finish;
         }