instrumentation_string = config_event_type_tracepoint;
break;
case LTTNG_KERNEL_KPROBE:
- instrumentation_string = config_event_type_kprobe;
+ instrumentation_string = config_event_type_probe;
break;
case LTTNG_KERNEL_FUNCTION:
- instrumentation_string = config_event_type_function;
+ instrumentation_string = config_event_type_function_entry;
break;
case LTTNG_KERNEL_KRETPROBE:
- instrumentation_string = config_event_type_kretprobe;
+ instrumentation_string = config_event_type_function;
break;
case LTTNG_KERNEL_NOOP:
instrumentation_string = config_event_type_noop;
case LTTNG_KERNEL_CONTEXT_HOSTNAME:
context_type_string = config_event_context_hostname;
break;
+ case LTTNG_KERNEL_CONTEXT_INTERRUPTIBLE:
+ context_type_string = config_event_context_interruptible;
+ break;
+ case LTTNG_KERNEL_CONTEXT_PREEMPTIBLE:
+ context_type_string = config_event_context_preemptible;
+ break;
+ case LTTNG_KERNEL_CONTEXT_NEED_RESCHEDULE:
+ context_type_string = config_event_context_need_reschedule;
+ break;
+ case LTTNG_KERNEL_CONTEXT_MIGRATABLE:
+ context_type_string = config_event_context_migratable;
+ break;
default:
context_type_string = NULL;
}
return ret;
}
-static
-int save_kernel_syscall(struct config_writer *writer,
- struct ltt_kernel_channel *kchan)
-{
- int ret, i;
- ssize_t count;
- struct lttng_event *events = NULL;
-
- assert(writer);
- assert(kchan);
-
- count = syscall_list_channel(kchan, &events, 0);
- if (!count) {
- /* No syscalls, just gracefully return. */
- ret = 0;
- goto end;
- }
-
- for (i = 0; i < count; i++) {
- struct ltt_kernel_event *kevent;
-
- /* Create a temporary kevent in order to save it. */
- /*
- * TODO: struct lttng_event does not really work for a filter,
- * but unfortunately, it is exposed as external API (and used as
- * internal representation. Using NULL meanwhile.
- */
- kevent = trace_kernel_create_event(&events[i],
- NULL, NULL);
- if (!kevent) {
- ret = -ENOMEM;
- goto end;
- }
- /* Init list in order so the destroy call can del the node. */
- CDS_INIT_LIST_HEAD(&kevent->list);
-
- ret = save_kernel_event(writer, kevent);
- trace_kernel_destroy_event(kevent);
- if (ret) {
- goto end;
- }
- }
-
- /* Everything went well */
- ret = 0;
-
-end:
- free(events);
- return ret;
-}
-
static
int save_kernel_events(struct config_writer *writer,
struct ltt_kernel_channel *kchan)
}
}
- /* Save syscalls if any. */
- ret = save_kernel_syscall(writer, kchan);
- if (ret) {
- goto end;
- }
-
/* /events */
ret = config_writer_close_element(writer);
if (ret) {
ust_event->enabled = agent_event->enabled;
ust_event->attr.instrumentation = LTTNG_UST_TRACEPOINT;
- strncpy(ust_event->attr.name, agent_event->name, LTTNG_SYMBOL_NAME_LEN);
+ if (lttng_strncpy(ust_event->attr.name, agent_event->name,
+ LTTNG_SYMBOL_NAME_LEN)) {
+ ret = -1;
+ goto end;
+ }
switch (agent_event->loglevel_type) {
case LTTNG_EVENT_LOGLEVEL_ALL:
ust_loglevel_type = LTTNG_UST_LOGLEVEL_ALL;
int save_session(struct ltt_session *session,
struct lttng_save_session_attr *attr, lttng_sock_cred *creds)
{
- int ret, fd;
- unsigned int file_opened = 0; /* Indicate if the file has been opened */
- char config_file_path[PATH_MAX];
+ int ret, fd = -1;
+ char config_file_path[LTTNG_PATH_MAX];
size_t len;
struct config_writer *writer = NULL;
size_t session_name_len;
const char *provided_path;
+ int file_open_flags = O_CREAT | O_WRONLY | O_TRUNC;
assert(session);
assert(attr);
ret = LTTNG_ERR_SET_URL;
goto end;
}
- strncpy(config_file_path, provided_path, len);
+ strncpy(config_file_path, provided_path, sizeof(config_file_path));
} else {
ssize_t ret_len;
char *home_dir = utils_get_user_home_dir(
* was done just above.
*/
config_file_path[len++] = '/';
- strncpy(config_file_path + len, session->name, session_name_len);
+ strncpy(config_file_path + len, session->name, sizeof(config_file_path) - len);
len += session_name_len;
strcpy(config_file_path + len, DEFAULT_SESSION_CONFIG_FILE_EXTENSION);
len += sizeof(DEFAULT_SESSION_CONFIG_FILE_EXTENSION);
config_file_path[len] = '\0';
- if (!access(config_file_path, F_OK) && !attr->overwrite) {
- /* File exists, notify the user since the overwrite flag is off. */
- ret = LTTNG_ERR_SAVE_FILE_EXIST;
- goto end;
+ if (!attr->overwrite) {
+ file_open_flags |= O_EXCL;
}
- fd = run_as_open(config_file_path, O_CREAT | O_WRONLY | O_TRUNC,
+ fd = run_as_open(config_file_path, file_open_flags,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP,
LTTNG_SOCK_GET_UID_CRED(creds), LTTNG_SOCK_GET_GID_CRED(creds));
if (fd < 0) {
PERROR("Could not create configuration file");
- ret = LTTNG_ERR_SAVE_IO_FAIL;
+ switch (errno) {
+ case EEXIST:
+ ret = LTTNG_ERR_SAVE_FILE_EXIST;
+ break;
+ case EACCES:
+ ret = LTTNG_ERR_EPERM;
+ break;
+ default:
+ ret = LTTNG_ERR_SAVE_IO_FAIL;
+ break;
+ }
goto end;
}
- file_opened = 1;
writer = config_writer_create(fd, 1);
if (!writer) {
}
if (ret) {
/* Delete file in case of error */
- if (file_opened && unlink(config_file_path)) {
+ if ((fd >= 0) && unlink(config_file_path)) {
PERROR("Unlinking XML session configuration.");
}
}
+ if (fd >= 0) {
+ ret = close(fd);
+ if (ret) {
+ PERROR("Closing XML session configuration");
+ }
+ }
+
return ret;
}