chiark / gitweb /
fstab-generator: avoid mangling of mount source string
[elogind.git] / src / fstab-generator / fstab-generator.c
index 86cbc45..d9ba3e3 100644 (file)
@@ -117,6 +117,7 @@ static int add_swap(const char *what, struct mntent *me) {
 
         fputs("# Automatically generated by systemd-fstab-generator\n\n"
               "[Unit]\n"
+              "SourcePath=/etc/fstab\n"
               "DefaultDependencies=no\n"
               "Conflicts=" SPECIAL_UMOUNT_TARGET "\n"
               "Before=" SPECIAL_UMOUNT_TARGET "\n", f);
@@ -150,7 +151,7 @@ static int add_swap(const char *what, struct mntent *me) {
                         goto finish;
                 }
 
-                mkdir_parents(lnk, 0755);
+                mkdir_parents_label(lnk, 0755);
                 if (symlink(unit, lnk) < 0) {
                         log_error("Failed to create symlink: %m");
                         r = -errno;
@@ -173,7 +174,7 @@ static int add_swap(const char *what, struct mntent *me) {
                                 goto finish;
                         }
 
-                        mkdir_parents(lnk, 0755);
+                        mkdir_parents_label(lnk, 0755);
                         if (symlink(unit, lnk) < 0) {
                                 log_error("Failed to create symlink: %m");
                                 r = -errno;
@@ -274,6 +275,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
 
         fputs("# Automatically generated by systemd-fstab-generator\n\n"
               "[Unit]\n"
+              "SourcePath=/etc/fstab\n"
               "DefaultDependencies=no\n", f);
 
         if (!path_equal(where, "/"))
@@ -324,7 +326,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
                         goto finish;
                 }
 
-                mkdir_parents(lnk, 0755);
+                mkdir_parents_label(lnk, 0755);
                 if (symlink(unit, lnk) < 0) {
                         log_error("Failed to create symlink: %m");
                         r = -errno;
@@ -350,7 +352,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
                                         goto finish;
                                 }
 
-                                mkdir_parents(lnk, 0755);
+                                mkdir_parents_label(lnk, 0755);
                                 if (symlink(unit, lnk) < 0) {
                                         log_error("Failed to creat symlink: %m");
                                         r = -errno;
@@ -386,6 +388,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
                 fprintf(f,
                         "# Automatically generated by systemd-fstab-generator\n\n"
                         "[Unit]\n"
+                        "SourcePath=/etc/fstab\n"
                         "DefaultDependencies=no\n"
                         "Conflicts=" SPECIAL_UMOUNT_TARGET "\n"
                         "Before=" SPECIAL_UMOUNT_TARGET " %s\n"
@@ -410,7 +413,7 @@ static int add_mount(const char *what, const char *where, struct mntent *me) {
                         goto finish;
                 }
 
-                mkdir_parents(lnk, 0755);
+                mkdir_parents_label(lnk, 0755);
                 if (symlink(automount_unit, lnk) < 0) {
                         log_error("Failed to create symlink: %m");
                         r = -errno;
@@ -467,9 +470,6 @@ static int parse_fstab(void) {
                         goto finish;
                 }
 
-                if (is_path(what))
-                        path_kill_slashes(what);
-
                 if (is_path(where))
                         path_kill_slashes(where);
 
@@ -495,8 +495,8 @@ finish:
 int main(int argc, char *argv[]) {
         int r;
 
-        if (argc > 2) {
-                log_error("This program takes one or no arguments.");
+        if (argc > 1 && argc != 4) {
+                log_error("This program takes three or no arguments.");
                 return EXIT_FAILURE;
         }
 
@@ -507,8 +507,6 @@ int main(int argc, char *argv[]) {
         log_parse_environment();
         log_open();
 
-        log_set_max_level(LOG_DEBUG);
-
         umask(0022);
 
         r = parse_fstab();