Fix: Deny session creation name 'auto'
[lttng-tools.git] / src / lib / lttng-ctl / lttng-ctl.c
index c6238e11c81e17b746553725d2d062d67a22d2d3..bbe7cb4180dda914676714496fe31c56d09bf56e 100644 (file)
@@ -69,8 +69,6 @@ static int connected;
  * Those two variables are used by error.h to silent or control the verbosity of
  * error message. They are global to the library so application linking with it
  * are able to compile correctly and also control verbosity of the library.
- *
- * Note that it is *not* possible to silent ERR() and PERROR() macros.
  */
 int lttng_opt_quiet;
 int lttng_opt_verbose;
@@ -682,11 +680,11 @@ int lttng_start_tracing(const char *session_name)
 }
 
 /*
- *  Stop tracing for all traces of the session.
- *  Returns size of returned session payload data or a negative error code.
+ * Stop tracing for all traces of the session.
  */
-int lttng_stop_tracing(const char *session_name)
+static int _lttng_stop_tracing(const char *session_name, int wait)
 {
+       int ret, data_ret;
        struct lttcomm_session_msg lsm;
 
        if (session_name == NULL) {
@@ -697,7 +695,57 @@ int lttng_stop_tracing(const char *session_name)
 
        copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
 
-       return ask_sessiond(&lsm, NULL);
+       ret = ask_sessiond(&lsm, NULL);
+       if (ret < 0 && ret != -LTTNG_ERR_TRACE_ALREADY_STOPPED) {
+               goto error;
+       }
+
+       if (!wait) {
+               goto end;
+       }
+
+       _MSG("Waiting for data availability");
+
+       /* Check for data availability */
+       do {
+               data_ret = lttng_data_pending(session_name);
+               if (data_ret < 0) {
+                       /* Return the data available call error. */
+                       ret = data_ret;
+                       goto error;
+               }
+
+               /*
+                * Data sleep time before retrying (in usec). Don't sleep if the call
+                * returned value indicates availability.
+                */
+               if (data_ret) {
+                       usleep(DEFAULT_DATA_AVAILABILITY_WAIT_TIME);
+                       _MSG(".");
+               }
+       } while (data_ret != 0);
+
+       MSG("");
+
+end:
+error:
+       return ret;
+}
+
+/*
+ * Stop tracing and wait for data availability.
+ */
+int lttng_stop_tracing(const char *session_name)
+{
+       return _lttng_stop_tracing(session_name, 1);
+}
+
+/*
+ * Stop tracing but _don't_ wait for data availability.
+ */
+int lttng_stop_tracing_no_wait(const char *session_name)
+{
+       return _lttng_stop_tracing(session_name, 0);
 }
 
 /*
@@ -1558,7 +1606,8 @@ int _lttng_create_session_ext(const char *name, const char *url,
        memset(&lsm, 0, sizeof(lsm));
 
        lsm.cmd_type = LTTNG_CREATE_SESSION;
-       if (!strncmp(name, DEFAULT_SESSION_NAME, strlen(DEFAULT_SESSION_NAME))) {
+       if (!strncmp(name, DEFAULT_SESSION_NAME, strlen(DEFAULT_SESSION_NAME))
+                       && strlen(name) == strlen(DEFAULT_SESSION_NAME)) {
                ret = snprintf(lsm.session.name, sizeof(lsm.session.name), "%s-%s",
                                name, datetime);
                if (ret < 0) {
@@ -1577,7 +1626,7 @@ int _lttng_create_session_ext(const char *name, const char *url,
 
        lsm.u.uri.size = size;
 
-       if (uris[0].dtype != LTTNG_DST_PATH && strlen(uris[0].subdir) == 0) {
+       if (size > 0 && uris[0].dtype != LTTNG_DST_PATH && strlen(uris[0].subdir) == 0) {
                ret = snprintf(uris[0].subdir, sizeof(uris[0].subdir), "%s-%s", name,
                                datetime);
                if (ret < 0) {
@@ -1595,7 +1644,7 @@ int _lttng_create_session_ext(const char *name, const char *url,
  * or is still being extracted by the consumer(s) hence not ready to be used by
  * any readers.
  */
-int lttng_data_available(const char *session_name)
+int lttng_data_pending(const char *session_name)
 {
        int ret;
        struct lttcomm_session_msg lsm;
@@ -1604,7 +1653,7 @@ int lttng_data_available(const char *session_name)
                return -LTTNG_ERR_INVALID;
        }
 
-       lsm.cmd_type = LTTNG_DATA_AVAILABLE;
+       lsm.cmd_type = LTTNG_DATA_PENDING;
 
        copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
 
@@ -1632,3 +1681,11 @@ static void __attribute__((constructor)) init()
        /* Set socket for health check */
        (void) set_health_socket_path();
 }
+
+/*
+ * lib destructor
+ */
+static void __attribute__((destructor)) lttng_ctl_exit()
+{
+       free(tracing_group);
+}
This page took 0.024611 seconds and 4 git commands to generate.