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@xxxxxxx> --- shlibs/uuid/src/gen_uuid.c | 35 +++++++++++++++++++++++++++++------ shlibs/uuid/src/uuid.h | 1 + shlibs/uuid/src/uuid.sym | 10 +++++++++- 3 files changed, 39 insertions(+), 7 deletions(-) diff --git a/shlibs/uuid/src/gen_uuid.c b/shlibs/uuid/src/gen_uuid.c index 6bd1f1d..b47c13f 100644 --- a/shlibs/uuid/src/gen_uuid.c +++ b/shlibs/uuid/src/gen_uuid.c @@ -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); } diff --git a/shlibs/uuid/src/uuid.h b/shlibs/uuid/src/uuid.h index e329bf7..874d65a 100644 --- a/shlibs/uuid/src/uuid.h +++ b/shlibs/uuid/src/uuid.h @@ -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); diff --git a/shlibs/uuid/src/uuid.sym b/shlibs/uuid/src/uuid.sym index eb57c33..d859ca7 100644 --- a/shlibs/uuid/src/uuid.sym +++ b/shlibs/uuid/src/uuid.sym @@ -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; -- 1.7.1 -- To unsubscribe from this list: send the line "unsubscribe util-linux" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html