*
* 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, <t_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);
+ free(session->name);
+ free(session->path);
+ pthread_mutex_destroy(&session->lock);
+ free(session);
return LTTCOMM_OK;
}
/* Prototypes */
int session_create(char *name, char *path);
-int session_destroy(char *name);
+int session_destroy(struct ltt_session *session);
void session_lock(struct ltt_session *session);
void session_lock_list(void);
/*
* Test deletion of 1 session
*/
-static int destroy_one_session(char *name)
+static int destroy_one_session(struct ltt_session *session)
{
int ret;
- ret = session_destroy(name);
+ ret = session_destroy(session);
if (ret == LTTCOMM_OK) {
/* Validate */
- ret = find_session_name(name);
+ if (session == NULL) {
+ return 0;
+ }
+ ret = find_session_name(session->name);
if (ret < 0) {
/* Success, -1 means that the sesion is NOT found */
return 0;
return -1;
}
- ret = destroy_one_session(OVERFLOW_SESSION_NAME);
- if (ret > 0) {
- printf("Session destroyed with %s\n", OVERFLOW_SESSION_NAME);
- return -1;
- }
-
/* Session list must be 0 */
assert(!session_list->count);
PRINT_OK();
printf("Destroy 1 session %s: ", SESSION1);
- ret = destroy_one_session(SESSION1);
+ ret = destroy_one_session(tmp);
if (ret < 0) {
return -1;
}
printf("Destroying %d sessions: ", MAX_SESSIONS);
for (i = 0; i < MAX_SESSIONS; i++) {
cds_list_for_each_entry_safe(iter, tmp, &session_list->head, list) {
- ret = destroy_one_session(iter->name);
+ ret = destroy_one_session(iter);
if (ret < 0) {
printf("session %d (name: %s) creation failed\n", i, iter->name);
return -1;