Implement UST PID tracker
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.c
index 0041969657e18089c8a957c941924363a752daaf..c2210f48aa484c94393003e9f5b782ddbc5770c4 100644 (file)
@@ -221,19 +221,19 @@ int lttng_check_tracing_group(void)
        /* Get number of supplementary group IDs */
        grp_list_size = getgroups(0, NULL);
        if (grp_list_size < 0) {
-               perror("getgroups");
+               PERROR("getgroups");
                goto end;
        }
 
        /* Alloc group list of the right size */
        grp_list = zmalloc(grp_list_size * sizeof(gid_t));
        if (!grp_list) {
-               perror("malloc");
+               PERROR("malloc");
                goto end;
        }
        grp_id = getgroups(grp_list_size, grp_list);
        if (grp_id < 0) {
-               perror("getgroups");
+               PERROR("getgroups");
                goto free_list;
        }
 
@@ -275,7 +275,7 @@ static int try_connect_sessiond(const char *sock_path)
 
        ret = lttcomm_close_unix_sock(ret);
        if (ret < 0) {
-               perror("lttcomm_close_unix_sock");
+               PERROR("lttcomm_close_unix_sock");
        }
 
        return 0;
@@ -858,7 +858,7 @@ static int generate_filter(char *filter_expression,
 
        /* No need to keep the memory stream. */
        if (fclose(fmem) != 0) {
-               perror("fclose");
+               PERROR("fclose");
        }
 
        *ctxp = ctx;
@@ -869,7 +869,7 @@ parse_error:
        filter_parser_ctx_free(ctx);
 filter_alloc_error:
        if (fclose(fmem) != 0) {
-               perror("fclose");
+               PERROR("fclose");
        }
 error:
        return ret;
@@ -1216,6 +1216,7 @@ int lttng_disable_event(struct lttng_handle *handle, const char *name,
        struct lttng_event ev;
 
        memset(&ev, 0, sizeof(ev));
+       ev.loglevel = -1;
        ev.type = LTTNG_EVENT_ALL;
        lttng_ctl_copy_string(ev.name, name, sizeof(ev.name));
        return lttng_disable_event_ext(handle, &ev, channel_name, NULL);
@@ -1279,6 +1280,62 @@ int lttng_disable_channel(struct lttng_handle *handle, const char *name)
        return lttng_ctl_ask_sessiond(&lsm, NULL);
 }
 
+/*
+ *  Add PID to session tracker.
+ *  Return 0 on success else a negative LTTng error code.
+ */
+int lttng_track_pid(struct lttng_handle *handle, int pid)
+{
+       struct lttcomm_session_msg lsm;
+
+       /*
+        * NULL arguments are forbidden. No default values.
+        */
+       if (handle == NULL) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       memset(&lsm, 0, sizeof(lsm));
+
+       lsm.cmd_type = LTTNG_TRACK_PID;
+       lsm.u.pid_tracker.pid = pid;
+
+       lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
+
+       lttng_ctl_copy_string(lsm.session.name, handle->session_name,
+                       sizeof(lsm.session.name));
+
+       return lttng_ctl_ask_sessiond(&lsm, NULL);
+}
+
+/*
+ *  Remove PID from session tracker.
+ *  Return 0 on success else a negative LTTng error code.
+ */
+int lttng_untrack_pid(struct lttng_handle *handle, int pid)
+{
+       struct lttcomm_session_msg lsm;
+
+       /*
+        * NULL arguments are forbidden. No default values.
+        */
+       if (handle == NULL) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       memset(&lsm, 0, sizeof(lsm));
+
+       lsm.cmd_type = LTTNG_UNTRACK_PID;
+       lsm.u.pid_tracker.pid = pid;
+
+       lttng_ctl_copy_lttng_domain(&lsm.domain, &handle->domain);
+
+       lttng_ctl_copy_string(lsm.session.name, handle->session_name,
+                       sizeof(lsm.session.name));
+
+       return lttng_ctl_ask_sessiond(&lsm, NULL);
+}
+
 /*
  *  Lists all available tracepoints of domain.
  *  Sets the contents of the events array.
@@ -1451,6 +1508,26 @@ int lttng_list_sessions(struct lttng_session **sessions)
        return ret / sizeof(struct lttng_session);
 }
 
+int lttng_set_session_shm_path(const char *session_name,
+               const char *shm_path)
+{
+       struct lttcomm_session_msg lsm;
+
+       if (session_name == NULL) {
+               return -LTTNG_ERR_INVALID;
+       }
+
+       memset(&lsm, 0, sizeof(lsm));
+       lsm.cmd_type = LTTNG_SET_SESSION_SHM_PATH;
+
+       lttng_ctl_copy_string(lsm.session.name, session_name,
+                       sizeof(lsm.session.name));
+       lttng_ctl_copy_string(lsm.u.set_shm_path.shm_path, shm_path,
+                       sizeof(lsm.u.set_shm_path.shm_path));
+
+       return lttng_ctl_ask_sessiond(&lsm, NULL);
+}
+
 /*
  *  Ask the session daemon for all available domains of a session.
  *  Sets the contents of the domains array.
This page took 0.02537 seconds and 4 git commands to generate.