chiark / gitweb /
manager: parse RD_TIMESTAMP passed from initrd
[elogind.git] / src / util.c
index 9a82c71dcb249b1e268f8959385fecbc05782f59..f41861b64eda1db93d0a50cb7cfb710f206027db 100644 (file)
@@ -3552,10 +3552,9 @@ void dual_timestamp_serialize(FILE *f, const char *name, dual_timestamp *t) {
                 (unsigned long long) t->monotonic);
 }
 
-void dual_timestamp_deserialize(FILE *f, const char *value, dual_timestamp *t) {
+void dual_timestamp_deserialize(const char *value, dual_timestamp *t) {
         unsigned long long a, b;
 
-        assert(f);
         assert(value);
         assert(t);
 
@@ -3567,6 +3566,74 @@ void dual_timestamp_deserialize(FILE *f, const char *value, dual_timestamp *t) {
         }
 }
 
+char *fstab_node_to_udev_node(const char *p) {
+        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;
+        }
+
+        if (startswith(p, "UUID=")) {
+
+                if (!(u = unquote(p+5, "\"\'")))
+                        return NULL;
+
+                t = xescape(u, "/ ");
+                free(u);
+
+                if (!t)
+                        return NULL;
+
+                r = asprintf(&dn, "/dev/disk/by-uuid/%s", ascii_strlower(t));
+                free(t);
+
+                if (r < 0)
+                        return NULL;
+
+                return dn;
+        }
+
+        return strdup(p);
+}
+
+void filter_environ(const char *prefix) {
+        int i, j;
+        assert(prefix);
+
+        if (!environ)
+                return;
+
+        for (i = 0, j = 0; environ[i]; i++) {
+
+                if (startswith(environ[i], prefix))
+                        continue;
+
+                environ[j++] = environ[i];
+        }
+
+        environ[j] = NULL;
+}
+
 static const char *const ioprio_class_table[] = {
         [IOPRIO_CLASS_NONE] = "none",
         [IOPRIO_CLASS_RT] = "realtime",