From 27b98e6c9ed3fbfc9ee84b56582892db3009b1b7 Mon Sep 17 00:00:00 2001 From: Michael Jeanson Date: Fri, 2 Apr 2021 20:52:58 -0400 Subject: [PATCH] Split and move compat.h to 'common/compat/' Move compat.h to 'src/common/compat/' and split it in specific compat headers. This is part of an effort to standardize our autotools setup across projects to simplify maintenance. Change-Id: Ic34ddc11acf81d0463d69e23986d83c29be9023b Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- src/common/Makefile.am | 3 + src/common/compat/errno.h | 16 ++++++ .../compat.h => common/compat/pthread.h} | 56 ++----------------- src/common/procname.h | 55 ++++++++++++++++++ src/common/ringbuffer/ring_buffer_frontend.c | 2 +- src/common/ustcomm.c | 2 +- src/liblttng-ust/Makefile.am | 1 - src/liblttng-ust/fd-tracker.c | 2 - src/liblttng-ust/lttng-context-procname.c | 2 +- src/liblttng-ust/lttng-events.c | 1 - src/liblttng-ust/lttng-tracer.h | 1 - src/liblttng-ust/lttng-ust-comm.c | 3 +- .../lttng-ust-statedump-provider.h | 1 - src/liblttng-ust/lttng-ust-statedump.c | 1 - tests/unit/pthread_name/pthread_name.c | 3 +- 15 files changed, 86 insertions(+), 63 deletions(-) create mode 100644 src/common/compat/errno.h rename src/{liblttng-ust/compat.h => common/compat/pthread.h} (71%) create mode 100644 src/common/procname.h diff --git a/src/common/Makefile.am b/src/common/Makefile.am index 1c6fcbf0..fa2a9da8 100644 --- a/src/common/Makefile.am +++ b/src/common/Makefile.am @@ -15,11 +15,14 @@ noinst_HEADERS = \ logging.h \ macros.h \ patient.h \ + procname.h \ safe-snprintf.h noinst_HEADERS += \ compat/dlfcn.h \ + compat/errno.h \ compat/mmap.h \ + compat/pthread.h \ compat/tid.h # These headers should be moved to the public headers when tested and diff --git a/src/common/compat/errno.h b/src/common/compat/errno.h new file mode 100644 index 00000000..c761d6e9 --- /dev/null +++ b/src/common/compat/errno.h @@ -0,0 +1,16 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2020 Michael Jeanson + */ + +#ifndef _UST_COMMON_COMPAT_ERRNO_H +#define _UST_COMMON_COMPAT_ERRNO_H + +#include + +#ifndef ENODATA +#define ENODATA ENOMSG +#endif + +#endif /* _UST_COMMON_COMPAT_ERRNO_H */ diff --git a/src/liblttng-ust/compat.h b/src/common/compat/pthread.h similarity index 71% rename from src/liblttng-ust/compat.h rename to src/common/compat/pthread.h index 7f0f5027..8779fa7e 100644 --- a/src/liblttng-ust/compat.h +++ b/src/common/compat/pthread.h @@ -6,22 +6,18 @@ * Copyright (C) 2020 Michael Jeanson */ -#ifndef _UST_COMPAT_H -#define _UST_COMPAT_H +#ifndef _UST_COMMON_COMPAT_PTHREAD_H +#define _UST_COMMON_COMPAT_PTHREAD_H #include #include -#include + +#include #ifdef __FreeBSD__ #include #endif -#include - -#define LTTNG_UST_PROCNAME_SUFFIX "-ust" - - #if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID) static inline int lttng_pthread_setname_np(const char *name) @@ -109,46 +105,4 @@ int lttng_pthread_getname_np(char *name, size_t len) #error "Please add pthread get name support for your OS." #endif -/* - * If a pthread setname/set_name function is available, declare - * the setustprocname() function that will add '-ust' to the end - * of the current process name, while truncating it if needed. - */ -static inline -int lttng_ust_setustprocname(void) -{ - int ret = 0, len; - char name[LTTNG_UST_ABI_PROCNAME_LEN]; - int limit = LTTNG_UST_ABI_PROCNAME_LEN - strlen(LTTNG_UST_PROCNAME_SUFFIX) - 1; - - /* - * Get the current thread name. - */ - ret = lttng_pthread_getname_np(name, LTTNG_UST_ABI_PROCNAME_LEN); - if (ret) { - goto error; - } - - len = strlen(name); - if (len > limit) { - len = limit; - } - - ret = sprintf(name + len, LTTNG_UST_PROCNAME_SUFFIX); - if (ret != strlen(LTTNG_UST_PROCNAME_SUFFIX)) { - goto error; - } - - ret = lttng_pthread_setname_np(name); - -error: - return ret; -} - -#include - -#ifndef ENODATA -#define ENODATA ENOMSG -#endif - -#endif /* _UST_COMPAT_H */ +#endif /* _UST_COMMON_COMPAT_PTHREAD_H */ diff --git a/src/common/procname.h b/src/common/procname.h new file mode 100644 index 00000000..061202ce --- /dev/null +++ b/src/common/procname.h @@ -0,0 +1,55 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2011 Mathieu Desnoyers + * Copyright (C) 2016 Raphaël Beamonte + * Copyright (C) 2020 Michael Jeanson + */ + +#ifndef _UST_COMMON_PROCNAME_H +#define _UST_COMMON_PROCNAME_H + +#include +#include + +#include "common/compat/pthread.h" + +#define LTTNG_UST_PROCNAME_SUFFIX "-ust" + +/* + * If a pthread setname/set_name function is available, declare + * the setustprocname() function that will add '-ust' to the end + * of the current process name, while truncating it if needed. + */ +static inline +int lttng_ust_setustprocname(void) +{ + int ret = 0, len; + char name[LTTNG_UST_ABI_PROCNAME_LEN]; + int limit = LTTNG_UST_ABI_PROCNAME_LEN - strlen(LTTNG_UST_PROCNAME_SUFFIX) - 1; + + /* + * Get the current thread name. + */ + ret = lttng_pthread_getname_np(name, LTTNG_UST_ABI_PROCNAME_LEN); + if (ret) { + goto error; + } + + len = strlen(name); + if (len > limit) { + len = limit; + } + + ret = sprintf(name + len, LTTNG_UST_PROCNAME_SUFFIX); + if (ret != strlen(LTTNG_UST_PROCNAME_SUFFIX)) { + goto error; + } + + ret = lttng_pthread_setname_np(name); + +error: + return ret; +} + +#endif /* _UST_COMMON_PROCNAME_H */ diff --git a/src/common/ringbuffer/ring_buffer_frontend.c b/src/common/ringbuffer/ring_buffer_frontend.c index 9074dbcb..d08fab75 100644 --- a/src/common/ringbuffer/ring_buffer_frontend.c +++ b/src/common/ringbuffer/ring_buffer_frontend.c @@ -62,7 +62,7 @@ #include "frontend.h" #include "shm.h" #include "rb-init.h" -#include "liblttng-ust/compat.h" /* For ENODATA */ +#include "common/compat/errno.h" /* For ENODATA */ /* Print DBG() messages about events lost only every 1048576 hits */ #define DBG_PRINT_NR_LOST (1UL << 20) diff --git a/src/common/ustcomm.c b/src/common/ustcomm.c index 2d445cba..ddd23ba8 100644 --- a/src/common/ustcomm.c +++ b/src/common/ustcomm.c @@ -28,7 +28,7 @@ #include "common/logging.h" #include "../liblttng-ust/ust-events-internal.h" -#include "../liblttng-ust/compat.h" +#include "common/compat/pthread.h" #define USTCOMM_CODE_OFFSET(code) \ (code == LTTNG_UST_OK ? 0 : (code - LTTNG_UST_ERR + 1)) diff --git a/src/liblttng-ust/Makefile.am b/src/liblttng-ust/Makefile.am index d064fad6..bca09ad8 100644 --- a/src/liblttng-ust/Makefile.am +++ b/src/liblttng-ust/Makefile.am @@ -80,7 +80,6 @@ liblttng_ust_runtime_la_SOURCES = \ tracepoint-internal.h \ ust-events-internal.h \ clock.h \ - compat.h \ wait.h \ jhash.h \ lttng-ust-uuid.h \ diff --git a/src/liblttng-ust/fd-tracker.c b/src/liblttng-ust/fd-tracker.c index df14f0e0..026a9327 100644 --- a/src/liblttng-ust/fd-tracker.c +++ b/src/liblttng-ust/fd-tracker.c @@ -30,8 +30,6 @@ #include #include "common/logging.h" -#include "liblttng-ust/compat.h" - /* Operations on the fd set. */ #define IS_FD_VALID(fd) ((fd) >= 0 && (fd) < lttng_ust_max_fd) #define GET_FD_SET_FOR_FD(fd, fd_sets) (&((fd_sets)[(fd) / FD_SETSIZE])) diff --git a/src/liblttng-ust/lttng-context-procname.c b/src/liblttng-ust/lttng-context-procname.c index 96a1b2ca..bbc4687a 100644 --- a/src/liblttng-ust/lttng-context-procname.c +++ b/src/liblttng-ust/lttng-context-procname.c @@ -13,7 +13,7 @@ #include #include #include -#include "compat.h" +#include "common/compat/pthread.h" #include "lttng-tracer-core.h" #include "context-internal.h" diff --git a/src/liblttng-ust/lttng-events.c b/src/liblttng-ust/lttng-events.c index ccd3dfd9..d5e08849 100644 --- a/src/liblttng-ust/lttng-events.c +++ b/src/liblttng-ust/lttng-events.c @@ -40,7 +40,6 @@ #include "common/dynamic-type.h" #include "common/ust-context-provider.h" #include "error.h" -#include "compat.h" #include "lttng-ust-uuid.h" #include "tracepoint-internal.h" diff --git a/src/liblttng-ust/lttng-tracer.h b/src/liblttng-ust/lttng-tracer.h index b02e4a80..b55388ef 100644 --- a/src/liblttng-ust/lttng-tracer.h +++ b/src/liblttng-ust/lttng-tracer.h @@ -15,7 +15,6 @@ #include #include #include "lttng-tracer-core.h" -#include "compat.h" /* Tracer properties */ #define CTF_MAGIC_NUMBER 0xC1FC1FC1 diff --git a/src/liblttng-ust/lttng-ust-comm.c b/src/liblttng-ust/lttng-ust-comm.c index a753206f..15cb5550 100644 --- a/src/liblttng-ust/lttng-ust-comm.c +++ b/src/liblttng-ust/lttng-ust-comm.c @@ -45,7 +45,8 @@ #include "common/macros.h" #include "tracepoint-internal.h" #include "lttng-tracer-core.h" -#include "compat.h" +#include "common/compat/pthread.h" +#include "common/procname.h" #include "common/ringbuffer/rb-init.h" #include "lttng-ust-statedump.h" #include "clock.h" diff --git a/src/liblttng-ust/lttng-ust-statedump-provider.h b/src/liblttng-ust/lttng-ust-statedump-provider.h index cab628aa..c6600f34 100644 --- a/src/liblttng-ust/lttng-ust-statedump-provider.h +++ b/src/liblttng-ust/lttng-ust-statedump-provider.h @@ -19,7 +19,6 @@ extern "C" { #include #include #include -#include "compat.h" #define LTTNG_UST_STATEDUMP_PROVIDER #include diff --git a/src/liblttng-ust/lttng-ust-statedump.c b/src/liblttng-ust/lttng-ust-statedump.c index cd8bc7c8..cd4df182 100644 --- a/src/liblttng-ust/lttng-ust-statedump.c +++ b/src/liblttng-ust/lttng-ust-statedump.c @@ -22,7 +22,6 @@ #include "lttng-ust-statedump.h" #include "jhash.h" #include "getenv.h" -#include "compat.h" #include "ust-events-internal.h" #define TRACEPOINT_DEFINE diff --git a/tests/unit/pthread_name/pthread_name.c b/tests/unit/pthread_name/pthread_name.c index 6faacf68..a662d826 100644 --- a/tests/unit/pthread_name/pthread_name.c +++ b/tests/unit/pthread_name/pthread_name.c @@ -6,7 +6,8 @@ #include #include -#include "../../../src/liblttng-ust/compat.h" +#include "common/compat/pthread.h" +#include "common/procname.h" #include "tap.h" -- 2.34.1