#define _LGPL_SOURCE
#include <assert.h>
+#include <errno.h>
#include <inttypes.h>
+#include <pthread.h>
#include <stdlib.h>
#include <string.h>
-#include <errno.h>
-#include <lttng/lttng-error.h>
#include <common/common.h>
#include <common/compat/getenv.h>
+#include <lttng/lttng-error.h>
#include "error.h"
/* TLS variable that contains the time of one single log entry. */
DEFINE_URCU_TLS(struct log_time, error_log_time);
+DEFINE_URCU_TLS(const char *, logger_thread_name);
LTTNG_HIDDEN
const char *log_add_time(void)
return "";
}
+LTTNG_HIDDEN
+void logger_set_thread_name(const char *name, bool set_pthread_name)
+{
+ int ret;
+
+ assert(name);
+ URCU_TLS(logger_thread_name) = name;
+
+ if (set_pthread_name) {
+ char pthread_name[16];
+
+ /*
+ * Truncations are expected since pthread limits thread names to
+ * a generous 16 characters.
+ */
+ strncpy(pthread_name, name, sizeof(pthread_name));
+ pthread_name[sizeof(pthread_name) - 1] = '\0';
+ ret = pthread_setname_np(pthread_self(), pthread_name);
+ if (ret) {
+ DBG("Failed to set pthread name attribute");
+ }
+ }
+}
+
/*
* Human readable error message.
*/
#include <stdbool.h>
#include <urcu/tls-compat.h>
#include <common/compat/time.h>
+#include <common/string-utils/format.h>
+#include <common/macros.h>
#ifndef _GNU_SOURCE
#error "lttng-tools error.h needs _GNU_SOURCE"
char str[19];
};
extern DECLARE_URCU_TLS(struct log_time, error_log_time);
+extern DECLARE_URCU_TLS(const char *, logger_thread_name);
extern int lttng_opt_quiet;
extern int lttng_opt_verbose;
} while (0)
/* Three level of debug. Use -v, -vv or -vvv for the levels */
-#define _ERRMSG(msg, type, fmt, args...) __lttng_print(type, msg \
- " - %s [%ld/%ld]: " fmt " (in %s() at " __FILE__ ":" XSTR(__LINE__) ")\n", \
- log_add_time(), (long) getpid(), (long) lttng_gettid(), ## args, __func__)
+#define _ERRMSG(msg, type, fmt, args...) \
+ do { \
+ if (caa_unlikely(__lttng_print_check_opt(type))) { \
+ char generic_name[MAX_INT_DEC_LEN(long) + \
+ MAX_INT_DEC_LEN(long)]; \
+ \
+ snprintf(generic_name, sizeof(generic_name), \
+ "%ld/%ld", (long) getpid(), \
+ (long) lttng_gettid()); \
+ \
+ __lttng_print(type, \
+ msg " - %s [%s]: " fmt \
+ " (in %s() at " __FILE__ \
+ ":" XSTR(__LINE__) ")\n", \
+ log_add_time(), \
+ URCU_TLS(logger_thread_name) ?: \
+ generic_name, \
+ ##args, __func__); \
+ } \
+ } while (0)
-#define _ERRMSG_NO_LOC(msg, type, fmt, args...) __lttng_print(type, msg \
- " - %s [%ld/%ld]: " fmt "\n", \
- log_add_time(), (long) getpid(), (long) lttng_gettid(), ## args)
+#define _ERRMSG_NO_LOC(msg, type, fmt, args...) \
+ do { \
+ if (caa_unlikely(__lttng_print_check_opt(type))) { \
+ char generic_name[MAX_INT_DEC_LEN(long) + \
+ MAX_INT_DEC_LEN(long)]; \
+ \
+ snprintf(generic_name, sizeof(generic_name), \
+ "%ld/%ld", (long) getpid(), \
+ (long) lttng_gettid()); \
+ \
+ __lttng_print(type, msg " - %s [%s]: " fmt "\n", \
+ log_add_time(), \
+ URCU_TLS(logger_thread_name) ?: \
+ generic_name, \
+ ##args); \
+ } \
+ } while (0)
#define MSG(fmt, args...) \
__lttng_print(PRINT_MSG, fmt "\n", ## args)
#define BUG(fmt, args...) _ERRMSG("BUG", PRINT_BUG, fmt, ## args)
-#define DBG(fmt, args...) _ERRMSG("DEBUG1", PRINT_DBG, fmt, ## args)
-#define DBG_NO_LOC(fmt, args...) _ERRMSG_NO_LOC("DEBUG1", PRINT_DBG, fmt, ## args)
-#define DBG2(fmt, args...) _ERRMSG("DEBUG2", PRINT_DBG2, fmt, ## args)
-#define DBG3(fmt, args...) _ERRMSG("DEBUG3", PRINT_DBG3, fmt, ## args)
+#define DBG(fmt, args...) _ERRMSG("DBG1", PRINT_DBG, fmt, ## args)
+#define DBG_NO_LOC(fmt, args...) _ERRMSG_NO_LOC("DBG1", PRINT_DBG, fmt, ## args)
+#define DBG2(fmt, args...) _ERRMSG("DBG2", PRINT_DBG2, fmt, ## args)
+#define DBG3(fmt, args...) _ERRMSG("DBG3", PRINT_DBG3, fmt, ## args)
#define LOG(type, fmt, args...) \
do { \
switch (type) { \
*/
const char *log_add_time(void);
+/* Name must be a statically-allocated string. */
+LTTNG_HIDDEN
+void logger_set_thread_name(const char *name, bool set_pthread_name);
+
#endif /* _ERROR_H */
DIR=$(readlink -f "$TESTDIR")
- if [ -z $(pgrep $RELAYD_MATCH) ]; then
+ if [ -z $(pgrep -f $RELAYD_MATCH) ]; then
# shellcheck disable=SC2086
$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST
#$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 &
local retval=0
local pids=
- pids=$(pgrep "$RELAYD_MATCH")
+ pids=$(pgrep -f "$RELAYD_MATCH")
if [ -z "$pids" ]; then
if [ "$withtap" -eq "1" ]; then
pass "No relay daemon to kill"
else
out=1
while [ -n "$out" ]; do
- out=$(pgrep "$RELAYD_MATCH")
+ out=$(pgrep -f "$RELAYD_MATCH")
if [ -n "$dtimeleft_s" ]; then
if [ $dtimeleft_s -lt 0 ]; then
out=
: "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}"
export LTTNG_SESSION_CONFIG_XSD_PATH
- if [ -z "$(pgrep "${SESSIOND_MATCH}")" ]; then
+ if [ -z "$(pgrep -f "${SESSIOND_MATCH}")" ]; then
# Have a load path ?
if [ -n "$load_path" ]; then
# shellcheck disable=SC2086
local retval=0
local runas_pids=
- runas_pids=$(pgrep "$RUNAS_MATCH")
+ runas_pids=$(pgrep -f "$RUNAS_MATCH")
local pids=
- pids=$(pgrep "$SESSIOND_MATCH")
+ pids=$(pgrep -f "$SESSIOND_MATCH")
if [ -n "$runas_pids" ]; then
pids="$pids $runas_pids"
else
out=1
while [ -n "$out" ]; do
- out=$(pgrep "${SESSIOND_MATCH}")
+ out=$(pgrep -f "${SESSIOND_MATCH}")
if [ -n "$dtimeleft_s" ]; then
if [ $dtimeleft_s -lt 0 ]; then
out=
done
out=1
while [ -n "$out" ]; do
- out=$(pgrep "$CONSUMERD_MATCH")
+ out=$(pgrep -f "$CONSUMERD_MATCH")
if [ -n "$dtimeleft_s" ]; then
if [ $dtimeleft_s -lt 0 ]; then
out=
return
fi
- PID_SESSIOND="$(pgrep "${SESSIOND_MATCH}") $(pgrep "$RUNAS_MATCH")"
+ PID_SESSIOND="$(pgrep -f "${SESSIOND_MATCH}") $(pgrep -f "$RUNAS_MATCH")"
if [ "$withtap" -eq "1" ]; then
diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')"
else
out=1
while [ $out -ne 0 ]; do
- pid="$(pgrep "$SESSIOND_MATCH")"
+ pid="$(pgrep -f "$SESSIOND_MATCH")"
# Wait until state becomes stopped for session
# daemon(s).
local retval=0
- PID_CONSUMERD="$(pgrep "$CONSUMERD_MATCH")"
+ PID_CONSUMERD="$(pgrep -f "$CONSUMERD_MATCH")"
if [ -z "$PID_CONSUMERD" ]; then
if [ "$withtap" -eq "1" ]; then
else
out=1
while [ $out -ne 0 ]; do
- pid="$(pgrep "$CONSUMERD_MATCH")"
+ pid="$(pgrep -f "$CONSUMERD_MATCH")"
# If consumerds are still present check their status.
# A zombie status qualifies the consumerd as *killed*
local withtap=$1
local signal=SIGSTOP
- PID_CONSUMERD="$(pgrep "$CONSUMERD_MATCH")"
+ PID_CONSUMERD="$(pgrep -f "$CONSUMERD_MATCH")"
diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')"
else
out=1
while [ $out -ne 0 ]; do
- pid="$(pgrep "$CONSUMERD_MATCH")"
+ pid="$(pgrep -f "$CONSUMERD_MATCH")"
# Wait until state becomes stopped for all
# consumers.