Implement UST PID tracker
[lttng-tools.git] / src / bin / lttng-sessiond / cmd.c
index 06b015f937e3e12f2d2a360a3ac6223d3588b64b..9ae5cff392d49ae67ea83eeb99acf1340bf19508 100644 (file)
@@ -912,11 +912,106 @@ int cmd_disable_channel(struct ltt_session *session, int domain,
                }
                break;
        }
-#if 0
-       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
-       case LTTNG_DOMAIN_UST_EXEC_NAME:
-       case LTTNG_DOMAIN_UST_PID:
-#endif
+       default:
+               ret = LTTNG_ERR_UNKNOWN_DOMAIN;
+               goto error;
+       }
+
+       ret = LTTNG_OK;
+
+error:
+       rcu_read_unlock();
+       return ret;
+}
+
+/*
+ * Command LTTNG_TRACK_PID processed by the client thread.
+ *
+ * Called with session lock held.
+ */
+int cmd_track_pid(struct ltt_session *session, int domain, int pid)
+{
+       int ret;
+
+       rcu_read_lock();
+
+       switch (domain) {
+       case LTTNG_DOMAIN_KERNEL:
+       {
+               struct ltt_kernel_session *ksess;
+
+               ksess = session->kernel_session;
+
+               ret = kernel_track_pid(ksess, pid);
+               if (ret != LTTNG_OK) {
+                       goto error;
+               }
+
+               kernel_wait_quiescent(kernel_tracer_fd);
+               break;
+       }
+       case LTTNG_DOMAIN_UST:
+       {
+               struct ltt_ust_session *usess;
+
+               usess = session->ust_session;
+
+               ret = trace_ust_track_pid(usess, pid);
+               if (ret != LTTNG_OK) {
+                       goto error;
+               }
+               break;
+       }
+       default:
+               ret = LTTNG_ERR_UNKNOWN_DOMAIN;
+               goto error;
+       }
+
+       ret = LTTNG_OK;
+
+error:
+       rcu_read_unlock();
+       return ret;
+}
+
+/*
+ * Command LTTNG_UNTRACK_PID processed by the client thread.
+ *
+ * Called with session lock held.
+ */
+int cmd_untrack_pid(struct ltt_session *session, int domain, int pid)
+{
+       int ret;
+
+       rcu_read_lock();
+
+       switch (domain) {
+       case LTTNG_DOMAIN_KERNEL:
+       {
+               struct ltt_kernel_session *ksess;
+
+               ksess = session->kernel_session;
+
+               ret = kernel_untrack_pid(ksess, pid);
+               if (ret != LTTNG_OK) {
+                       goto error;
+               }
+
+               kernel_wait_quiescent(kernel_tracer_fd);
+               break;
+       }
+       case LTTNG_DOMAIN_UST:
+       {
+               struct ltt_ust_session *usess;
+
+               usess = session->ust_session;
+
+               ret = trace_ust_untrack_pid(usess, pid);
+               if (ret != LTTNG_OK) {
+                       goto error;
+               }
+               break;
+       }
        default:
                ret = LTTNG_ERR_UNKNOWN_DOMAIN;
                goto error;
@@ -1186,11 +1281,6 @@ int cmd_disable_event(struct ltt_session *session, int domain,
 
                break;
        }
-#if 0
-       case LTTNG_DOMAIN_UST_EXEC_NAME:
-       case LTTNG_DOMAIN_UST_PID:
-       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
-#endif
        default:
                ret = LTTNG_ERR_UND;
                goto error;
@@ -1330,11 +1420,6 @@ int cmd_add_context(struct ltt_session *session, int domain,
                }
                break;
        }
-#if 0
-       case LTTNG_DOMAIN_UST_EXEC_NAME:
-       case LTTNG_DOMAIN_UST_PID:
-       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
-#endif
        default:
                ret = LTTNG_ERR_UND;
                goto error;
@@ -1661,11 +1746,6 @@ int cmd_enable_event(struct ltt_session *session, struct lttng_domain *domain,
 
                break;
        }
-#if 0
-       case LTTNG_DOMAIN_UST_EXEC_NAME:
-       case LTTNG_DOMAIN_UST_PID:
-       case LTTNG_DOMAIN_UST_PID_FOLLOW_CHILDREN:
-#endif
        default:
                ret = LTTNG_ERR_UND;
                goto error;
@@ -1871,6 +1951,8 @@ ssize_t cmd_list_syscalls(struct lttng_event **events)
 
 /*
  * Command LTTNG_START_TRACE processed by the client thread.
+ *
+ * Called with session mutex held.
  */
 int cmd_start_trace(struct ltt_session *session)
 {
@@ -2231,6 +2313,8 @@ error:
 
 /*
  * Command LTTNG_DESTROY_SESSION processed by the client thread.
+ *
+ * Called with session lock held.
  */
 int cmd_destroy_session(struct ltt_session *session, int wpipe)
 {
@@ -3152,7 +3236,7 @@ int cmd_snapshot_record(struct ltt_session *session,
        int ret = LTTNG_OK;
        unsigned int use_tmp_output = 0;
        struct snapshot_output tmp_output;
-       unsigned int nb_streams, snapshot_success = 0;
+       unsigned int snapshot_success = 0;
 
        assert(session);
        assert(output);
@@ -3333,6 +3417,29 @@ error:
        return ret;
 }
 
+/*
+ * Command LTTNG_SET_SESSION_SHM_PATH processed by the client thread.
+ */
+int cmd_set_session_shm_path(struct ltt_session *session,
+               const char *shm_path)
+{
+       /* Safety net */
+       assert(session);
+
+       /*
+        * Can only set shm path before session is started.
+        */
+       if (session->has_been_started) {
+               return LTTNG_ERR_SESSION_STARTED;
+       }
+
+       strncpy(session->shm_path, shm_path,
+               sizeof(session->shm_path));
+       session->shm_path[sizeof(session->shm_path) - 1] = '\0';
+
+       return 0;
+}
+
 /*
  * Init command subsystem.
  */
This page took 0.025702 seconds and 4 git commands to generate.