From: Michael Jeanson Date: Thu, 22 Apr 2021 00:17:56 +0000 (-0400) Subject: Move lttng_ust_strerror to liblttng-ust X-Git-Tag: v2.13.0-rc1~14 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=bb863844b80f455f7c44279da57d966f7d42ab51;p=lttng-ust.git Move lttng_ust_strerror to liblttng-ust Move the implementation of lttng_ust_strerror to liblttng-ust, it's part of its public ABI and should not be copied in multiples libraries. Change-Id: I825769d6c62b25e3e21b71abd18241998c6dde85 Signed-off-by: Michael Jeanson Signed-off-by: Mathieu Desnoyers --- diff --git a/src/common/ustcomm.c b/src/common/ustcomm.c index 0c46fe5e..00cbf5a7 100644 --- a/src/common/ustcomm.c +++ b/src/common/ustcomm.c @@ -23,16 +23,12 @@ #include "common/ustcomm.h" #include "common/ust-fd.h" #include "common/macros.h" -#include #include "common/dynamic-type.h" #include "common/logging.h" #include "common/events.h" #include "common/compat/pthread.h" -#define USTCOMM_CODE_OFFSET(code) \ - (code == LTTNG_UST_OK ? 0 : (code - LTTNG_UST_ERR + 1)) - #define USTCOMM_MAX_SEND_FDS 4 static @@ -48,43 +44,6 @@ int serialize_fields(struct lttng_ust_session *session, size_t *iter_output, size_t nr_lttng_fields, const struct lttng_ust_event_field * const *lttng_fields); -/* - * Human readable error message. - */ -static const char *ustcomm_readable_code[] = { - [ USTCOMM_CODE_OFFSET(LTTNG_UST_OK) ] = "Success", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR) ] = "Unknown error", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_NOENT) ] = "No entry", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_EXIST) ] = "Object already exists", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL) ] = "Invalid argument", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_PERM) ] = "Permission denied", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_NOSYS) ] = "Not implemented", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_EXITING) ] = "Process is exiting", - - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL_MAGIC) ] = "Invalid magic number", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_INVAL_SOCKET_TYPE) ] = "Invalid socket type", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_UNSUP_MAJOR) ] = "Unsupported major version", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_PEERCRED) ] = "Cannot get unix socket peer credentials", - [ USTCOMM_CODE_OFFSET(LTTNG_UST_ERR_PEERCRED_PID) ] = "Peer credentials PID is invalid. Socket appears to belong to a distinct, non-nested pid namespace.", -}; - -/* - * lttng_ust_strerror - * @code: must be a negative value of enum lttng_ust_error_code (or 0). - * - * Returns a ptr to a string representing a human readable error code from the - * ustcomm_return_code enum. - */ -const char *lttng_ust_strerror(int code) -{ - code = -code; - - if (code < LTTNG_UST_OK || code >= LTTNG_UST_ERR_NR) - code = LTTNG_UST_ERR; - - return ustcomm_readable_code[USTCOMM_CODE_OFFSET(code)]; -} - /* * ustcomm_connect_unix_sock * diff --git a/src/lib/lttng-ust/Makefile.am b/src/lib/lttng-ust/Makefile.am index 7f82ebde..2b22471a 100644 --- a/src/lib/lttng-ust/Makefile.am +++ b/src/lib/lttng-ust/Makefile.am @@ -61,7 +61,8 @@ liblttng_ust_runtime_la_SOURCES = \ rculfhash-internal.h \ rculfhash-mm-chunk.c \ rculfhash-mm-mmap.c \ - rculfhash-mm-order.c + rculfhash-mm-order.c \ + strerror.c if HAVE_PERF_EVENT liblttng_ust_runtime_la_SOURCES += \ diff --git a/src/lib/lttng-ust/strerror.c b/src/lib/lttng-ust/strerror.c new file mode 100644 index 00000000..1fa7fc3a --- /dev/null +++ b/src/lib/lttng-ust/strerror.c @@ -0,0 +1,48 @@ +/* + * SPDX-License-Identifier: LGPL-2.1-only + * + * Copyright (C) 2011 David Goulet + * Copyright (C) 2011-2013 Mathieu Desnoyers + */ + +#include + +#define CODE_OFFSET(code) \ + (code == LTTNG_UST_OK ? 0 : (code - LTTNG_UST_ERR + 1)) + +/* + * Human readable error message. + */ +static const char *ustcomm_readable_code[] = { + [ CODE_OFFSET(LTTNG_UST_OK) ] = "Success", + [ CODE_OFFSET(LTTNG_UST_ERR) ] = "Unknown error", + [ CODE_OFFSET(LTTNG_UST_ERR_NOENT) ] = "No entry", + [ CODE_OFFSET(LTTNG_UST_ERR_EXIST) ] = "Object already exists", + [ CODE_OFFSET(LTTNG_UST_ERR_INVAL) ] = "Invalid argument", + [ CODE_OFFSET(LTTNG_UST_ERR_PERM) ] = "Permission denied", + [ CODE_OFFSET(LTTNG_UST_ERR_NOSYS) ] = "Not implemented", + [ CODE_OFFSET(LTTNG_UST_ERR_EXITING) ] = "Process is exiting", + + [ CODE_OFFSET(LTTNG_UST_ERR_INVAL_MAGIC) ] = "Invalid magic number", + [ CODE_OFFSET(LTTNG_UST_ERR_INVAL_SOCKET_TYPE) ] = "Invalid socket type", + [ CODE_OFFSET(LTTNG_UST_ERR_UNSUP_MAJOR) ] = "Unsupported major version", + [ CODE_OFFSET(LTTNG_UST_ERR_PEERCRED) ] = "Cannot get unix socket peer credentials", + [ CODE_OFFSET(LTTNG_UST_ERR_PEERCRED_PID) ] = "Peer credentials PID is invalid. Socket appears to belong to a distinct, non-nested pid namespace.", +}; + +/* + * lttng_ust_strerror + * @code: must be a negative value of enum lttng_ust_error_code (or 0). + * + * Returns a ptr to a string representing a human readable error code from the + * ustcomm_return_code enum. + */ +const char *lttng_ust_strerror(int code) +{ + code = -code; + + if (code < LTTNG_UST_OK || code >= LTTNG_UST_ERR_NR) + code = LTTNG_UST_ERR; + + return ustcomm_readable_code[CODE_OFFSET(code)]; +}