Fix runas namespace
[lttng-tools.git] / lttng-sessiond / session.c
index 2ab49485f738a9d3c45df96ba91baed4a397794b..1a79fd564b40da5d7d26d29c1ba276003cedeac0 100644 (file)
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
 #include <urcu.h>
 
 #include <lttng-sessiond-comm.h>
 #include <lttngerr.h>
 
-#include "hashtable.h"
+#include "common/runas.h"
 #include "session.h"
 
-#include "../hashtable/hash.h"
-
 /*
  * NOTES:
  *
@@ -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, &ltt_session_list.head);
-       ltt_session_list.count++;
+       return ++ltt_session_list.count;
 }
 
 /*
@@ -163,7 +164,7 @@ int session_destroy(struct ltt_session *session)
 /*
  * Create a brand new session and add it to the session list.
  */
-int session_create(char *name, char *path)
+int session_create(char *name, char *path, uid_t uid, gid_t gid)
 {
        int ret;
        struct ltt_session *new_session;
@@ -213,12 +214,27 @@ int session_create(char *name, char *path)
        /* Init lock */
        pthread_mutex_init(&new_session->lock, NULL);
 
+       new_session->uid = uid;
+       new_session->gid = gid;
+
+       ret = run_as_mkdir_recursive(new_session->path, S_IRWXU | S_IRWXG,
+                       new_session->uid, new_session->gid);
+       if (ret < 0) {
+               if (ret != -EEXIST) {
+                       ERR("Trace directory creation error");
+                       ret = LTTCOMM_CREATE_FAIL;
+                       goto error;
+               }
+       }
+
        /* Add new session to the session list */
        session_lock_list();
-       add_session_list(new_session);
+       new_session->id = 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 ID %d by UID %d GID %d",
+               name, path, new_session->id,
+               new_session->uid, new_session->gid);
 
        return LTTCOMM_OK;
 
This page took 0.023632 seconds and 4 git commands to generate.