Low: fix internal object symbol's leak & expose run-time lib version

The object in question has never been published through the header file,
hence it's presumably safe to make it static as it's meant to be.

On the other hand, QB_LOG_INIT_DATA macro from qblog.h has already
started to depend on that symbol so as to locate the library handle
for libqb itself correctly.  This is trivially fixed by finally exposing
library versioning info in run-time ("online") as a structure with
members corresponding to compile-time ("offline") counterparts from
qbconfig.h header file, which are admittedly of very limited use
as opposed to the newly introduced dynamic info, plus lower-cased
equivalent of QB_VER_STR.  Better than to roll out a futile data object
serving as an artificial anchor for the above purpose, and this was
due for a while, afterall.

In turn, also bump "current" and "age" of fields of the libtool's
"-version-info" versioning system.

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
This commit is contained in:
Jan Pokorný 2017-10-06 17:17:26 +02:00
parent 20246f544f
commit c011b12fca
No known key found for this signature in database
GPG Key ID: 61BBB23A9E8F8DE2
9 changed files with 46 additions and 11 deletions

View File

@ -30,7 +30,12 @@
/* Enabling code using __attribute__((section)) */ /* Enabling code using __attribute__((section)) */
#undef QB_HAVE_ATTRIBUTE_SECTION #undef QB_HAVE_ATTRIBUTE_SECTION
/* versioning info: MAJOR, MINOR, MICRO, and REST components */ /* versioning info: MAJOR, MINOR, MICRO, and REST components;
note that static compile-time info is not that useful as consulting
the respectively named members of qb_version struct constant under
@c qb_ver identifier (or @c qb_ver_str equivalent of the local
upper-cased value) directly from libqb in run-time (see qbutil.h),
but that was only introduced after v1.0.2 */
#undef QB_VER_MAJOR #undef QB_VER_MAJOR
#undef QB_VER_MINOR #undef QB_VER_MINOR
#undef QB_VER_MICRO #undef QB_VER_MICRO

View File

@ -299,9 +299,11 @@ extern struct qb_log_callsite QB_ATTR_SECTION_STOP[];
#define QB_NONAPI_LOG_INIT_DATA_EXTRA_(name) \ #define QB_NONAPI_LOG_INIT_DATA_EXTRA_(name) \
{ Dl_info work_dli; \ { Dl_info work_dli; \
/* libqb sanity (locating libqb by it's relatively unique \ /* libqb sanity (locating libqb by it's relatively unique \
-- and currently only such per-linkage global one -- \ non-functional symbols -- the two are mutually exclusive, the \
non-functional symbol, due to possible confusion otherwise) */ \ ordinarily latter was introduced by accident, the former is \
if (dladdr(dlsym(RTLD_DEFAULT, "facilitynames"), &work_dli) \ intentional -- due to possible confusion otherwise) */ \
if ((dladdr(dlsym(RTLD_DEFAULT, "qb_ver_str"), &work_dli) \
|| dladdr(dlsym(RTLD_DEFAULT, "facilitynames"), &work_dli)) \
&& (work_handle = dlopen(work_dli.dli_fname, \ && (work_handle = dlopen(work_dli.dli_fname, \
RTLD_LOCAL|RTLD_LAZY)) != NULL) { \ RTLD_LOCAL|RTLD_LAZY)) != NULL) { \
work_s1 = (struct qb_log_callsite *) \ work_s1 = (struct qb_log_callsite *) \

View File

@ -289,6 +289,17 @@ uint64_t
qb_util_stopwatch_time_split_get(qb_util_stopwatch_t *sw, qb_util_stopwatch_time_split_get(qb_util_stopwatch_t *sw,
uint32_t receint, uint32_t older); uint32_t receint, uint32_t older);
/** Structured library versioning info */
extern const struct qb_version {
uint8_t major; /**< Major component */
uint8_t minor; /**< Minor component */
uint8_t micro; /**< Micro component */
const char *rest; /**< Rest (pertaining the mid-release-point) */
} qb_ver;
/** Complete library versioning info as a string */
extern const char *const qb_ver_str;
/* *INDENT-OFF* */ /* *INDENT-OFF* */
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -30,7 +30,7 @@ AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
lib_LTLIBRARIES = libqb.la lib_LTLIBRARIES = libqb.la
libqb_la_LDFLAGS = -version-info 18:2:18 libqb_la_LDFLAGS = -version-info 19:0:19
source_to_lint = util.c hdb.c ringbuffer.c ringbuffer_helper.c \ source_to_lint = util.c hdb.c ringbuffer.c ringbuffer_helper.c \
array.c loop.c loop_poll.c loop_job.c \ array.c loop.c loop_poll.c loop_job.c \

View File

@ -892,10 +892,12 @@ qb_log_init(const char *name, int32_t facility, uint8_t priority)
#ifdef QB_HAVE_ATTRIBUTE_SECTION #ifdef QB_HAVE_ATTRIBUTE_SECTION
/* sanity check that target chain supplied QB_ATTR_SECTION_ST{ART,OP} /* sanity check that target chain supplied QB_ATTR_SECTION_ST{ART,OP}
symbols and hence the local references to them are not referencing symbols and hence the local references to them are not referencing
the proper libqb's ones (locating libqb-self by it's relatively the proper libqb's ones (locating libqb by it's relatively unique
unique -- and currently only such per-linkage global one -- non-functional symbols -- the two are mutually exclusive, the
non-functional symbol, due to possible confusion otherwise) */ ordinarily latter was introduced by accident, the former is
if (dladdr(dlsym(RTLD_DEFAULT, "facilitynames"), &work_dli) intentional -- due to possible confusion otherwise) */
if ((dladdr(dlsym(RTLD_DEFAULT, "qb_ver_str"), &work_dli)
|| dladdr(dlsym(RTLD_DEFAULT, "facilitynames"), &work_dli))
&& (work_handle = dlopen(work_dli.dli_fname, && (work_handle = dlopen(work_dli.dli_fname,
RTLD_LOCAL|RTLD_LAZY)) != NULL) { RTLD_LOCAL|RTLD_LAZY)) != NULL) {
work_s1 = (struct qb_log_callsite *) work_s1 = (struct qb_log_callsite *)

View File

@ -49,7 +49,7 @@ static struct syslog_names prioritynames[] = {
{NULL, -1} {NULL, -1}
}; };
struct syslog_names facilitynames[] = { static struct syslog_names facilitynames[] = {
{"auth", LOG_AUTH}, {"auth", LOG_AUTH},
#if defined(LOG_AUTHPRIV) #if defined(LOG_AUTHPRIV)
{"authpriv", LOG_AUTHPRIV}, {"authpriv", LOG_AUTHPRIV},

View File

@ -23,6 +23,7 @@
#include "util_int.h" #include "util_int.h"
#include <pthread.h> #include <pthread.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <qb/qbconfig.h>
#include <qb/qbdefs.h> #include <qb/qbdefs.h>
#include <qb/qbutil.h> #include <qb/qbutil.h>
@ -372,3 +373,12 @@ qb_util_stopwatch_time_split_get(qb_util_stopwatch_t *sw,
} }
return (time_start - time_end) / QB_TIME_NS_IN_USEC; return (time_start - time_end) / QB_TIME_NS_IN_USEC;
} }
const struct qb_version qb_ver = {
.major = QB_VER_MAJOR,
.minor = QB_VER_MINOR,
.micro = QB_VER_MICRO,
.rest = QB_VER_REST,
};
const char *const qb_ver_str = QB_VER_STR;

View File

@ -53,6 +53,11 @@ main(int32_t argc, char *argv[])
qb_log_tags_stringify_fn_set(my_tags_stringify); qb_log_tags_stringify_fn_set(my_tags_stringify);
qb_log_format_set(QB_LOG_STDERR, "[%5g|%p] %f:%l:%b"); qb_log_format_set(QB_LOG_STDERR, "[%5g|%p] %f:%l:%b");
#if 0
printf("\n==%s consists of: %d, %d, %d, %s==\n\n", qb_ver_str,
qb_ver.major, qb_ver.minor, qb_ver.micro, qb_ver.rest);
#endif
#if 0 #if 0
printf("--\n"); printf("--\n");
qb_log_callsites_dump(); qb_log_callsites_dump();

View File

@ -1,2 +1,2 @@
[MAIN |debug] ../log_client.c:64:hello [MAIN |debug] ../log_client.c:69:hello
[libqb|error] log_blackbox.c:196:qb_log_blackbox_print_from_file: [libqb|error] log_blackbox.c:196:qb_log_blackbox_print_from_file: