From: Mathieu Desnoyers Date: Mon, 21 Nov 2011 15:55:25 +0000 (+0100) Subject: Allocate session UID with count increment X-Git-Tag: v2.0-pre15~91 X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=commitdiff_plain;h=44e96653751b3d75c823abc6275d8e732738c789 Allocate session UID with count increment Otherwise, the UST session UID gets assigned only when the first UST channel is created for a session, causing IDs to be used for many sessions (the count of the number of sessions allocated so far) if the session creation / channel creation is not performed in a usual sequence. Signed-off-by: Mathieu Desnoyers --- diff --git a/lttng-sessiond/main.c b/lttng-sessiond/main.c index d5b4c8db2..7fe0f9a4b 100644 --- a/lttng-sessiond/main.c +++ b/lttng-sessiond/main.c @@ -1780,10 +1780,7 @@ static int create_ust_session(struct ltt_session *session, DBG("Creating UST session"); - session_lock_list(); - uid = session_list_ptr->count; - session_unlock_list(); - + uid = session->uid; lus = trace_ust_create_session(session->path, uid, domain); if (lus == NULL) { ret = LTTCOMM_UST_SESS_FAIL; diff --git a/lttng-sessiond/session.c b/lttng-sessiond/session.c index 2ab49485f..bf16f76cb 100644 --- a/lttng-sessiond/session.c +++ b/lttng-sessiond/session.c @@ -55,11 +55,12 @@ static struct ltt_session_list ltt_session_list = { * Add a ltt_session structure to the global list. * * The caller MUST acquire the session list lock before. + * Returns the unique identifier for the session. */ -static void add_session_list(struct ltt_session *ls) +static int add_session_list(struct ltt_session *ls) { cds_list_add(&ls->list, <t_session_list.head); - ltt_session_list.count++; + return ++ltt_session_list.count; } /* @@ -215,10 +216,10 @@ int session_create(char *name, char *path) /* Add new session to the session list */ session_lock_list(); - add_session_list(new_session); + new_session->uid = add_session_list(new_session); session_unlock_list(); - DBG("Tracing session %s created in %s", name, path); + DBG("Tracing session %s created in %s with UID %d", name, path, new_session->uid); return LTTCOMM_OK; diff --git a/lttng-sessiond/session.h b/lttng-sessiond/session.h index 2d077a4bc..9d8bd32aa 100644 --- a/lttng-sessiond/session.h +++ b/lttng-sessiond/session.h @@ -68,6 +68,7 @@ struct ltt_session { pthread_mutex_t lock; struct cds_list_head list; int enabled; /* enabled/started flag */ + int uid; }; /* Prototypes */