/*
* SPDX-License-Identifier: GPL-2.0-only
*
- * Copyright (C) 2011 Julien Desfossez <julien.desfossez@polymtl.ca>
+ * Copyright (C) 2011 EfficiOS Inc.
* Copyright (C) 2011-2013 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
*/
return 0;
}
+/*
+ * Protocol for LTTNG_UST_ABI_CONTEXT command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - send: var len ctx_name
+ * - receive: struct ustcomm_ust_reply
+ *
+ * TODO: At the next breaking protocol bump, we should indicate the total
+ * command message length as part of a message header so that the protocol can
+ * recover from invalid command errors.
+ */
int lttng_ust_ctl_add_context(int sock, struct lttng_ust_context_attr *ctx,
struct lttng_ust_abi_object_data *obj_data,
struct lttng_ust_abi_object_data **_context_data)
}
ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
if (ret < 0) {
+ if (ret == -EINVAL) {
+ /*
+ * Command unknown from remote end. The communication socket is
+ * now out-of-sync and needs to be shutdown.
+ */
+ (void) ustcomm_shutdown_unix_sock(sock);
+ }
goto end;
}
context_data->handle = -1;
return ret;
}
+/*
+ * Protocol for LTTNG_UST_ABI_FILTER command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - send: var len bytecode
+ * - receive: struct ustcomm_ust_reply
+ *
+ * TODO: At the next breaking protocol bump, we should indicate the total
+ * command message length as part of a message header so that the protocol can
+ * recover from invalid command errors.
+ */
int lttng_ust_ctl_set_filter(int sock, struct lttng_ust_abi_filter_bytecode *bytecode,
struct lttng_ust_abi_object_data *obj_data)
{
}
if (ret != bytecode->len)
return -EINVAL;
- return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
+ ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
+ if (ret == -EINVAL) {
+ /*
+ * Command unknown from remote end. The communication socket is
+ * now out-of-sync and needs to be shutdown.
+ */
+ (void) ustcomm_shutdown_unix_sock(sock);
+ }
+ return ret;
}
+/*
+ * Protocol for LTTNG_UST_ABI_CAPTURE command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - receive: struct ustcomm_ust_reply
+ * - send: var len bytecode
+ * - receive: struct ustcomm_ust_reply (actual command return code)
+ */
int lttng_ust_ctl_set_capture(int sock, struct lttng_ust_abi_capture_bytecode *bytecode,
struct lttng_ust_abi_object_data *obj_data)
{
lum.u.capture.reloc_offset = bytecode->reloc_offset;
lum.u.capture.seqnum = bytecode->seqnum;
- ret = ustcomm_send_app_msg(sock, &lum);
+ ret = ustcomm_send_app_cmd(sock, &lum, &lur);
if (ret)
return ret;
/* send var len bytecode */
return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
}
+/*
+ * Protocol for LTTNG_UST_ABI_EXCLUSION command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - send: var len exclusion names
+ * - receive: struct ustcomm_ust_reply
+ *
+ * TODO: At the next breaking protocol bump, we should indicate the total
+ * command message length as part of a message header so that the protocol can
+ * recover from invalid command errors.
+ */
int lttng_ust_ctl_set_exclusion(int sock, struct lttng_ust_abi_event_exclusion *exclusion,
struct lttng_ust_abi_object_data *obj_data)
{
if (ret != exclusion->count * LTTNG_UST_ABI_SYM_NAME_LEN) {
return -EINVAL;
}
- return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
+ ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
+ if (ret == -EINVAL) {
+ /*
+ * Command unknown from remote end. The communication socket is
+ * now out-of-sync and needs to be shutdown.
+ */
+ (void) ustcomm_shutdown_unix_sock(sock);
+ }
+ return ret;
}
/* Enable event, channel and session ioctl */
return lttng_ust_ctl_disable(sock, &obj);
}
+/*
+ * Protocol for LTTNG_UST_ABI_EVENT_NOTIFIER_GROUP_CREATE command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - receive: struct ustcomm_ust_reply
+ * - send: file descriptor
+ * - receive: struct ustcomm_ust_reply (actual command return code)
+ */
int lttng_ust_ctl_create_event_notifier_group(int sock, int pipe_fd,
struct lttng_ust_abi_object_data **_event_notifier_group_data)
{
lum.handle = LTTNG_UST_ABI_ROOT_HANDLE;
lum.cmd = LTTNG_UST_ABI_EVENT_NOTIFIER_GROUP_CREATE;
- ret = ustcomm_send_app_msg(sock, &lum);
+ ret = ustcomm_send_app_cmd(sock, &lum, &lur);
if (ret)
goto error;
return ret;
}
+/*
+ * Protocol for LTTNG_UST_ABI_EVENT_NOTIFIER_CREATE command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - receive: struct ustcomm_ust_reply
+ * - send: struct lttng_ust_abi_event_notifier
+ * - receive: struct ustcomm_ust_reply (actual command return code)
+ */
int lttng_ust_ctl_create_event_notifier(int sock, struct lttng_ust_abi_event_notifier *event_notifier,
struct lttng_ust_abi_object_data *event_notifier_group,
struct lttng_ust_abi_object_data **_event_notifier_data)
lum.cmd = LTTNG_UST_ABI_EVENT_NOTIFIER_CREATE;
lum.u.event_notifier.len = sizeof(*event_notifier);
- ret = ustcomm_send_app_msg(sock, &lum);
+ ret = ustcomm_send_app_cmd(sock, &lum, &lur);
if (ret) {
free(event_notifier_data);
return ret;
return ret;
}
+/*
+ * Protocol for LTTNG_UST_ABI_CHANNEL command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - send: file descriptors and channel data
+ * - receive: struct ustcomm_ust_reply
+ *
+ * TODO: At the next breaking protocol bump, we should indicate the total
+ * command message length as part of a message header so that the protocol can
+ * recover from invalid command errors.
+ */
int lttng_ust_ctl_send_channel_to_ust(int sock, int session_handle,
struct lttng_ust_abi_object_data *channel_data)
{
ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
if (!ret) {
channel_data->handle = lur.ret_val;
+ } else if (ret == -EINVAL) {
+ /*
+ * Command unknown from remote end. The communication socket is
+ * now out-of-sync and needs to be shutdown.
+ */
+ (void) ustcomm_shutdown_unix_sock(sock);
}
return ret;
}
+/*
+ * Protocol for LTTNG_UST_ABI_STREAM command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - send: file descriptors and stream data
+ * - receive: struct ustcomm_ust_reply
+ *
+ * TODO: At the next breaking protocol bump, we should indicate the total
+ * command message length as part of a message header so that the protocol can
+ * recover from invalid command errors.
+ */
int lttng_ust_ctl_send_stream_to_ust(int sock,
struct lttng_ust_abi_object_data *channel_data,
struct lttng_ust_abi_object_data *stream_data)
stream_data->u.stream.wakeup_fd, 1);
if (ret)
return ret;
- return ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
+ ret = ustcomm_recv_app_reply(sock, &lur, lum.handle, lum.cmd);
+ if (ret == -EINVAL) {
+ /*
+ * Command unknown from remote end. The communication socket is
+ * now out-of-sync and needs to be shutdown.
+ */
+ (void) ustcomm_shutdown_unix_sock(sock);
+ }
+ return ret;
}
int lttng_ust_ctl_duplicate_ust_object_data(struct lttng_ust_abi_object_data **dest,
obj->u.channel.wakeup_fd =
dup(src->u.channel.wakeup_fd);
if (obj->u.channel.wakeup_fd < 0) {
- ret = errno;
+ ret = -errno;
goto chan_error_wakeup_fd;
}
} else {
obj->u.stream.wakeup_fd =
dup(src->u.stream.wakeup_fd);
if (obj->u.stream.wakeup_fd < 0) {
- ret = errno;
+ ret = -errno;
goto stream_error_wakeup_fd;
}
} else {
obj->u.stream.shm_fd =
dup(src->u.stream.shm_fd);
if (obj->u.stream.shm_fd < 0) {
- ret = errno;
+ ret = -errno;
goto stream_error_shm_fd;
}
} else {
obj->u.counter_global.shm_fd =
dup(src->u.counter_global.shm_fd);
if (obj->u.counter_global.shm_fd < 0) {
- ret = errno;
+ ret = -errno;
goto error_type;
}
}
obj->u.counter_cpu.shm_fd =
dup(src->u.counter_cpu.shm_fd);
if (obj->u.counter_cpu.shm_fd < 0) {
- ret = errno;
+ ret = -errno;
goto error_type;
}
}
int lttng_ust_ctl_get_nr_stream_per_channel(void)
{
- return num_possible_cpus();
+ return get_possible_cpus_array_len();
}
struct lttng_ust_ctl_consumer_channel *
/*
* Override application uid/gid with unix socket credentials. Use the
* first group of the cr_groups.
- * Use the pid and ppid provided by the application on registration.
*/
static
int get_cred(int sock,
socklen_t xucred_len = sizeof(struct xucred);
int ret;
- ret = getsockopt(sock, SOL_SOCKET, LOCAL_PEERCRED, &xucred, &xucred_len);
+ ret = getsockopt(sock, SOL_LOCAL, LOCAL_PEERCRED, &xucred, &xucred_len);
if (ret) {
return -LTTNG_UST_ERR_PEERCRED;
}
if (xucred.cr_version != XUCRED_VERSION || xucred.cr_ngroups < 1) {
return -LTTNG_UST_ERR_PEERCRED;
}
- DBG("Unix socket peercred [ uid: %u, gid: %u ], "
- "application registered claiming [ pid: %d, ppid: %d, uid: %u, gid: %u ]",
- xucred.cr_uid, xucred.cr_groups[0],
+ DBG("Unix socket peercred [ pid: %u, uid: %u, gid: %u ], "
+ "application registered claiming [ pid: %u, ppid: %u, uid: %u, gid: %u ]",
+ xucred.cr_pid, xucred.cr_uid, xucred.cr_groups[0],
reg_msg->pid, reg_msg->ppid, reg_msg->uid, reg_msg->gid);
- *pid = reg_msg->pid;
- *ppid = reg_msg->ppid;
+ *pid = xucred.cr_pid;
*uid = xucred.cr_uid;
*gid = xucred.cr_groups[0];
+ if (xucred.cr_pid == reg_msg->pid) {
+ *ppid = reg_msg->ppid;
+ } else {
+ *ppid = 0;
+ }
return 0;
}
#else
int lttng_ust_ctl_get_nr_cpu_per_counter(void)
{
- return num_possible_cpus();
+ return get_possible_cpus_array_len();
}
struct lttng_ust_ctl_daemon_counter *
free(counter);
}
+/*
+ * Protocol for LTTNG_UST_ABI_COUNTER command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - receive: struct ustcomm_ust_reply
+ * - send: counter data
+ * - receive: struct ustcomm_ust_reply (actual command return code)
+ */
int lttng_ust_ctl_send_counter_data_to_ust(int sock, int parent_handle,
struct lttng_ust_abi_object_data *counter_data)
{
lum.handle = parent_handle;
lum.cmd = LTTNG_UST_ABI_COUNTER;
lum.u.counter.len = size;
- ret = ustcomm_send_app_msg(sock, &lum);
+ ret = ustcomm_send_app_cmd(sock, &lum, &lur);
if (ret)
return ret;
return ret;
}
+/*
+ * Protocol for LTTNG_UST_ABI_COUNTER_GLOBAL command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - receive: struct ustcomm_ust_reply
+ * - send: file descriptor
+ * - receive: struct ustcomm_ust_reply (actual command return code)
+ */
int lttng_ust_ctl_send_counter_global_data_to_ust(int sock,
struct lttng_ust_abi_object_data *counter_data,
struct lttng_ust_abi_object_data *counter_global_data)
lum.handle = counter_data->handle; /* parent handle */
lum.cmd = LTTNG_UST_ABI_COUNTER_GLOBAL;
lum.u.counter_global.len = size;
- ret = ustcomm_send_app_msg(sock, &lum);
+ ret = ustcomm_send_app_cmd(sock, &lum, &lur);
if (ret)
return ret;
return ret;
}
+/*
+ * Protocol for LTTNG_UST_ABI_COUNTER_CPU command:
+ *
+ * - send: struct ustcomm_ust_msg
+ * - receive: struct ustcomm_ust_reply
+ * - send: file descriptor
+ * - receive: struct ustcomm_ust_reply (actual command return code)
+ */
int lttng_ust_ctl_send_counter_cpu_data_to_ust(int sock,
struct lttng_ust_abi_object_data *counter_data,
struct lttng_ust_abi_object_data *counter_cpu_data)
lum.cmd = LTTNG_UST_ABI_COUNTER_CPU;
lum.u.counter_cpu.len = size;
lum.u.counter_cpu.cpu_nr = counter_cpu_data->u.counter_cpu.cpu_nr;
- ret = ustcomm_send_app_msg(sock, &lum);
+ ret = ustcomm_send_app_cmd(sock, &lum, &lur);
if (ret)
return ret;
return counter->ops->counter_clear(counter->counter, dimension_indexes);
}
+int lttng_ust_ctl_get_version(uint32_t *major, uint32_t *minor,
+ uint32_t *patchlevel) {
+ *major = LTTNG_UST_MAJOR_VERSION;
+ *minor = LTTNG_UST_MINOR_VERSION;
+ *patchlevel = LTTNG_UST_PATCHLEVEL_VERSION;
+ return 0;
+}
+
static
void lttng_ust_ctl_ctor(void)
__attribute__((constructor));