Hide private usterr-signal-safe.h symbols
authorMichael Jeanson <mjeanson@efficios.com>
Thu, 25 Feb 2021 16:14:47 +0000 (11:14 -0500)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 2 Mar 2021 19:45:55 +0000 (14:45 -0500)
The major SONAME bump to '1' gives us the opportunity to hide private
symbols that should never have been visible.

Changing 'ust_loglevel' from a public weak symbol to a private one,
means that each library that uses ust_err will now have it's own private
copy of the loglevel and will have to call 'ust_err_init' in it's
constructor.

While we're at it, namespace the symbols that were previously part of
the ABI.

Change-Id: I031d4ebfaa43fa4fb3c9f60dc6b557b1d30eca18
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
include/Makefile.am
include/usterr-signal-safe.h
liblttng-ust-ctl/ustctl.c
liblttng-ust-dl/lttng-ust-dl.c
liblttng-ust-fd/Makefile.am
liblttng-ust-fd/lttng-ust-fd.c
liblttng-ust/lttng-ust-comm.c
liblttng-ust/tracepoint.c
snprintf/core.c

index 2c78459efc2813b9bf760834e256bd7e9018d22e..61a09cdc854c1b4f854dd9f47a9091096a2db61c 100644 (file)
@@ -48,8 +48,6 @@ nobase_nodist_include_HEADERS = \
 ### Global private headers ###
 ###                        ###
 
-# note: usterr-signal-safe.h need namespace cleanup.
-
 noinst_HEADERS = \
        usterr-signal-safe.h \
        ust-snprintf.h \
index 3d6756872fd6943a18ca83149bde06349fb084c8..bbdad0495e8710e53f6ef996eaa23113ba6927c2 100644 (file)
 #include <sys/types.h>
 #include <errno.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <ust-share.h>
+#include "ust-helper.h"
 #include "ust-tid.h"
 #include "ust-snprintf.h"
 
-enum ust_loglevel {
-       UST_LOGLEVEL_UNKNOWN = 0,
-       UST_LOGLEVEL_NORMAL,
-       UST_LOGLEVEL_DEBUG,
+enum ust_err_loglevel {
+       UST_ERR_LOGLEVEL_UNKNOWN = 0,
+       UST_ERR_LOGLEVEL_NORMAL,
+       UST_ERR_LOGLEVEL_DEBUG,
 };
 
-extern volatile enum ust_loglevel ust_loglevel;
-void init_usterr(void);
+LTTNG_HIDDEN
+extern volatile enum ust_err_loglevel ust_err_loglevel;
+LTTNG_HIDDEN
+void ust_err_init(void);
 
 #ifdef LTTNG_UST_DEBUG
-static inline int ust_debug(void)
+static inline bool ust_err_debug_enabled(void)
 {
-       return 1;
+       return true;
 }
 #else /* #ifdef LTTNG_UST_DEBUG */
-static inline int ust_debug(void)
+static inline bool ust_err_debug_enabled(void)
 {
-       return ust_loglevel == UST_LOGLEVEL_DEBUG;
+       return ust_err_loglevel == UST_ERR_LOGLEVEL_DEBUG;
 }
 #endif /* #else #ifdef LTTNG_UST_DEBUG */
 
+/*
+ * The default component for error messages.
+ */
 #ifndef UST_COMPONENT
-//#error UST_COMPONENT is undefined
 #define UST_COMPONENT libust
 #endif
 
@@ -47,17 +53,18 @@ static inline int ust_debug(void)
 #define UST_XSTR(d) UST_STR(d)
 #define UST_STR(s) #s
 
-#define USTERR_MAX_LEN 512
+#define UST_ERR_MAX_LEN        512
 
-/* We sometimes print in the tracing path, and tracing can occur in
+/*
+ * We sometimes print in the tracing path, and tracing can occur in
  * signal handlers, so we must use a print method which is signal safe.
  */
-/* Can't use dynamic allocation. Limit ourselves to USTERR_MAX_LEN chars. */
+/* Can't use dynamic allocation. Limit ourselves to UST_ERR_MAX_LEN chars. */
 /* Add end of string in case of buffer overflow. */
 #define sigsafe_print_err(fmt, args...)                                        \
 do {                                                                   \
-       if (ust_debug()) {                                              \
-               char ____buf[USTERR_MAX_LEN];                           \
+       if (ust_err_debug_enabled()) {                                  \
+               char ____buf[UST_ERR_MAX_LEN];                          \
                int ____saved_errno;                                    \
                                                                        \
                ____saved_errno = errno;        /* signal-safety */     \
@@ -92,7 +99,7 @@ do {                                                                  \
  */
 #define PERROR(call, args...)                                          \
        do {                                                            \
-               if (ust_debug()) {                                      \
+               if (ust_err_debug_enabled()) {                          \
                        char buf[200] = "Error in strerror_r()";        \
                        strerror_r(errno, buf, sizeof(buf));            \
                        ERRMSG("Error: " call ": %s", ## args, buf);    \
@@ -104,7 +111,7 @@ do {                                                                        \
  */
 #define PERROR(call, args...)                                          \
        do {                                                            \
-               if (ust_debug()) {                                      \
+               if (ust_err_debug_enabled()) {                          \
                        char *buf;                                      \
                        char tmp[200];                                  \
                        buf = strerror_r(errno, tmp, sizeof(tmp));      \
index 057895d838614a444e434a404b7bbb4a8d69cf69..a149e9d6ba6d875878f4a15860820d9e9d8a19d3 100644 (file)
@@ -2921,8 +2921,8 @@ int ustctl_counter_clear(struct ustctl_daemon_counter *counter,
 static __attribute__((constructor))
 void ustctl_init(void)
 {
-       init_usterr();
-       lttng_ust_getenv_init();        /* Needs init_usterr() to be completed. */
+       ust_err_init();
+       lttng_ust_getenv_init();        /* Needs ust_err_init() to be completed. */
        lttng_ust_clock_init();
        lttng_ring_buffer_metadata_client_init();
        lttng_ring_buffer_client_overwrite_init();
index 6b7362aca2b74402c2baf3bab4071b2ed677ad5e..b2e43b9613847318839bfb3e0eb82abfcccb871a 100644 (file)
@@ -32,6 +32,12 @@ static void *(*__lttng_ust_plibc_dlmopen)(Lmid_t nsid, const char *filename,
 #endif
 static int (*__lttng_ust_plibc_dlclose)(void *handle);
 
+static __attribute__((constructor))
+void _lttng_ust_dl_init(void)
+{
+       ust_err_init();
+}
+
 static
 void *_lttng_ust_dl_libc_dlopen(const char *filename, int flags)
 {
index 9b30d87c4bdc60b7c3ca71af2bf1cce558ed3448..b9242d8fdd7c5d5fd877f9b721acb2aeb9c14c80 100644 (file)
@@ -8,6 +8,7 @@ liblttng_ust_fd_la_SOURCES = \
 
 liblttng_ust_fd_la_LIBADD = \
        $(top_builddir)/liblttng-ust/liblttng-ust.la \
+       $(top_builddir)/snprintf/libustsnprintf.la \
        $(DL_LIBS)
 
 liblttng_ust_fd_la_CFLAGS = -DUST_COMPONENT=liblttng-ust-fd $(AM_CFLAGS)
index c60f3f0370bcf51b7d54edca395cf8493e052f47..607df41eabfb9c8ca21069b0f11f7cd63c4dda89 100644 (file)
 static int (*__lttng_ust_fd_plibc_close)(int fd);
 static int (*__lttng_ust_fd_plibc_fclose)(FILE *stream);
 
+static __attribute__((constructor))
+void _lttng_ust_fd_init(void)
+{
+       ust_err_init();
+}
+
 static
 int _lttng_ust_fd_libc_close(int fd)
 {
index 18701936feacd241c505e7f134092ec2079c6956..a269104965e9c8348af7bb4a89c3f65ec6d634a9 100644 (file)
@@ -1718,7 +1718,7 @@ void wait_for_sessiond(struct sock_info *sock_info)
 "Please upgrade your kernel "
 "(fix is commit 9ea71503a8ed9184d2d0b8ccc4d269d05f7940ae in Linux kernel "
 "mainline). LTTng-UST will use polling mode fallback.");
-                       if (ust_debug())
+                       if (ust_err_debug_enabled())
                                PERROR("futex");
                        goto end_wait;
                }
@@ -2107,8 +2107,8 @@ void __attribute__((constructor)) lttng_ust_init(void)
         * sessiond (otherwise leading to errors when trying to create
         * sessiond before the init functions are completed).
         */
-       init_usterr();
-       lttng_ust_getenv_init();        /* Needs init_usterr() to be completed. */
+       ust_err_init();
+       lttng_ust_getenv_init();        /* Needs ust_err_init() to be completed. */
        init_tracepoint();
        lttng_ust_init_fd_tracker();
        lttng_ust_clock_init();
index 089232e1030d2cc4b05f3247a19bbf2576937610..e0b5da3f46386fb39312a743d002db0efdddcacb 100644 (file)
@@ -897,7 +897,7 @@ lib_added:
 
        DBG("just registered a tracepoints section from %p and having %d tracepoints",
                tracepoints_start, tracepoints_count);
-       if (ust_debug()) {
+       if (ust_err_debug_enabled()) {
                int i;
 
                for (i = 0; i < tracepoints_count; i++) {
@@ -960,7 +960,7 @@ void init_tracepoint(void)
 {
        if (uatomic_xchg(&initialized, 1) == 1)
                return;
-       init_usterr();
+       ust_err_init();
        check_weak_hidden();
 }
 
index c4d9e0b13107b24967762d2b1b07d24ef40e6b6a..d0f60a106e6f5d389b8c8a5a93c8a584ce669c79 100644 (file)
@@ -6,13 +6,13 @@
 
 #include <usterr-signal-safe.h>
 
-volatile enum ust_loglevel ust_loglevel;
+volatile enum ust_err_loglevel ust_err_loglevel;
 
-void init_usterr(void)
+void ust_err_init(void)
 {
        char *ust_debug;
 
-       if (ust_loglevel == UST_LOGLEVEL_UNKNOWN) {
+       if (ust_err_loglevel == UST_ERR_LOGLEVEL_UNKNOWN) {
                /*
                 * This getenv is not part of lttng_getenv() because it
                 * is required to print ERR() performed during getenv
@@ -20,8 +20,8 @@ void init_usterr(void)
                 */
                ust_debug = getenv("LTTNG_UST_DEBUG");
                if (ust_debug)
-                       ust_loglevel = UST_LOGLEVEL_DEBUG;
+                       ust_err_loglevel = UST_ERR_LOGLEVEL_DEBUG;
                else
-                       ust_loglevel = UST_LOGLEVEL_NORMAL;
+                       ust_err_loglevel = UST_ERR_LOGLEVEL_NORMAL;
        }
 }
This page took 0.030668 seconds and 4 git commands to generate.