]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libuuid: introduce uuid_generate_time_safe()
authorPetr Uzel <petr.uzel@suse.cz>
Mon, 14 Feb 2011 13:43:29 +0000 (14:43 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 16 Feb 2011 15:07:16 +0000 (16:07 +0100)
The problem with libuuid interface is that it is impossible to
inform the caller of uuid_generate_time() if the UUID was generated
in a safe manner (either via uuidd, or using the global clock state
counter).

This patch introduces new function,

int uuid_generate_time_safe(uuid_t out)

which can report whether the generated UUID is safe.

Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
shlibs/uuid/src/gen_uuid.c
shlibs/uuid/src/uuid.h
shlibs/uuid/src/uuid.sym

index 6bd1f1df3d27419bc6348c76f36329c415cfd269..b47c13f6c18631cb464aa717087e942992c2a084 100644 (file)
@@ -595,8 +595,15 @@ int __uuid_generate_time(uuid_t out, int *num)
        return ret;
 }
 
-void uuid_generate_time(uuid_t out)
-{
+/*
+ * Generate time-based UUID and store it to @out
+ *
+ * Tries to guarantee uniqueness of the generated UUIDs by obtaining them from the uuidd daemon,
+ * or, if uuidd is not usable, by using the global clock state counter (see get_clock()).
+ * If neither of these is possible (e.g. because of insufficient permissions), it generates
+ * the UUID anyway, but returns -1. Otherwise, returns 0.
+ */
+static int uuid_generate_time_generic(uuid_t out) {
 #ifdef HAVE_TLS
        THREAD_LOCAL int                num = 0;
        THREAD_LOCAL struct uuid        uu;
@@ -615,7 +622,7 @@ void uuid_generate_time(uuid_t out)
                        last_time = time(0);
                        uuid_unpack(out, &uu);
                        num--;
-                       return;
+                       return 0;
                }
                num = 0;
        }
@@ -628,14 +635,30 @@ void uuid_generate_time(uuid_t out)
                }
                num--;
                uuid_pack(&uu, out);
-               return;
+               return 0;
        }
 #else
        if (get_uuid_via_daemon(UUIDD_OP_TIME_UUID, out, 0) == 0)
-               return;
+               return 0;
 #endif
 
-       __uuid_generate_time(out, 0);
+       return __uuid_generate_time(out, 0);
+}
+
+/*
+ * Generate time-based UUID and store it to @out.
+ *
+ * Discards return value from uuid_generate_time_generic()
+ */
+void uuid_generate_time(uuid_t out)
+{
+       (void)uuid_generate_time_generic(out);
+}
+
+
+int uuid_generate_time_safe(uuid_t out)
+{
+       return uuid_generate_time_generic(out);
 }
 
 
index e329bf7a711118bef71b4c2dc8ac5c468fa3f69b..874d65a196dc673b8b780e8eafdfd4bfd50c4b30 100644 (file)
@@ -79,6 +79,7 @@ void uuid_copy(uuid_t dst, const uuid_t src);
 void uuid_generate(uuid_t out);
 void uuid_generate_random(uuid_t out);
 void uuid_generate_time(uuid_t out);
+int uuid_generate_time_safe(uuid_t out);
 
 /* isnull.c */
 int uuid_is_null(const uuid_t uu);
index eb57c33e6607bdf55563ec0f102a8e10c1098048..d859ca7266cf73ccd2051927d7203b36e25c0a8c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * The symbol versioning ensures that a new application requiring symbol foo()
- * can't run with old libblkid.so not providing foo() - the global SONAME
+ * can't run with old libuuid.so not providing foo() - the global SONAME
  * version info can't enforce this since we never change the SONAME.
  *
  * The original libuuid from e2fsprogs (<=1.41.5) does not to use
@@ -31,3 +31,11 @@ global:
 local:
        *;
 };
+
+/*
+ * version(s) since util-linux 2.20
+ */
+UUID_2.20 {
+global:
+       uuid_generate_time_safe;
+} UUID_1.0;