summaryrefslogtreecommitdiff
path: root/src/shared/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/util.c')
-rw-r--r--src/shared/util.c52
1 files changed, 19 insertions, 33 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index 736cb15a5f..d94bc695c8 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -4126,52 +4126,38 @@ void dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
}
}
-char *fstab_node_to_udev_node(const char *p) {
+static char *tag_to_udev_node(const char *tagvalue, const char *by) {
char *dn, *t, *u;
int r;
/* FIXME: to follow udev's logic 100% we need to leave valid
* UTF8 chars unescaped */
- if (startswith(p, "LABEL=")) {
-
- if (!(u = unquote(p+6, "\"\'")))
- return NULL;
-
- t = xescape(u, "/ ");
- free(u);
-
- if (!t)
- return NULL;
-
- r = asprintf(&dn, "/dev/disk/by-label/%s", t);
- free(t);
-
- if (r < 0)
- return NULL;
-
- return dn;
- }
+ u = unquote(tagvalue, "\"\'");
+ if (u == NULL)
+ return NULL;
- if (startswith(p, "UUID=")) {
+ t = xescape(u, "/ ");
+ free(u);
- if (!(u = unquote(p+5, "\"\'")))
- return NULL;
+ if (t == NULL)
+ return NULL;
- t = xescape(u, "/ ");
- free(u);
+ r = asprintf(&dn, "/dev/disk/by-%s/%s", by, t);
+ free(t);
- if (!t)
- return NULL;
+ if (r < 0)
+ return NULL;
- r = asprintf(&dn, "/dev/disk/by-uuid/%s", t);
- free(t);
+ return dn;
+}
- if (r < 0)
- return NULL;
+char *fstab_node_to_udev_node(const char *p) {
+ if (startswith(p, "LABEL="))
+ return tag_to_udev_node(p+6, "label");
- return dn;
- }
+ if (startswith(p, "UUID="))
+ return tag_to_udev_node(p+5, "uuid");
return strdup(p);
}