#include <assert.h>
#include <signal.h>
+#include <common/lttng-kernel.h>
#include <common/common.h>
#include <common/utils.h>
#include <common/compat/getenv.h>
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;
};
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,
RUN_AS_RMDIR_RECURSIVE,
RUN_AS_MKDIR_RECURSIVE,
RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET,
+ RUN_AS_EXTRACT_SDT_PROBE_OFFSETS,
};
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;
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;
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)
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;
switch (cmd) {
case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
+ case RUN_AS_EXTRACT_SDT_PROBE_OFFSETS:
break;
default:
return 0;
switch (cmd) {
case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
+ case RUN_AS_EXTRACT_SDT_PROBE_OFFSETS:
break;
default:
return 0;
switch (cmd) {
case RUN_AS_EXTRACT_ELF_SYMBOL_OFFSET:
+ case RUN_AS_EXTRACT_SDT_PROBE_OFFSETS:
break;
default:
return 0;
return ret;
}
+
/*
* Return < 0 on error, 0 if OK, 1 on hangup.
*/
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)
{
* 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);
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);