Add get proc name wrapper for FreeBSD
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Tue, 21 Feb 2012 00:52:30 +0000 (19:52 -0500)
committerChristian Babeux <christian.babeux@efficios.com>
Tue, 27 Nov 2012 19:55:18 +0000 (14:55 -0500)
commit 08114193d6fd56309b520ae50e7117b8bc7f34a5 upstream.

[ Edit by Christian Babeux: Resolve includes conflict in
  liblttng-ust/lttng-ust-comm.c ]

Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Signed-off-by: Christian Babeux <christian.babeux@efficios.com>
liblttng-ust/compat.h
liblttng-ust/ltt-events.c
liblttng-ust/lttng-context-procname.c
liblttng-ust/lttng-ust-comm.c

index 19d4da828b67cc793b056a46933d3b332c74b870..803cc12db912314192b9c07e62a7918a37e8dac6 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <sys/syscall.h>
+/*
+ * sched_getcpu.
+ */
+#ifdef __linux__
 
 #ifdef __UCLIBC__
+#include <sys/syscall.h>
 #define __getcpu(cpu, node, cache)     syscall(__NR_getcpu, cpu, node, cache)
 static inline
 int sched_getcpu(void)
@@ -32,4 +36,50 @@ 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 <sys/prctl.h>
+
+#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 <stdlib.h>
+#include <string.h>
+
+/*
+ * 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 */
index 775e73cad828f5119a8b3275b4f86470d55d07b9..5a624c492c4b3a4fae98c13857ae00be06bbb17b 100644 (file)
@@ -33,7 +33,6 @@
 #include <stddef.h>
 #include <inttypes.h>
 #include <time.h>
-#include <sys/prctl.h>
 #include <lttng/ust-endian.h>
 #include "clock.h"
 
@@ -48,6 +47,7 @@
 #include <usterr-signal-safe.h>
 #include <helper.h>
 #include "error.h"
+#include "compat.h"
 
 #include "tracepoint-internal.h"
 #include "ltt-tracer.h"
@@ -56,8 +56,6 @@
 #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
@@ -1106,7 +1104,7 @@ int _ltt_session_metadata_statedump(struct ltt_session *session)
        struct ltt_channel *chan;
        struct ltt_event *event;
        int ret = 0;
-       char procname[PROCNAME_LEN] = "";
+       char procname[LTTNG_UST_PROCNAME_LEN] = "";
 
        if (!CMM_ACCESS_ONCE(session->active))
                return 0;
@@ -1160,8 +1158,8 @@ int _ltt_session_metadata_statedump(struct ltt_session *session)
                goto end;
 
        /* ignore error, just use empty string if error. */
-       (void) prctl(PR_GET_NAME, (unsigned long) procname, 0, 0, 0);
-       procname[PROCNAME_LEN - 1] = '\0';
+       lttng_ust_getprocname(procname);
+       procname[LTTNG_UST_PROCNAME_LEN - 1] = '\0';
        ret = lttng_metadata_printf(session,
                "env {\n"
                "       vpid = %d;\n"
index caf86a95b65a509cb650e43a8c2ce10691d31dee..d165be88277daada8bbb616c2db60572050f9aa2 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
-#include <sys/prctl.h>
 #include <lttng/ust-events.h>
 #include <lttng/ust-tracer.h>
 #include <lttng/ringbuffer-config.h>
 #include <assert.h>
-
-#define PROCNAME_LEN   17      /* includes \0 */
+#include "compat.h"
 
 /*
  * We cache the result to ensure we don't trigger a system call for
@@ -39,12 +37,9 @@ static char cached_procname[17];
 static inline
 char *wrapper_getprocname(void)
 {
-       int ret;
-
        if (caa_unlikely(!cached_procname[0])) {
-               ret = prctl(PR_GET_NAME, (unsigned long) cached_procname,
-                       0, 0, 0);
-               assert(!ret);
+               lttng_ust_getprocname(cached_procname);
+               cached_procname[LTTNG_UST_PROCNAME_LEN - 1] = '\0';
        }
        return cached_procname;
 }
@@ -59,7 +54,7 @@ size_t procname_get_size(size_t offset)
 {
        size_t size = 0;
 
-       size += PROCNAME_LEN;
+       size += LTTNG_UST_PROCNAME_LEN;
        return size;
 }
 
@@ -71,7 +66,7 @@ void procname_record(struct lttng_ctx_field *field,
        char *procname;
 
        procname = wrapper_getprocname();
-       chan->ops->event_write(ctx, procname, PROCNAME_LEN);
+       chan->ops->event_write(ctx, procname, LTTNG_UST_PROCNAME_LEN);
 }
 
 int lttng_add_procname_to_ctx(struct lttng_ctx **ctx)
@@ -94,7 +89,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 = PROCNAME_LEN;
+       field->event_field.type.u.array.length = LTTNG_UST_PROCNAME_LEN;
        field->get_size = procname_get_size;
        field->record = procname_record;
        return 0;
index dece0ee6e70d42ef4982e545884a6f944e550fc8..af7928c3eda10fb0ea13ab01d99f5e01539b436c 100644 (file)
@@ -22,7 +22,6 @@
 #define _LGPL_SOURCE
 #include <sys/types.h>
 #include <sys/socket.h>
-#include <sys/prctl.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -46,6 +45,7 @@
 #include <usterr-signal-safe.h>
 #include "tracepoint-internal.h"
 #include "ltt-tracer-core.h"
+#include "compat.h"
 #include "../libringbuffer/tlsfixup.h"
 
 /*
@@ -177,7 +177,6 @@ static
 int register_app_to_sessiond(int socket)
 {
        ssize_t ret;
-       int prctl_ret;
        struct {
                uint32_t major;
                uint32_t minor;
@@ -196,11 +195,7 @@ int register_app_to_sessiond(int socket)
        reg_msg.uid = getuid();
        reg_msg.gid = getgid();
        reg_msg.bits_per_long = CAA_BITS_PER_LONG;
-       prctl_ret = prctl(PR_GET_NAME, (unsigned long) reg_msg.name, 0, 0, 0);
-       if (prctl_ret) {
-               ERR("Error executing prctl");
-               return -errno;
-       }
+       lttng_ust_getprocname(reg_msg.name);
 
        ret = ustcomm_send_unix_sock(socket, &reg_msg, sizeof(reg_msg));
        if (ret >= 0 && ret != sizeof(reg_msg))
This page took 0.028472 seconds and 4 git commands to generate.