From 4c1ee94e5ef9ac3efb4a036108a9ff4eb24c238c Mon Sep 17 00:00:00 2001 From: Mathieu Desnoyers Date: Wed, 22 Feb 2012 17:10:32 -0500 Subject: [PATCH] Revert "Add get proc name wrapper for FreeBSD" This reverts commit 48621a4272bdeb1e8fced511ca6bf3c4c2240c15. Signed-off-by: Mathieu Desnoyers --- liblttng-ust/compat.h | 52 +-------------------------- liblttng-ust/ltt-events.c | 10 +++--- liblttng-ust/lttng-context-procname.c | 17 +++++---- liblttng-ust/lttng-ust-comm.c | 9 +++-- 4 files changed, 25 insertions(+), 63 deletions(-) diff --git a/liblttng-ust/compat.h b/liblttng-ust/compat.h index 05b85a93..8ee4470a 100644 --- a/liblttng-ust/compat.h +++ b/liblttng-ust/compat.h @@ -14,13 +14,9 @@ * modified is included with the above copyright notice. */ -/* - * sched_getcpu. - */ -#ifdef __linux__ +#include #ifdef __UCLIBC__ -#include #define __getcpu(cpu, node, cache) syscall(__NR_getcpu, cpu, node, cache) static inline int sched_getcpu(void) @@ -31,50 +27,4 @@ int sched_getcpu(void) return (s == -1) ? s : c; } #endif /* __UCLIBC__ */ - -#else -#error "Please add support for your OS into liblttng-ust/compat.h." -#endif - -/* - * lttng_ust_getprocname. - */ -#ifdef __linux__ - -#include - -#define LTTNG_UST_PROCNAME_LEN 17 - -static inline -void lttng_ust_getprocname(char *name) -{ - (void) prctl(PR_GET_NAME, (unsigned long) name, 0, 0, 0); -} - -#elif defined(__FreeBSD__) -#include -#include - -/* - * Limit imposed by Linux UST-sessiond ABI. - */ -#define LTTNG_UST_PROCNAME_LEN 17 - -/* - * Acts like linux prctl, the string is not necessarily 0-terminated if - * 16-byte long. - */ -static inline -void lttng_ust_getprocname(char *name) -{ - const char *bsd_name; - - bsd_name = getprogname(); - if (!bsd_name) - name[0] = '\0'; - memcpy(name, bsd_name, LTTNG_UST_PROCNAME_LEN - 1); -} - -#endif - #endif /* _UST_COMPAT_H */ diff --git a/liblttng-ust/ltt-events.c b/liblttng-ust/ltt-events.c index c9d35dde..e42b6de6 100644 --- a/liblttng-ust/ltt-events.c +++ b/liblttng-ust/ltt-events.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include "clock.h" @@ -35,7 +36,6 @@ #include #include #include "error.h" -#include "compat.h" #include "tracepoint-internal.h" #include "ltt-tracer.h" @@ -44,6 +44,8 @@ #include "../libringbuffer/shm.h" #include "jhash.h" +#define PROCNAME_LEN 17 + /* * The sessions mutex is the centralized mutex across UST tracing * control and probe registration. All operations within this file are @@ -1091,7 +1093,7 @@ int _ltt_session_metadata_statedump(struct ltt_session *session) struct ltt_channel *chan; struct ltt_event *event; int ret = 0; - char procname[LTTNG_UST_PROCNAME_LEN] = ""; + char procname[PROCNAME_LEN] = ""; if (!CMM_ACCESS_ONCE(session->active)) return 0; @@ -1145,8 +1147,8 @@ int _ltt_session_metadata_statedump(struct ltt_session *session) goto end; /* ignore error, just use empty string if error. */ - lttng_ust_getprocname(procname); - procname[LTTNG_UST_PROCNAME_LEN - 1] = '\0'; + (void) prctl(PR_GET_NAME, (unsigned long) procname, 0, 0, 0); + procname[PROCNAME_LEN - 1] = '\0'; ret = lttng_metadata_printf(session, "env {\n" " vpid = %d;\n" diff --git a/liblttng-ust/lttng-context-procname.c b/liblttng-ust/lttng-context-procname.c index b737084b..b9bae82e 100644 --- a/liblttng-ust/lttng-context-procname.c +++ b/liblttng-ust/lttng-context-procname.c @@ -7,11 +7,13 @@ * Dual LGPL v2.1/GPL v2 license. */ +#include #include #include #include #include -#include "compat.h" + +#define PROCNAME_LEN 17 /* includes \0 */ /* * We cache the result to ensure we don't trigger a system call for @@ -24,9 +26,12 @@ static char cached_procname[17]; static inline char *wrapper_getprocname(void) { + int ret; + if (caa_unlikely(!cached_procname[0])) { - lttng_ust_getprocname(cached_procname); - cached_procname[LTTNG_UST_PROCNAME_LEN - 1] = '\0'; + ret = prctl(PR_GET_NAME, (unsigned long) cached_procname, + 0, 0, 0); + assert(!ret); } return cached_procname; } @@ -41,7 +46,7 @@ size_t procname_get_size(size_t offset) { size_t size = 0; - size += LTTNG_UST_PROCNAME_LEN; + size += PROCNAME_LEN; return size; } @@ -53,7 +58,7 @@ void procname_record(struct lttng_ctx_field *field, char *procname; procname = wrapper_getprocname(); - chan->ops->event_write(ctx, procname, LTTNG_UST_PROCNAME_LEN); + chan->ops->event_write(ctx, procname, PROCNAME_LEN); } int lttng_add_procname_to_ctx(struct lttng_ctx **ctx) @@ -76,7 +81,7 @@ int lttng_add_procname_to_ctx(struct lttng_ctx **ctx) field->event_field.type.u.array.elem_type.u.basic.integer.reverse_byte_order = 0; field->event_field.type.u.array.elem_type.u.basic.integer.base = 10; field->event_field.type.u.array.elem_type.u.basic.integer.encoding = lttng_encode_UTF8; - field->event_field.type.u.array.length = LTTNG_UST_PROCNAME_LEN; + field->event_field.type.u.array.length = PROCNAME_LEN; field->get_size = procname_get_size; field->record = procname_record; return 0; diff --git a/liblttng-ust/lttng-ust-comm.c b/liblttng-ust/lttng-ust-comm.c index 86cce18d..b3567dda 100644 --- a/liblttng-ust/lttng-ust-comm.c +++ b/liblttng-ust/lttng-ust-comm.c @@ -22,6 +22,7 @@ #define _LGPL_SOURCE #include #include +#include #include #include #include @@ -45,7 +46,6 @@ #include #include "tracepoint-internal.h" #include "ltt-tracer-core.h" -#include "compat.h" /* * Has lttng ust comm constructor been called ? @@ -159,6 +159,7 @@ static int register_app_to_sessiond(int socket) { ssize_t ret; + int prctl_ret; struct { uint32_t major; uint32_t minor; @@ -177,7 +178,11 @@ int register_app_to_sessiond(int socket) reg_msg.uid = getuid(); reg_msg.gid = getgid(); reg_msg.bits_per_long = CAA_BITS_PER_LONG; - lttng_ust_getprocname(reg_msg.name); + prctl_ret = prctl(PR_GET_NAME, (unsigned long) reg_msg.name, 0, 0, 0); + if (prctl_ret) { + ERR("Error executing prctl"); + return -errno; + } ret = ustcomm_send_unix_sock(socket, ®_msg, sizeof(reg_msg)); if (ret >= 0 && ret != sizeof(reg_msg)) -- 2.34.1