Add UST namespace contexts
[lttng-tools.git] / src / bin / lttng-sessiond / save.c
index c03b17ea8e312a85db5c5b2d44c7ebc458a600a4..6c7ca6757ea4cf9bbf9dd936dd2e141c91fc683e 100644 (file)
@@ -215,16 +215,16 @@ const char *get_kernel_instrumentation_string(
                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_UPROBE:
                instrumentation_string = config_event_type_userspace_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;
@@ -294,6 +294,27 @@ const char *get_kernel_context_type_string(
        case LTTNG_KERNEL_CONTEXT_CALLSTACK_KERNEL:
                context_type_string = config_event_context_callstack_kernel;
                break;
+       case LTTNG_KERNEL_CONTEXT_CGROUP_NS:
+               context_type_string = config_event_context_cgroup_ns;
+               break;
+       case LTTNG_KERNEL_CONTEXT_IPC_NS:
+               context_type_string = config_event_context_ipc_ns;
+               break;
+       case LTTNG_KERNEL_CONTEXT_MNT_NS:
+               context_type_string = config_event_context_mnt_ns;
+               break;
+       case LTTNG_KERNEL_CONTEXT_NET_NS:
+               context_type_string = config_event_context_net_ns;
+               break;
+       case LTTNG_KERNEL_CONTEXT_PID_NS:
+               context_type_string = config_event_context_pid_ns;
+               break;
+       case LTTNG_KERNEL_CONTEXT_USER_NS:
+               context_type_string = config_event_context_user_ns;
+               break;
+       case LTTNG_KERNEL_CONTEXT_UTS_NS:
+               context_type_string = config_event_context_uts_ns;
+               break;
        default:
                context_type_string = NULL;
        }
@@ -326,6 +347,27 @@ const char *get_ust_context_type_string(
        case LTTNG_UST_CONTEXT_APP_CONTEXT:
                context_type_string = config_event_context_app;
                break;
+       case LTTNG_UST_CONTEXT_CGROUP_NS:
+               context_type_string = config_event_context_cgroup_ns;
+               break;
+       case LTTNG_UST_CONTEXT_IPC_NS:
+               context_type_string = config_event_context_ipc_ns;
+               break;
+       case LTTNG_UST_CONTEXT_MNT_NS:
+               context_type_string = config_event_context_mnt_ns;
+               break;
+       case LTTNG_UST_CONTEXT_NET_NS:
+               context_type_string = config_event_context_net_ns;
+               break;
+       case LTTNG_UST_CONTEXT_PID_NS:
+               context_type_string = config_event_context_pid_ns;
+               break;
+       case LTTNG_UST_CONTEXT_USER_NS:
+               context_type_string = config_event_context_user_ns;
+               break;
+       case LTTNG_UST_CONTEXT_UTS_NS:
+               context_type_string = config_event_context_uts_ns;
+               break;
        case LTTNG_UST_CONTEXT_PERF_THREAD_COUNTER:
                /*
                 * Error, should not be stored in the XML, perf contexts
@@ -504,8 +546,8 @@ int save_kernel_userspace_probe_tracepoint_event(struct config_writer *writer,
 {
        int ret = 0;
        const char *probe_name, *provider_name, *binary_path;
-       struct lttng_userspace_probe_location *userspace_probe_location;
-       struct lttng_userspace_probe_location_lookup_method *lookup_method;
+       const struct lttng_userspace_probe_location *userspace_probe_location;
+       const struct lttng_userspace_probe_location_lookup_method *lookup_method;
        enum lttng_userspace_probe_location_lookup_method_type lookup_type;
 
        /* Get userspace probe location from the event. */
@@ -618,8 +660,8 @@ int save_kernel_userspace_probe_function_event(struct config_writer *writer,
 {
        int ret = 0;
        const char *function_name, *binary_path;
-       struct lttng_userspace_probe_location *userspace_probe_location;
-       struct lttng_userspace_probe_location_lookup_method *lookup_method;
+       const struct lttng_userspace_probe_location *userspace_probe_location;
+       const struct lttng_userspace_probe_location_lookup_method *lookup_method;
        enum lttng_userspace_probe_location_lookup_method_type lookup_type;
 
        /* Get userspace probe location from the event. */
@@ -2245,6 +2287,9 @@ int save_session_rotation_schedules(struct config_writer *writer,
 
        ret = config_writer_open_element(writer,
                        config_element_rotation_schedules);
+       if (ret) {
+               goto end;
+       }
        if (session->rotate_timer_period) {
                ret = save_session_rotation_schedule(writer,
                                LTTNG_ROTATION_SCHEDULE_TYPE_PERIODIC,
@@ -2281,13 +2326,13 @@ static
 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);
@@ -2298,7 +2343,7 @@ int save_session(struct ltt_session *session,
 
        if (!session_access_ok(session,
                LTTNG_SOCK_GET_UID_CRED(creds),
-               LTTNG_SOCK_GET_GID_CRED(creds))) {
+               LTTNG_SOCK_GET_GID_CRED(creds)) || session->destroyed) {
                ret = LTTNG_ERR_EPERM;
                goto end;
        }
@@ -2311,7 +2356,7 @@ int save_session(struct ltt_session *session,
                        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(
@@ -2355,27 +2400,34 @@ int save_session(struct ltt_session *session,
         * 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) {
@@ -2489,12 +2541,12 @@ end:
        }
        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 (file_opened) {
+       if (fd >= 0) {
                ret = close(fd);
                if (ret) {
                        PERROR("Closing XML session configuration");
@@ -2524,6 +2576,7 @@ int cmd_save_sessions(struct lttng_save_session_attr *attr,
                session_lock(session);
                ret = save_session(session, attr, creds);
                session_unlock(session);
+               session_put(session);
                if (ret) {
                        goto end;
                }
@@ -2531,10 +2584,13 @@ int cmd_save_sessions(struct lttng_save_session_attr *attr,
                struct ltt_session_list *list = session_get_list();
 
                cds_list_for_each_entry(session, &list->head, list) {
+                       if (!session_get(session)) {
+                               continue;
+                       }
                        session_lock(session);
                        ret = save_session(session, attr, creds);
                        session_unlock(session);
-
+                       session_put(session);
                        /* Don't abort if we don't have the required permissions. */
                        if (ret && ret != LTTNG_ERR_EPERM) {
                                goto end;
This page took 0.026619 seconds and 4 git commands to generate.