chiark / gitweb /
fstab-generator: make error more helpful in case of duplicates in fstab
[elogind.git] / src / fstab-generator / fstab-generator.c
index 251a346c4d131a2c6ab81d18bd2fac7400d423fd..ba55f2c2b73d0ce09bbd59232b4cbbe54c94e998 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: %m");
+                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;
         }
 
@@ -138,7 +141,7 @@ static int add_swap(const char *what, struct mntent *me) {
 
         fflush(f);
         if (ferror(f)) {
-                log_error("Failed to write unit file: %m");
+                log_error("Failed to write unit file %s: %m", unit);
                 r = -errno;
                 goto finish;
         }
@@ -152,7 +155,7 @@ static int add_swap(const char *what, struct mntent *me) {
 
                 mkdir_parents_label(lnk, 0755);
                 if (symlink(unit, lnk) < 0) {
-                        log_error("Failed to create symlink: %m");
+                        log_error("Failed to create symlink %s: %m", lnk);
                         r = -errno;
                         goto finish;
                 }
@@ -171,7 +174,7 @@ static int add_swap(const char *what, struct mntent *me) {
 
                         mkdir_parents_label(lnk, 0755);
                         if (symlink(unit, lnk) < 0) {
-                                log_error("Failed to create symlink: %m");
+                                log_error("Failed to create symlink %s: %m", lnk);
                                 r = -errno;
                                 goto finish;
                         }
@@ -191,14 +194,6 @@ finish:
         return r;
 }
 
-static bool mount_is_bind(struct mntent *me) {
-        assert(me);
-
-        return
-                hasmntopt(me, "bind") ||
-                streq(me->mnt_opts, "bind");
-}
-
 static bool mount_is_network(struct mntent *me) {
         assert(me);
 
@@ -231,7 +226,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
                 return 0;
 
         isnetwork = mount_is_network(me);
-        isbind = mount_is_bind(me);
+        isbind = !!hasmntopt(me, "bind");
 
         noauto = !!hasmntopt(me, "noauto");
         nofail = !!hasmntopt(me, "nofail");
@@ -262,7 +257,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: %m");
+                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;
         }
 
@@ -306,7 +304,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
 
         fflush(f);
         if (ferror(f)) {
-                log_error("Failed to write unit file: %m");
+                log_error("Failed to write unit file %s: %m", unit);
                 r = -errno;
                 goto finish;
         }
@@ -320,7 +318,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
 
                 mkdir_parents_label(lnk, 0755);
                 if (symlink(unit, lnk) < 0) {
-                        log_error("Failed to create symlink: %m");
+                        log_error("Failed to create symlink %s: %m", lnk);
                         r = -errno;
                         goto finish;
                 }
@@ -342,7 +340,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
 
                                 mkdir_parents_label(lnk, 0755);
                                 if (symlink(unit, lnk) < 0) {
-                                        log_error("Failed to create symlink: %m");
+                                        log_error("Failed to create symlink %s: %m", lnk);
                                         r = -errno;
                                         goto finish;
                                 }
@@ -367,7 +365,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
                 f = fopen(automount_unit, "wxe");
                 if (!f) {
                         r = -errno;
-                        log_error("Failed to create unit file: %m");
+                        log_error("Failed to create unit file %s: %m", automount_unit);
                         goto finish;
                 }
 
@@ -386,7 +384,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
 
                 fflush(f);
                 if (ferror(f)) {
-                        log_error("Failed to write unit file: %m");
+                        log_error("Failed to write unit file %s: %m", automount_unit);
                         r = -errno;
                         goto finish;
                 }
@@ -400,7 +398,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
 
                 mkdir_parents_label(lnk, 0755);
                 if (symlink(automount_unit, lnk) < 0) {
-                        log_error("Failed to create symlink: %m");
+                        log_error("Failed to create symlink %s: %m", lnk);
                         r = -errno;
                         goto finish;
                 }