run_as: add extract SDT probe offsets command
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 28 Jun 2018 18:33:10 +0000 (14:33 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 24 Aug 2018 19:57:46 +0000 (15:57 -0400)
Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Signed-off-by: Erica Bugden <ebugden@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/common/lttng-kernel.h
src/common/runas-stub.c
src/common/runas.c
src/common/runas.h

index 9d6d60c404f885a6388969962356940c4a870319..922da33c84108a71c7ddee04b5ebfcce61b20934 100644 (file)
 
 #include <stdint.h>
 #include <common/macros.h>
+#include <lttng/constant.h>
+#include <lttng/event.h>
 
 #define LTTNG_KERNEL_SYM_NAME_LEN  256
+#define LTTNG_KERNEL_MAX_UPROBE_NUM  32
 
 /*
  * LTTng DebugFS ABI structures.
index 99b44d32acf44fca676b107b950cc9e0b31456fa..7af8b6e0c5df3ee98f14be195dfe9373a79037c5 100644 (file)
@@ -45,6 +45,11 @@ int lttng_elf_get_symbol_offset(int fd, char *symbol, uint64_t *offset)
 {
        return -1;
 }
+int lttng_elf_get_sdt_probe_offsets(int fd, const char *provider_name,
+               const char *probe_name, uint64_t **offsets, uint32_t *nb_probe)
+{
+       return -1;
+}
 int run_as_create_worker(char *procname)
 {
        return -1;
index bed25a46368d61d875939acd1461e0b98a3af4cb..3916d6754314eadd4947b576dbcb4d98273ad861 100644 (file)
@@ -32,6 +32,7 @@
 #include <assert.h>
 #include <signal.h>
 
+#include <common/lttng-kernel.h>
 #include <common/common.h>
 #include <common/utils.h>
 #include <common/compat/getenv.h>
@@ -71,6 +72,11 @@ struct run_as_extract_elf_symbol_offset_data {
        char function[LTTNG_SYMBOL_NAME_LEN];
 };
 
+struct run_as_extract_sdt_probe_offsets_data {
+       char probe_name[LTTNG_SYMBOL_NAME_LEN];
+       char provider_name[LTTNG_SYMBOL_NAME_LEN];
+};
+
 struct run_as_mkdir_ret {
        int ret;
 };
@@ -91,6 +97,11 @@ struct run_as_extract_elf_symbol_offset_ret {
        uint64_t offset;
 };
 
+struct run_as_extract_sdt_probe_offsets_ret {
+       uint32_t num_offset;
+       uint64_t offsets[LTTNG_KERNEL_MAX_UPROBE_NUM];
+};
+
 enum run_as_cmd {
        RUN_AS_MKDIR,
        RUN_AS_OPEN,
@@ -98,6 +109,7 @@ enum run_as_cmd {
        RUN_AS_RMDIR_RECURSIVE,
        RUN_AS_MKDIR_RECURSIVE,
        RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET,
+       RUN_AS_EXTRACT_SDT_PROBE_OFFSETS,
 };
 
 struct run_as_data {
@@ -109,6 +121,7 @@ struct run_as_data {
                struct run_as_unlink_data unlink;
                struct run_as_rmdir_recursive_data rmdir_recursive;
                struct run_as_extract_elf_symbol_offset_data extract_elf_symbol_offset;
+               struct run_as_extract_sdt_probe_offsets_data extract_sdt_probe_offsets;
        } u;
        uid_t uid;
        gid_t gid;
@@ -137,6 +150,7 @@ struct run_as_ret {
                struct run_as_unlink_ret unlink;
                struct run_as_rmdir_recursive_ret rmdir_recursive;
                struct run_as_extract_elf_symbol_offset_ret extract_elf_symbol_offset;
+               struct run_as_extract_sdt_probe_offsets_ret extract_sdt_probe_offsets;
        } u;
        int _errno;
        bool _error;
@@ -244,6 +258,46 @@ int _extract_elf_symbol_offset(struct run_as_data *data,
        return ret;
 }
 
+static
+int _extract_sdt_probe_offsets(struct run_as_data *data,
+               struct run_as_ret *ret_value)
+{
+       int ret = 0;
+       uint64_t *offsets = NULL;
+       uint32_t num_offset;
+
+       ret_value->_error = false;
+
+       /* On success, this call allocates the offsets paramater. */
+       ret = lttng_elf_get_sdt_probe_offsets(data->fd,
+                       data->u.extract_sdt_probe_offsets.provider_name,
+                       data->u.extract_sdt_probe_offsets.probe_name,
+                       &offsets, &num_offset);
+
+       if (ret) {
+               DBG("Failed to extract SDT probe offsets");
+               ret_value->_error = true;
+               goto end;
+       }
+
+       if (num_offset <= 0 || num_offset > LTTNG_KERNEL_MAX_UPROBE_NUM) {
+               DBG("Wrong number of probes.");
+               ret = -1;
+               ret_value->_error = true;
+               goto free_offset;
+       }
+
+       /* Copy the content of the offsets array to the ret struct. */
+       memcpy(ret_value->u.extract_sdt_probe_offsets.offsets,
+                       offsets, num_offset * sizeof(uint64_t));
+
+       ret_value->u.extract_sdt_probe_offsets.num_offset = num_offset;
+
+free_offset:
+       free(offsets);
+end:
+       return ret;
+}
 
 static
 run_as_fct run_as_enum_to_fct(enum run_as_cmd cmd)
@@ -261,6 +315,8 @@ run_as_fct run_as_enum_to_fct(enum run_as_cmd cmd)
                return _mkdir_recursive;
        case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
                return _extract_elf_symbol_offset;
+       case RUN_AS_EXTRACT_SDT_PROBE_OFFSETS:
+               return _extract_sdt_probe_offsets;
        default:
                ERR("Unknown command %d", (int) cmd);
                return NULL;
@@ -313,6 +369,7 @@ int send_fd_to_worker(struct run_as_worker *worker, enum run_as_cmd cmd, int fd)
 
        switch (cmd) {
        case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
+       case RUN_AS_EXTRACT_SDT_PROBE_OFFSETS:
                break;
        default:
                return 0;
@@ -381,6 +438,7 @@ int recv_fd_from_master(struct run_as_worker *worker, enum run_as_cmd cmd, int *
 
        switch (cmd) {
        case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
+       case RUN_AS_EXTRACT_SDT_PROBE_OFFSETS:
                break;
        default:
                return 0;
@@ -402,6 +460,7 @@ int cleanup_received_fd(enum run_as_cmd cmd, int fd)
 
        switch (cmd) {
        case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
+       case RUN_AS_EXTRACT_SDT_PROBE_OFFSETS:
                break;
        default:
                return 0;
@@ -415,6 +474,7 @@ int cleanup_received_fd(enum run_as_cmd cmd, int fd)
 
        return ret;
 }
+
 /*
  * Return < 0 on error, 0 if OK, 1 on hangup.
  */
@@ -875,6 +935,45 @@ int run_as_extract_elf_symbol_offset(int fd, const char* function,
        return 0;
 }
 
+LTTNG_HIDDEN
+int run_as_extract_sdt_probe_offsets(int fd, const char* provider_name,
+               const char* probe_name, uid_t uid, gid_t gid,
+               uint64_t **offsets, uint32_t *num_offset)
+{
+       struct run_as_data data;
+       struct run_as_ret ret;
+
+       DBG3("extract_sdt_probe_offsets() on fd=%d, probe_name=%s and "
+               "provider_name=%s with for uid %d and gid %d", fd, probe_name,
+               provider_name, (int) uid, (int) gid);
+
+       data.fd = fd;
+
+       strncpy(data.u.extract_sdt_probe_offsets.probe_name, probe_name, LTTNG_SYMBOL_NAME_LEN - 1);
+       strncpy(data.u.extract_sdt_probe_offsets.provider_name, provider_name, LTTNG_SYMBOL_NAME_LEN - 1);
+
+       data.u.extract_sdt_probe_offsets.probe_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+       data.u.extract_sdt_probe_offsets.provider_name[LTTNG_SYMBOL_NAME_LEN - 1] = '\0';
+
+       run_as(RUN_AS_EXTRACT_SDT_PROBE_OFFSETS, &data, &ret, uid, gid);
+
+       errno = ret._errno;
+
+       if (ret._error) {
+               return -1;
+       }
+
+       *num_offset = ret.u.extract_sdt_probe_offsets.num_offset;
+
+       *offsets = zmalloc(*num_offset * sizeof(uint64_t));
+       if (!*offsets) {
+               return -ENOMEM;
+       }
+
+       memcpy(*offsets, ret.u.extract_sdt_probe_offsets.offsets, *num_offset * sizeof(uint64_t));
+       return 0;
+}
+
 static
 int reset_sighandler(void)
 {
index 098d5c3aa41143440759f043ad41dd0978911895..ba6482f69a9c91746673983b0f89462ae8a58df9 100644 (file)
@@ -19,9 +19,9 @@
  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
+#include <stdint.h>
 #include <sys/types.h>
 #include <unistd.h>
-#include <pthread.h>
 
 LTTNG_HIDDEN
 int run_as_mkdir_recursive(const char *path, mode_t mode, uid_t uid, gid_t gid);
@@ -37,6 +37,10 @@ LTTNG_HIDDEN
 int run_as_extract_elf_symbol_offset(int fd, const char* function,
                uid_t uid, gid_t gid, uint64_t *offset);
 LTTNG_HIDDEN
+int run_as_extract_sdt_probe_offsets(int fd, const char *provider_name,
+               const char* probe_name, uid_t uid, gid_t gid,
+               uint64_t **offsets, uint32_t *num_offset);
+LTTNG_HIDDEN
 int run_as_create_worker(char *procname);
 LTTNG_HIDDEN
 void run_as_destroy_worker(void);
This page took 0.028717 seconds and 4 git commands to generate.