kevent = trace_kernel_find_event(event->name, kchan,
event->type, filter);
if (kevent == NULL) {
- ret = kernel_create_event(event, kchan,
- filter_expression, filter);
+ ret = kernel_create_event(event, kchan, filter_expression, filter);
/* We have passed ownership */
filter_expression = NULL;
filter = NULL;
- if (ret < 0) {
- switch (-ret) {
- case EEXIST:
- ret = LTTNG_ERR_KERN_EVENT_EXIST;
- break;
- case ENOSYS:
- ret = LTTNG_ERR_KERN_EVENT_ENOSYS;
- break;
- default:
- ret = LTTNG_ERR_KERN_ENABLE_FAIL;
- break;
- }
+ if (ret) {
goto end;
}
} else if (kevent->enabled == 0) {
char *filter_expression,
struct lttng_filter_bytecode *filter)
{
- int ret;
+ int err, fd;
+ enum lttng_error_code ret;
struct ltt_kernel_event *event;
assert(ev);
assert(channel);
/* We pass ownership of filter_expression and filter */
- event = trace_kernel_create_event(ev, filter_expression,
- filter);
- if (event == NULL) {
- ret = -1;
+ ret = trace_kernel_create_event(ev, filter_expression,
+ filter, &event);
+ if (ret != LTTNG_OK) {
goto error;
}
- ret = kernctl_create_event(channel->fd, event->event);
- if (ret < 0) {
- switch (-ret) {
+ fd = kernctl_create_event(channel->fd, event->event);
+ if (fd < 0) {
+ switch (-fd) {
case EEXIST:
+ ret = LTTNG_ERR_KERN_EVENT_EXIST;
break;
case ENOSYS:
WARN("Event type not implemented");
+ ret = LTTNG_ERR_KERN_EVENT_ENOSYS;
break;
case ENOENT:
WARN("Event %s not found!", ev->name);
+ ret = LTTNG_ERR_KERN_ENABLE_FAIL;
break;
default:
+ ret = LTTNG_ERR_KERN_ENABLE_FAIL;
PERROR("create event ioctl");
}
goto free_event;
}
event->type = ev->type;
- event->fd = ret;
+ event->fd = fd;
/* Prevent fd duplication after execlp() */
- ret = fcntl(event->fd, F_SETFD, FD_CLOEXEC);
- if (ret < 0) {
+ err = fcntl(event->fd, F_SETFD, FD_CLOEXEC);
+ if (err < 0) {
PERROR("fcntl session fd");
}
if (filter) {
- ret = kernctl_filter(event->fd, filter);
- if (ret) {
+ err = kernctl_filter(event->fd, filter);
+ if (err < 0) {
+ switch (-err) {
+ case ENOMEM:
+ ret = LTTNG_ERR_FILTER_NOMEM;
+ break;
+ default:
+ ret = LTTNG_ERR_FILTER_INVAL;
+ break;
+ }
goto filter_error;
}
}
- ret = kernctl_enable(event->fd);
- if (ret < 0) {
- switch (-ret) {
+ err = kernctl_enable(event->fd);
+ if (err < 0) {
+ switch (-err) {
case EEXIST:
ret = LTTNG_ERR_KERN_EVENT_EXIST;
break;
default:
PERROR("enable kernel event");
+ ret = LTTNG_ERR_KERN_ENABLE_FAIL;
break;
}
goto enable_error;
*
* Return pointer to structure or NULL.
*/
-struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev,
- char *filter_expression, struct lttng_filter_bytecode *filter)
+enum lttng_error_code trace_kernel_create_event(
+ struct lttng_event *ev, char *filter_expression,
+ struct lttng_filter_bytecode *filter,
+ struct ltt_kernel_event **kernel_event)
{
- struct ltt_kernel_event *lke;
+ enum lttng_error_code ret;
struct lttng_kernel_event *attr;
+ struct ltt_kernel_event *local_kernel_event;
assert(ev);
- lke = zmalloc(sizeof(struct ltt_kernel_event));
+ local_kernel_event = zmalloc(sizeof(struct ltt_kernel_event));
attr = zmalloc(sizeof(struct lttng_kernel_event));
- if (lke == NULL || attr == NULL) {
+ if (local_kernel_event == NULL || attr == NULL) {
PERROR("kernel event zmalloc");
+ ret = LTTNG_ERR_NOMEM;
goto error;
}
break;
default:
ERR("Unknown kernel instrumentation type (%d)", ev->type);
+ ret = LTTNG_ERR_INVALID;
goto error;
}
attr->name[LTTNG_KERNEL_SYM_NAME_LEN - 1] = '\0';
/* Setting up a kernel event */
- lke->fd = -1;
- lke->event = attr;
- lke->enabled = 1;
- lke->filter_expression = filter_expression;
- lke->filter = filter;
+ local_kernel_event->fd = -1;
+ local_kernel_event->event = attr;
+ local_kernel_event->enabled = 1;
+ local_kernel_event->filter_expression = filter_expression;
+ local_kernel_event->filter = filter;
- return lke;
+ *kernel_event = local_kernel_event;
+
+ return LTTNG_OK;
error:
free(filter_expression);
free(filter);
- free(lke);
+ free(local_kernel_event);
free(attr);
- return NULL;
+ return ret;
}
/*
struct ltt_kernel_session *trace_kernel_create_session(void);
struct ltt_kernel_channel *trace_kernel_create_channel(
struct lttng_channel *chan);
-struct ltt_kernel_event *trace_kernel_create_event(struct lttng_event *ev,
- char *filter_expression, struct lttng_filter_bytecode *filter);
+enum lttng_error_code trace_kernel_create_event(struct lttng_event *ev,
+ char *filter_expression, struct lttng_filter_bytecode *filter,
+ struct ltt_kernel_event **kernel_event);
struct ltt_kernel_metadata *trace_kernel_create_metadata(void);
struct ltt_kernel_stream *trace_kernel_create_stream(const char *name,
unsigned int count);
static void test_create_kernel_event(void)
{
+ enum lttng_error_code ret;
struct ltt_kernel_event *event;
struct lttng_event ev;
ev.type = LTTNG_EVENT_TRACEPOINT;
ev.loglevel_type = LTTNG_EVENT_LOGLEVEL_ALL;
- event = trace_kernel_create_event(&ev, NULL, NULL);
- ok(event != NULL, "Create kernel event");
+ ret = trace_kernel_create_event(&ev, NULL, NULL, &event);
+ ok(ret == LTTNG_OK, "Create kernel event");
if (!event) {
skip(1, "Event is null");