Fix: Save tracker as part of UST and Kernel domains only
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 30 Aug 2015 22:55:52 +0000 (18:55 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Tue, 8 Sep 2015 13:06:27 +0000 (09:06 -0400)
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/save.c

index 8558b52195b9e3ac13720c6a7b5d4568989492a7..2f5a7fb2988a5eb9942194a677873125d019fd62 100644 (file)
@@ -1250,6 +1250,99 @@ const char *get_config_domain_str(enum lttng_domain_type domain)
        return str_dom;
 }
 
+static
+int save_pid_tracker(struct config_writer *writer,
+       struct ltt_session *sess, int domain)
+{
+       int ret = 0;
+       ssize_t nr_pids = 0, i;
+       int32_t *pids = NULL;
+
+       switch (domain) {
+       case LTTNG_DOMAIN_KERNEL:
+       {
+               nr_pids = kernel_list_tracker_pids(sess->kernel_session, &pids);
+               if (nr_pids < 0) {
+                       ret = LTTNG_ERR_KERN_LIST_FAIL;
+                       goto end;
+               }
+               break;
+       }
+       case LTTNG_DOMAIN_UST:
+       {
+               nr_pids = trace_ust_list_tracker_pids(sess->ust_session, &pids);
+               if (nr_pids < 0) {
+                       ret = LTTNG_ERR_UST_LIST_FAIL;
+                       goto end;
+               }
+               break;
+       }
+       case LTTNG_DOMAIN_JUL:
+       case LTTNG_DOMAIN_LOG4J:
+       case LTTNG_DOMAIN_PYTHON:
+       default:
+               ret = LTTNG_ERR_UNKNOWN_DOMAIN;
+               goto end;
+       }
+
+       /* Only create a pid_tracker if enabled or untrack all */
+       if (nr_pids != 1 || (nr_pids == 1 && pids[0] != -1)) {
+               ret = config_writer_open_element(writer,
+                               config_element_pid_tracker);
+               if (ret) {
+                       ret = LTTNG_ERR_SAVE_IO_FAIL;
+                       goto end;
+               }
+
+               ret = config_writer_open_element(writer,
+                               config_element_targets);
+               if (ret) {
+                       ret = LTTNG_ERR_SAVE_IO_FAIL;
+                       goto end;
+               }
+
+               for (i = 0; i < nr_pids; i++) {
+                       ret = config_writer_open_element(writer,
+                                       config_element_target_pid);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end;
+                       }
+
+                       ret = config_writer_write_element_unsigned_int(writer,
+                                       config_element_pid, pids[i]);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end;
+                       }
+
+                       /* /pid_target */
+                       ret = config_writer_close_element(writer);
+                       if (ret) {
+                               ret = LTTNG_ERR_SAVE_IO_FAIL;
+                               goto end;
+                       }
+               }
+
+               /* /targets */
+               ret = config_writer_close_element(writer);
+               if (ret) {
+                       ret = LTTNG_ERR_SAVE_IO_FAIL;
+                       goto end;
+               }
+
+               /* /pid_tracker */
+               ret = config_writer_close_element(writer);
+               if (ret) {
+                       ret = LTTNG_ERR_SAVE_IO_FAIL;
+                       goto end;
+               }
+       }
+end:
+       free(pids);
+       return ret;
+}
+
 static
 int save_ust_domain(struct config_writer *writer,
        struct ltt_session *session, enum lttng_domain_type domain)
@@ -1326,107 +1419,34 @@ int save_ust_domain(struct config_writer *writer,
                goto end;
        }
 
-       /* /domain */
-       ret = config_writer_close_element(writer);
-       if (ret) {
-               ret = LTTNG_ERR_SAVE_IO_FAIL;
-               goto end;
-       }
-
-end:
-       return ret;
-}
-
-static
-int save_pid_tracker(struct config_writer *writer,
-       struct ltt_session *sess, int domain)
-{
-       int ret = 0;
-       ssize_t nr_pids = 0, i;
-       int32_t *pids = NULL;
-
-       switch (domain) {
-       case LTTNG_DOMAIN_KERNEL:
-       {
-               nr_pids = kernel_list_tracker_pids(sess->kernel_session, &pids);
-               if (nr_pids < 0) {
-                       ret = LTTNG_ERR_KERN_LIST_FAIL;
-                       goto end;
-               }
-               break;
-       }
-       case LTTNG_DOMAIN_UST:
-       {
-               nr_pids = trace_ust_list_tracker_pids(sess->ust_session, &pids);
-               if (nr_pids < 0) {
-                       ret = LTTNG_ERR_UST_LIST_FAIL;
-                       goto end;
-               }
-               break;
-       }
-       case LTTNG_DOMAIN_JUL:
-       case LTTNG_DOMAIN_LOG4J:
-       case LTTNG_DOMAIN_PYTHON:
-       default:
-               ret = LTTNG_ERR_UNKNOWN_DOMAIN;
-               goto end;
-       }
-
-       /* Only create a pid_tracker if enabled or untrack all */
-       if (nr_pids != 1 || (nr_pids == 1 && pids[0] != -1)) {
+       if (domain == LTTNG_DOMAIN_UST) {
                ret = config_writer_open_element(writer,
-                               config_element_pid_tracker);
+                               config_element_trackers);
                if (ret) {
                        ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
                }
 
-               ret = config_writer_open_element(writer,
-                               config_element_targets);
+               ret = save_pid_tracker(writer, session, LTTNG_DOMAIN_UST);
                if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
                }
 
-               for (i = 0; i < nr_pids; i++) {
-                       ret = config_writer_open_element(writer,
-                                       config_element_target_pid);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       ret = config_writer_write_element_unsigned_int(writer,
-                                       config_element_pid, pids[i]);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-
-                       /* /pid_target */
-                       ret = config_writer_close_element(writer);
-                       if (ret) {
-                               ret = LTTNG_ERR_SAVE_IO_FAIL;
-                               goto end;
-                       }
-               }
-
-               /* /targets */
+               /* /trackers */
                ret = config_writer_close_element(writer);
                if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
                        goto end;
                }
+       }
 
-               /* /pid_tracker */
-               ret = config_writer_close_element(writer);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end;
-               }
+       /* /domain */
+       ret = config_writer_close_element(writer);
+       if (ret) {
+               ret = LTTNG_ERR_SAVE_IO_FAIL;
+               goto end;
        }
+
 end:
-       free(pids);
        return ret;
 }
 
@@ -1494,24 +1514,6 @@ int save_domains(struct config_writer *writer, struct ltt_session *session)
                        goto end;
                }
 
-               ret = config_writer_open_element(writer,
-                               config_element_trackers);
-               if (ret) {
-                       ret = LTTNG_ERR_SAVE_IO_FAIL;
-                       goto end;
-               }
-
-               ret = save_pid_tracker(writer, session, LTTNG_DOMAIN_UST);
-               if (ret) {
-                       goto end;
-               }
-
-               /* /trackers */
-               ret = config_writer_close_element(writer);
-               if (ret) {
-                       goto end;
-               }
-
                ret = save_ust_domain(writer, session, LTTNG_DOMAIN_JUL);
                if (ret) {
                        goto end;
This page took 0.028886 seconds and 4 git commands to generate.