Split and move compat.h to 'common/compat/'
authorMichael Jeanson <mjeanson@efficios.com>
Sat, 3 Apr 2021 00:52:58 +0000 (20:52 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 13 Apr 2021 18:20:42 +0000 (14:20 -0400)
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 <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
16 files changed:
src/common/Makefile.am
src/common/compat/errno.h [new file with mode: 0644]
src/common/compat/pthread.h [new file with mode: 0644]
src/common/procname.h [new file with mode: 0644]
src/common/ringbuffer/ring_buffer_frontend.c
src/common/ustcomm.c
src/liblttng-ust/Makefile.am
src/liblttng-ust/compat.h [deleted file]
src/liblttng-ust/fd-tracker.c
src/liblttng-ust/lttng-context-procname.c
src/liblttng-ust/lttng-events.c
src/liblttng-ust/lttng-tracer.h
src/liblttng-ust/lttng-ust-comm.c
src/liblttng-ust/lttng-ust-statedump-provider.h
src/liblttng-ust/lttng-ust-statedump.c
tests/unit/pthread_name/pthread_name.c

index 1c6fcbf0704a4e63161cd48580a4c41274da2d2d..fa2a9da87a491cb1a7cdb586bba2816684c96f00 100644 (file)
@@ -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 (file)
index 0000000..c761d6e
--- /dev/null
@@ -0,0 +1,16 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#ifndef _UST_COMMON_COMPAT_ERRNO_H
+#define _UST_COMMON_COMPAT_ERRNO_H
+
+#include <errno.h>
+
+#ifndef ENODATA
+#define ENODATA        ENOMSG
+#endif
+
+#endif /* _UST_COMMON_COMPAT_ERRNO_H */
diff --git a/src/common/compat/pthread.h b/src/common/compat/pthread.h
new file mode 100644 (file)
index 0000000..8779fa7
--- /dev/null
@@ -0,0 +1,108 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2016 Raphaël Beamonte <raphael.beamonte@gmail.com>
+ * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#ifndef _UST_COMMON_COMPAT_PTHREAD_H
+#define _UST_COMMON_COMPAT_PTHREAD_H
+
+#include <pthread.h>
+#include <errno.h>
+
+#include <lttng/ust-abi.h>
+
+#ifdef __FreeBSD__
+#include <pthread_np.h>
+#endif
+
+#if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID)
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+       /*
+        * Some implementations don't error out, replicate this behavior for
+        * consistency.
+        */
+       if (strnlen(name, LTTNG_UST_ABI_PROCNAME_LEN) >= LTTNG_UST_ABI_PROCNAME_LEN) {
+               return ERANGE;
+       }
+
+       return pthread_setname_np(pthread_self(), name);
+}
+#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+       return pthread_setname_np(name);
+}
+#elif defined(HAVE_PTHREAD_SET_NAME_NP_WITH_TID)
+
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+       /* Replicate pthread_setname_np's behavior */
+       if (strnlen(name, LTTNG_UST_ABI_PROCNAME_LEN) >= LTTNG_UST_ABI_PROCNAME_LEN) {
+               return ERANGE;
+       }
+
+       pthread_set_name_np(pthread_self(), name);
+       return 0;
+}
+#elif defined(__linux__)
+
+/* Fallback on prtctl on Linux */
+#include <sys/prctl.h>
+
+static inline
+int lttng_pthread_setname_np(const char *name)
+{
+       /* Replicate pthread_setname_np's behavior */
+       if (strnlen(name, LTTNG_UST_ABI_PROCNAME_LEN) >= LTTNG_UST_ABI_PROCNAME_LEN) {
+               return ERANGE;
+       }
+       return prctl(PR_SET_NAME, name, 0, 0, 0);
+}
+#else
+#error "Please add pthread set name support for your OS."
+#endif
+
+
+#if defined(HAVE_PTHREAD_GETNAME_NP_WITH_TID)
+static inline
+int lttng_pthread_getname_np(char *name, size_t len)
+{
+       return pthread_getname_np(pthread_self(), name, len);
+}
+#elif defined(HAVE_PTHREAD_GETNAME_NP_WITHOUT_TID)
+static inline
+int lttng_pthread_getname_np(char *name, size_t len)
+{
+       return pthread_getname_np(name, len);
+}
+#elif defined(HAVE_PTHREAD_GET_NAME_NP_WITH_TID)
+
+static inline
+int lttng_pthread_getname_np(char *name, size_t len)
+{
+       pthread_get_name_np(pthread_self(), name, len);
+       return 0;
+}
+#elif defined(__linux__)
+
+/* Fallback on prtctl on Linux */
+#include <sys/prctl.h>
+
+static inline
+int lttng_pthread_getname_np(char *name, size_t len)
+{
+       return prctl(PR_GET_NAME, name, 0, 0, 0);
+}
+
+#else
+#error "Please add pthread get name support for your OS."
+#endif
+
+#endif /* _UST_COMMON_COMPAT_PTHREAD_H */
diff --git a/src/common/procname.h b/src/common/procname.h
new file mode 100644 (file)
index 0000000..061202c
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * SPDX-License-Identifier: LGPL-2.1-only
+ *
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ * Copyright (C) 2016 Raphaël Beamonte <raphael.beamonte@gmail.com>
+ * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
+ */
+
+#ifndef _UST_COMMON_PROCNAME_H
+#define _UST_COMMON_PROCNAME_H
+
+#include <string.h>
+#include <lttng/ust-abi.h>
+
+#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 */
index 9074dbcb3a41bde88316dcf107103a76d5f3d50c..d08fab758f1faada9b056df76d0f9956f730e89b 100644 (file)
@@ -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)
index 2d445cbadc0bda6cafd15cb1bb3594d713d4d2d2..ddd23ba86e381e6d581f315b819654df4476216c 100644 (file)
@@ -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))
index d064fad6b3415940a55eb069385c75f3c2429cbc..bca09ad8ccdf2c3a540efeccb7285412ca5fb6c8 100644 (file)
@@ -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/compat.h b/src/liblttng-ust/compat.h
deleted file mode 100644 (file)
index 7f0f502..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * SPDX-License-Identifier: LGPL-2.1-only
- *
- * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
- * Copyright (C) 2016 Raphaël Beamonte <raphael.beamonte@gmail.com>
- * Copyright (C) 2020 Michael Jeanson <mjeanson@efficios.com>
- */
-
-#ifndef _UST_COMPAT_H
-#define _UST_COMPAT_H
-
-#include <pthread.h>
-#include <errno.h>
-#include <string.h>
-
-#ifdef __FreeBSD__
-#include <pthread_np.h>
-#endif
-
-#include <lttng/ust-abi.h>
-
-#define LTTNG_UST_PROCNAME_SUFFIX "-ust"
-
-
-#if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID)
-static inline
-int lttng_pthread_setname_np(const char *name)
-{
-       /*
-        * Some implementations don't error out, replicate this behavior for
-        * consistency.
-        */
-       if (strnlen(name, LTTNG_UST_ABI_PROCNAME_LEN) >= LTTNG_UST_ABI_PROCNAME_LEN) {
-               return ERANGE;
-       }
-
-       return pthread_setname_np(pthread_self(), name);
-}
-#elif defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID)
-static inline
-int lttng_pthread_setname_np(const char *name)
-{
-       return pthread_setname_np(name);
-}
-#elif defined(HAVE_PTHREAD_SET_NAME_NP_WITH_TID)
-
-static inline
-int lttng_pthread_setname_np(const char *name)
-{
-       /* Replicate pthread_setname_np's behavior */
-       if (strnlen(name, LTTNG_UST_ABI_PROCNAME_LEN) >= LTTNG_UST_ABI_PROCNAME_LEN) {
-               return ERANGE;
-       }
-
-       pthread_set_name_np(pthread_self(), name);
-       return 0;
-}
-#elif defined(__linux__)
-
-/* Fallback on prtctl on Linux */
-#include <sys/prctl.h>
-
-static inline
-int lttng_pthread_setname_np(const char *name)
-{
-       /* Replicate pthread_setname_np's behavior */
-       if (strnlen(name, LTTNG_UST_ABI_PROCNAME_LEN) >= LTTNG_UST_ABI_PROCNAME_LEN) {
-               return ERANGE;
-       }
-       return prctl(PR_SET_NAME, name, 0, 0, 0);
-}
-#else
-#error "Please add pthread set name support for your OS."
-#endif
-
-
-#if defined(HAVE_PTHREAD_GETNAME_NP_WITH_TID)
-static inline
-int lttng_pthread_getname_np(char *name, size_t len)
-{
-       return pthread_getname_np(pthread_self(), name, len);
-}
-#elif defined(HAVE_PTHREAD_GETNAME_NP_WITHOUT_TID)
-static inline
-int lttng_pthread_getname_np(char *name, size_t len)
-{
-       return pthread_getname_np(name, len);
-}
-#elif defined(HAVE_PTHREAD_GET_NAME_NP_WITH_TID)
-
-static inline
-int lttng_pthread_getname_np(char *name, size_t len)
-{
-       pthread_get_name_np(pthread_self(), name, len);
-       return 0;
-}
-#elif defined(__linux__)
-
-/* Fallback on prtctl on Linux */
-#include <sys/prctl.h>
-
-static inline
-int lttng_pthread_getname_np(char *name, size_t len)
-{
-       return prctl(PR_GET_NAME, name, 0, 0, 0);
-}
-
-#else
-#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 <errno.h>
-
-#ifndef ENODATA
-#define ENODATA        ENOMSG
-#endif
-
-#endif /* _UST_COMPAT_H */
index df14f0e08e18c5a841f4c2a1317d259d0340c859..026a9327f297ac016ca009763716eb308e752e37 100644 (file)
@@ -30,8 +30,6 @@
 #include <lttng/ust-error.h>
 #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]))
index 96a1b2ca2c36083b9d921220f1173f551256025d..bbc4687ad20bb2d878a5b249952092d98d45e95c 100644 (file)
@@ -13,7 +13,7 @@
 #include <lttng/ringbuffer-context.h>
 #include <urcu/tls-compat.h>
 #include <assert.h>
-#include "compat.h"
+#include "common/compat/pthread.h"
 #include "lttng-tracer-core.h"
 
 #include "context-internal.h"
index ccd3dfd9164bf744806dcbf69a7d18cc49baae4d..d5e088495cf57c49b09527524caa4c9e8e765b9a 100644 (file)
@@ -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"
index b02e4a80d282300189a79c33cfce30fe44b4d81b..b55388ef00654e75b2e907205e54656a024026e3 100644 (file)
@@ -15,7 +15,6 @@
 #include <stdint.h>
 #include <lttng/ust-events.h>
 #include "lttng-tracer-core.h"
-#include "compat.h"
 
 /* Tracer properties */
 #define CTF_MAGIC_NUMBER               0xC1FC1FC1
index a753206fd550825184d4ff76ef9e82ea583e2986..15cb555028d979ff656ddbcf9e3c66e98f190c10 100644 (file)
@@ -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"
index cab628aa8ea1131d4d96908314a652225298b1bb..c6600f349b4281614d4ccb2e5df8bc14220425f0 100644 (file)
@@ -19,7 +19,6 @@ extern "C" {
 #include <stdint.h>
 #include <unistd.h>
 #include <lttng/ust-events.h>
-#include "compat.h"
 
 #define LTTNG_UST_STATEDUMP_PROVIDER
 #include <lttng/tracepoint.h>
index cd8bc7c8247022f9da56428e40b573050cc5f334..cd4df182c0e04564f3fdcefc95864eb682f2ccbb 100644 (file)
@@ -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
index 6faacf68224da07f7b0429aeccb9caeae89f509c..a662d826be4f1321abea4ff886a0dcddd2826e17 100644 (file)
@@ -6,7 +6,8 @@
 
 #include <stdio.h>
 #include <string.h>
-#include "../../../src/liblttng-ust/compat.h"
+#include "common/compat/pthread.h"
+#include "common/procname.h"
 
 #include "tap.h"
 
This page took 0.033744 seconds and 4 git commands to generate.