starfry

systemd patch for fstab overmounting

Jan 3rd, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.67 KB | None | 0 0
  1. --- systemd-org/src/fstab-generator/fstab-generator.c   2013-01-03 14:07:16.729253290 +0000
  2. +++ systemd-pat/src/fstab-generator/fstab-generator.c   2013-01-03 14:01:01.532488521 +0000
  3. @@ -214,6 +214,8 @@
  4.                       int passno, bool wait, bool noauto, bool nofail, bool automount, bool isbind, bool isnetwork,
  5.                       const char *source) {
  6.          char *name = NULL, *unit = NULL, *lnk = NULL, *device = NULL, *automount_name = NULL, *automount_unit = NULL;
  7. +       char uniq_suffix[10] = ".mount";
  8. +        int uniq_num = 0;
  9.          FILE *f = NULL;
  10.          int r;
  11.          const char *post, *pre;
  12. @@ -244,27 +246,35 @@
  13.                  pre = SPECIAL_LOCAL_FS_PRE_TARGET;
  14.          }  
  15.  
  16. -        name = unit_name_from_path(where, ".mount");
  17. -        if (!name) {
  18. -                r = log_oom();
  19. -                goto finish;
  20. -        }
  21. -
  22. -        unit = strjoin(arg_dest, "/", name, NULL);
  23. -        if (!unit) {
  24. -                r = log_oom();
  25. -                goto finish;
  26. -        }
  27. +        do {
  28.  
  29. -        f = fopen(unit, "wxe");
  30. -        if (!f) {
  31. -                r = -errno;
  32. -                if (errno == EEXIST)
  33. -                        log_error("Failed to create mount unit file %s, as it already exists. Duplicate entry in /etc/fstab?", unit);
  34. -                else
  35. -                        log_error("Failed to create unit file %s: %m", unit);
  36. -                goto finish;
  37. -        }
  38. +                name = unit_name_from_path(where, uniq_suffix);
  39. +                if (!name) {
  40. +                        r = log_oom();
  41. +                        goto finish;
  42. +                }
  43. +
  44. +                unit = strjoin(arg_dest, "/", name, NULL);
  45. +                if (!unit) {
  46. +                        r = log_oom();
  47. +                        goto finish;
  48. +                }
  49. +
  50. +                f = fopen(unit, "wxe");
  51. +                if (!f) {
  52. +                        r = -errno;
  53. +                        if (errno == EEXIST)
  54. +                        {
  55. +                                snprintf(uniq_suffix, 10, "_%d.mount", uniq_num++);
  56. +                                log_warning("Failed to create mount unit file %s because it already exists (overmount entry in /etc/fstab?). Will retry with suffix %s", unit, uniq_suffix);
  57. +                        }
  58. +                        else
  59. +                        {
  60. +                                log_error("Failed to create unit file %s: %m", unit);
  61. +                                goto finish;
  62. +                        }
  63. +                }
  64. +        } while (!f);
  65.  
  66.          fprintf(f,
  67.                "# Automatically generated by systemd-fstab-generator\n\n"
  68. --- systemd-org/src/core/mount.c        2012-10-23 00:53:02.708658801 +0100
  69. +++ systemd-pat/src/core/mount.c        2013-01-03 14:01:39.545830761 +0000
  70. @@ -506,6 +506,9 @@
  71.  static int mount_verify(Mount *m) {
  72.          bool b;
  73.          char *e;
  74. +       char *ext, *suf;
  75. +       int name_len;
  76. +       char cm[strlen(UNIT(m)->id)];
  77.          assert(m);
  78.  
  79.          if (UNIT(m)->load_state != UNIT_LOADED)
  80. @@ -517,7 +520,15 @@
  81.          if (!(e = unit_name_from_path(m->where, ".mount")))
  82.                  return -ENOMEM;
  83.  
  84. -        b = unit_has_name(UNIT(m), e);
  85. +       /* clean mount file name with any overmount suffix removed */
  86. +       ext = strrchr(UNIT(m)->id,'.');
  87. +       suf = strrchr(UNIT(m)->id,'_');
  88. +       name_len = (suf ? suf : ext ) - UNIT(m)->id;
  89. +        strncpy(cm,UNIT(m)->id, name_len);
  90. +        strcpy(cm + name_len, ext);
  91. +       log_debug("clean mount file name (with any overmount suffix removed): %s", cm);
  92. +
  93. +        b = unit_has_name(UNIT(m), e) || !strcmp(e,cm);
  94.          free(e);
  95.  
  96.          if (!b) {
Advertisement
Add Comment
Please, Sign In to add comment