+/*
+ * This is an extension of create session that is ONLY and SHOULD only be used
+ * by the lttng command line program. It exists to avoid using URI parsing in
+ * the lttng client.
+ *
+ * We need the date and time for the trace path subdirectory for the case where
+ * the user does NOT define one using either -o or -U. Using the normal
+ * lttng_create_session API call, we have no clue on the session daemon side if
+ * the URL was generated automatically by the client or define by the user.
+ *
+ * So this function "wrapper" is hidden from the public API, takes the datetime
+ * string and appends it if necessary to the URI subdirectory before sending it
+ * to the session daemon.
+ *
+ * With this extra function, the lttng_create_session call behavior is not
+ * changed and the timestamp is appended to the URI on the session daemon side
+ * if necessary.
+ */
+int _lttng_create_session_ext(const char *name, const char *url,
+ const char *datetime)
+{
+ int ret;
+ ssize_t size;
+ struct lttcomm_session_msg lsm;
+ struct lttng_uri *uris = NULL;
+
+ if (name == NULL || datetime == NULL || url == NULL) {
+ return -LTTNG_ERR_INVALID;
+ }
+
+ memset(&lsm, 0, sizeof(lsm));
+
+ lsm.cmd_type = LTTNG_CREATE_SESSION;
+ copy_string(lsm.session.name, name, sizeof(lsm.session.name));
+
+ /* There should never be a data URL */
+ size = parse_str_urls_to_uri(url, NULL, &uris);
+ if (size < 0) {
+ ret = -LTTNG_ERR_INVALID;
+ goto error;
+ }
+
+ lsm.u.uri.size = size;
+
+ 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) {
+ PERROR("snprintf uri subdir");
+ ret = -LTTNG_ERR_FATAL;
+ goto error;
+ }
+ }
+
+ ret = ask_sessiond_varlen(&lsm, uris, sizeof(struct lttng_uri) * size,
+ NULL);
+
+error:
+ free(uris);
+ return ret;
+}
+
+/*
+ * For a given session name, this call checks if the data is ready to be read
+ * or is still being extracted by the consumer(s) hence not ready to be used by
+ * any readers.
+ */
+int lttng_data_pending(const char *session_name)
+{
+ int ret;
+ struct lttcomm_session_msg lsm;
+
+ if (session_name == NULL) {
+ return -LTTNG_ERR_INVALID;
+ }
+
+ lsm.cmd_type = LTTNG_DATA_PENDING;
+
+ copy_string(lsm.session.name, session_name, sizeof(lsm.session.name));
+
+ ret = ask_sessiond(&lsm, NULL);
+
+ /*
+ * The ask_sessiond function negate the return code if it's not LTTNG_OK so
+ * getting -1 means that the reply ret_code was 1 thus meaning that the
+ * data is available. Yes it is hackish but for now this is the only way.
+ */
+ if (ret == -1) {
+ ret = 1;
+ }
+
+ return ret;
+}
+