From 7e50e956e4e84bc668335a926e2ba44659be1088 Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Tue, 21 Feb 2012 09:56:27 -0500 Subject: [PATCH] Create libuuid/libc uuid wrapper commit 19d8b1b3cecac9a52cf8e0e381854703c141ec5e upstream. Signed-off-by: Mathieu Desnoyers Signed-off-by: Christian Babeux --- configure.ac | 4 ++ include/lttng/ust-events.h | 7 +-- liblttng-ust/Makefile.am | 11 +++- liblttng-ust/clock.h | 12 ++--- liblttng-ust/ltt-events.c | 11 ++-- liblttng-ust/ltt-ring-buffer-client.h | 3 +- .../ltt-ring-buffer-metadata-client.h | 2 +- liblttng-ust/uuid.h | 54 +++++++++++++++++++ 8 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 liblttng-ust/uuid.h diff --git a/configure.ac b/configure.ac index de1c0c5f..511da2e9 100644 --- a/configure.ac +++ b/configure.ac @@ -80,18 +80,22 @@ AC_CHECK_LIB([pthread], [pthread_create]) AC_CHECK_LIB([uuid], [uuid_generate], [ AC_DEFINE_UNQUOTED([LTTNG_UST_HAVE_LIBUUID], 1, [Has libuuid support.]) + have_libuuid=yes ], [ # libuuid not found, check for uuid_create in libc. AC_CHECK_LIB([c], [uuid_create], [ AC_DEFINE_UNQUOTED([LTTNG_UST_HAVE_LIBC_UUID], 1, [Has libc uuid support.]) + have_libc_uuid=yes ], [ AC_MSG_ERROR([Cannot find libuuid uuid_generate nor libc uuid_create. Use [LDFLAGS]=-Ldir to specify its location.]) ]) ] ) +AM_CONDITIONAL([LTTNG_UST_BUILD_WITH_LIBUUID], [test "x$have_libuuid" = "xyes"]) +AM_CONDITIONAL([LTTNG_UST_BUILD_WITH_LIBC_UUID], [test "x$have_libc_uuid" = "xyes"]) # Checks for header files. #AC_CHECK_HEADERS([fcntl.h stdint.h stdlib.h string.h sys/socket.h sys/time.h unistd.h]) diff --git a/include/lttng/ust-events.h b/include/lttng/ust-events.h index 251c0fb6..1a548f1a 100644 --- a/include/lttng/ust-events.h +++ b/include/lttng/ust-events.h @@ -21,13 +21,14 @@ #include #include -#include #include #include #include #include #include +#define LTTNG_UST_UUID_LEN 16 + struct ltt_channel; struct ltt_session; struct lttng_ust_lib_ring_buffer_ctx; @@ -355,7 +356,7 @@ struct ltt_channel { /* Channel ID, available for consumer too */ unsigned int id; /* Copy of session UUID for consumer (availability through shm) */ - uuid_t uuid; /* Trace session unique ID */ + unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */ }; struct ltt_session { @@ -368,7 +369,7 @@ struct ltt_session { struct cds_list_head wildcards; /* Wildcard list head */ struct cds_list_head list; /* Session list */ unsigned int free_chan_id; /* Next chan ID to allocate */ - uuid_t uuid; /* Trace session unique ID */ + unsigned char uuid[LTTNG_UST_UUID_LEN]; /* Trace session unique ID */ unsigned int metadata_dumped:1; }; diff --git a/liblttng-ust/Makefile.am b/liblttng-ust/Makefile.am index 04b9ff3f..16070d59 100644 --- a/liblttng-ust/Makefile.am +++ b/liblttng-ust/Makefile.am @@ -33,7 +33,8 @@ liblttng_ust_runtime_la_SOURCES = \ compat.h \ wait.h \ jhash.h \ - error.h + error.h \ + uuid.h liblttng_ust_support_la_SOURCES = \ ltt-tracer.h \ @@ -55,10 +56,16 @@ liblttng_ust_support_la_LIBADD = \ liblttng_ust_la_LIBADD = \ -lpthread \ -lrt \ - -luuid \ -llttng-ust-tracepoint \ $(top_builddir)/snprintf/libustsnprintf.la \ $(top_builddir)/liblttng-ust-comm/liblttng-ust-comm.la \ liblttng-ust-runtime.la liblttng-ust-support.la +if LTTNG_UST_BUILD_WITH_LIBUUID +liblttng_ust_la_LIBADD += -luuid +endif +if LTTNG_UST_BUILD_WITH_LIBC_UUID +liblttng_ust_la_LIBADD += -lc +endif + liblttng_ust_la_CFLAGS = -DUST_COMPONENT="liblttng_ust" -fno-strict-aliasing diff --git a/liblttng-ust/clock.h b/liblttng-ust/clock.h index 82a7b45c..b4d17e78 100644 --- a/liblttng-ust/clock.h +++ b/liblttng-ust/clock.h @@ -25,11 +25,7 @@ #include #include #include - -/* - * Includes final \0. - */ -#define CLOCK_UUID_LEN 37 +#include "uuid.h" /* TRACE CLOCK */ @@ -71,12 +67,12 @@ const int trace_clock_uuid(char *uuid) if (!fp) { return -ENOENT; } - len = fread(uuid, 1, CLOCK_UUID_LEN - 1, fp); - if (len < CLOCK_UUID_LEN - 1) { + len = fread(uuid, 1, LTTNG_UST_UUID_STR_LEN - 1, fp); + if (len < LTTNG_UST_UUID_STR_LEN - 1) { ret = -EINVAL; goto end; } - uuid[CLOCK_UUID_LEN - 1] = '\0'; + uuid[LTTNG_UST_UUID_STR_LEN - 1] = '\0'; end: fclose(fp); return ret; diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index 5a624c49..627acfec 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -48,6 +47,7 @@ #include #include "error.h" #include "compat.h" +#include "uuid.h" #include "tracepoint-internal.h" #include "ltt-tracer.h" @@ -308,6 +308,7 @@ void synchronize_trace(void) struct ltt_session *ltt_session_create(void) { struct ltt_session *session; + int ret; session = zmalloc(sizeof(struct ltt_session)); if (!session) @@ -315,7 +316,10 @@ struct ltt_session *ltt_session_create(void) CDS_INIT_LIST_HEAD(&session->chan); CDS_INIT_LIST_HEAD(&session->events); CDS_INIT_LIST_HEAD(&session->wildcards); - uuid_generate(session->uuid); + ret = lttng_ust_uuid_generate(session->uuid); + if (ret != 0) { + session->uuid[0] = '\0'; + } cds_list_add(&session->list, &sessions); return session; } @@ -1100,7 +1104,8 @@ static int _ltt_session_metadata_statedump(struct ltt_session *session) { unsigned char *uuid_c = session->uuid; - char uuid_s[37], clock_uuid_s[CLOCK_UUID_LEN]; + char uuid_s[LTTNG_UST_UUID_STR_LEN], + clock_uuid_s[LTTNG_UST_UUID_STR_LEN]; struct ltt_channel *chan; struct ltt_event *event; int ret = 0; diff --git a/liblttng-ust/ltt-ring-buffer-client.h b/liblttng-ust/ltt-ring-buffer-client.h index d64af555..7b6827ff 100644 --- a/liblttng-ust/ltt-ring-buffer-client.h +++ b/liblttng-ust/ltt-ring-buffer-client.h @@ -24,6 +24,7 @@ #include #include "lttng/bitfield.h" #include "clock.h" +#include "uuid.h" #include "ltt-tracer.h" #include "../libringbuffer/frontend_types.h" @@ -43,7 +44,7 @@ struct packet_header { * Trace magic number. * contains endianness information. */ - uint8_t uuid[16]; + uint8_t uuid[LTTNG_UST_UUID_LEN]; uint32_t stream_id; struct { diff --git a/liblttng-ust/ltt-ring-buffer-metadata-client.h b/liblttng-ust/ltt-ring-buffer-metadata-client.h index 1e18df9d..acc56fdd 100644 --- a/liblttng-ust/ltt-ring-buffer-metadata-client.h +++ b/liblttng-ust/ltt-ring-buffer-metadata-client.h @@ -28,7 +28,7 @@ struct metadata_packet_header { uint32_t magic; /* 0x75D11D57 */ - uint8_t uuid[16]; /* Unique Universal Identifier */ + uint8_t uuid[LTTNG_UST_UUID_LEN]; /* Unique Universal Identifier */ uint32_t checksum; /* 0 if unused */ uint32_t content_size; /* in bits */ uint32_t packet_size; /* in bits */ diff --git a/liblttng-ust/uuid.h b/liblttng-ust/uuid.h new file mode 100644 index 00000000..1027acbe --- /dev/null +++ b/liblttng-ust/uuid.h @@ -0,0 +1,54 @@ +#ifndef _LTTNG_UST_UUID_H +#define _LTTNG_UST_UUID_H + +/* + * Copyright (C) 2011 Mathieu Desnoyers + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + */ + +#include +#include /* For LTTNG_UST_UUID_LEN */ +/* + * Includes final \0. + */ +#define LTTNG_UST_UUID_STR_LEN 37 + +#include + +#ifdef LTTNG_UST_HAVE_LIBUUID +static inline +int lttng_ust_uuid_generate(unsigned char *uuid_out) +{ + uuid_generate(uuid_out); + return 0; +} + +#elif defined(LTTNG_UST_HAVE_LIBC_UUID) +#include +#include + +static inline +int lttng_ust_uuid_generate(unsigned char *uuid_out) +{ + uint32_t status; + + uuid_create(uuid_out, &status); + if (status == uuid_s_ok) + return 0; + else + return -1; +} + +#else +#error "LTTng-UST needs to have a UUID generator configured." +#endif + +#endif /* _LTTNG_UST_UUID_H */ -- 2.34.1