Remove session list lock acquisition of the search
authorDavid Goulet <david.goulet@polymtl.ca>
Tue, 4 Oct 2011 20:24:10 +0000 (16:24 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Tue, 4 Oct 2011 20:24:10 +0000 (16:24 -0400)
The lock/unlock of the session list in the find session by name function
is removed thus the caller must held the lock before calling that search
function.

Also, the path and name are now static size on the stack and not
allocated strings at session creation.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
ltt-sessiond/main.c
ltt-sessiond/session.c
ltt-sessiond/session.h

index 46c98a5611b9e818c0c99e7e7a64bcd56a02b60e..d9c9d7b9a12923ab5c66c1eaff53ff6432c8cf69 100644 (file)
@@ -2525,7 +2525,9 @@ static int process_client_msg(struct command_ctx *cmd_ctx)
                break;
        default:
                DBG("Getting session %s by name", cmd_ctx->lsm->session.name);
+               session_lock_list();
                cmd_ctx->session = session_find_by_name(cmd_ctx->lsm->session.name);
+               session_unlock_list();
                if (cmd_ctx->session == NULL) {
                        if (cmd_ctx->lsm->session.name != NULL) {
                                ret = LTTCOMM_SESS_NOT_FOUND;
index ae83e45aec1b7610992772d48b35615a8adb1ba1..b35157bae40c13a381f2b54dea44c825101075bb 100644 (file)
@@ -113,29 +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;
 
        DBG2("Trying to find session by name %s", name);
 
-       session_lock_list();
        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;
 }
 
@@ -154,8 +150,6 @@ int session_destroy(struct ltt_session *session)
 
        DBG("Destroying session %s", session->name);
        del_session_list(session);
-       free(session->name);
-       free(session->path);
        pthread_mutex_destroy(&session->lock);
        free(session);
 
@@ -186,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;
                }
@@ -198,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;
                }
index 2f40f585d47f73b06c790577b98da7ed23e1677b..7db95ed1d6360b477030d26209c5b518c4d90cf7 100644 (file)
@@ -56,8 +56,8 @@ struct ltt_session_list {
  * session for both LTTng and UST.
  */
 struct ltt_session {
-       char *name;
-       char *path;
+       char name[NAME_MAX];
+       char path[PATH_MAX];
        struct ltt_kernel_session *kernel_session;
        struct ltt_ust_session_list ust_session_list;
        /*
This page took 0.030047 seconds and 4 git commands to generate.