Update documentation following babeltrace UI change
[lttng-tools.git] / ltt-sessiond / session.c
index aaca9f9370510a6765524fe27302c19ff192f3a4..b35157bae40c13a381f2b54dea44c825101075bb 100644 (file)
@@ -113,27 +113,25 @@ void session_unlock(struct ltt_session *session)
 }
 
 /*
- * Return a ltt_session structure ptr that matches name.
- * If no session found, NULL is returned.
+ * Return a ltt_session structure ptr that matches name. If no session found,
+ * NULL is returned. This must be called with the session lock held using
+ * session_lock_list and session_unlock_list.
  */
 struct ltt_session *session_find_by_name(char *name)
 {
-       int found = 0;
        struct ltt_session *iter;
 
-       session_lock_list();
+       DBG2("Trying to find session by name %s", name);
+
        cds_list_for_each_entry(iter, &ltt_session_list.head, list) {
                if (strncmp(iter->name, name, NAME_MAX) == 0) {
-                       found = 1;
-                       break;
+                       goto found;
                }
        }
-       session_unlock_list();
 
-       if (!found) {
-               iter = NULL;
-       }
+       iter = NULL;
 
+found:
        return iter;
 }
 
@@ -142,23 +140,18 @@ struct ltt_session *session_find_by_name(char *name)
  *
  * Return -1 if no session is found.  On success, return 1;
  */
-int session_destroy(char *name)
+int session_destroy(struct ltt_session *session)
 {
-       struct ltt_session *iter, *tmp;
-
-       session_lock_list();
-       cds_list_for_each_entry_safe(iter, tmp, &ltt_session_list.head, list) {
-               if (strcmp(iter->name, name) == 0) {
-                       DBG("Destroying session %s", iter->name);
-                       del_session_list(iter);
-                       free(iter->name);
-                       free(iter->path);
-                       pthread_mutex_destroy(&iter->lock);
-                       free(iter);
-                       break;
-               }
+       /* Safety check */
+       if (session == NULL) {
+               ERR("Session pointer was null on session destroy");
+               return LTTCOMM_OK;
        }
-       session_unlock_list();
+
+       DBG("Destroying session %s", session->name);
+       del_session_list(session);
+       pthread_mutex_destroy(&session->lock);
+       free(session);
 
        return LTTCOMM_OK;
 }
@@ -187,7 +180,7 @@ int session_create(char *name, char *path)
 
        /* Define session name */
        if (name != NULL) {
-               if (asprintf(&new_session->name, "%s", name) < 0) {
+               if (snprintf(new_session->name, NAME_MAX, "%s", name) < 0) {
                        ret = LTTCOMM_FATAL;
                        goto error_asprintf;
                }
@@ -199,7 +192,7 @@ int session_create(char *name, char *path)
 
        /* Define session system path */
        if (path != NULL) {
-               if (asprintf(&new_session->path, "%s", path) < 0) {
+               if (snprintf(new_session->path, PATH_MAX, "%s", path) < 0) {
                        ret = LTTCOMM_FATAL;
                        goto error_asprintf;
                }
This page took 0.024293 seconds and 4 git commands to generate.