Custom upgrade: refactor: ust_app_find_by_pid -> ust_app_with_pid_exists
[deliverable/lttng-tools.git] / src / bin / lttng-sessiond / ust-app.c
index e5d6857a3ed4f5229e6db5199aa7ed90677a8973..e180bff2abe45db514504c2c22a5a7b34a15d2a9 100644 (file)
@@ -2415,8 +2415,8 @@ static void shadow_copy_session(struct ust_app_session *ua_sess,
        switch (ua_sess->buffer_type) {
        case LTTNG_BUFFER_PER_PID:
                ret = snprintf(ua_sess->path, sizeof(ua_sess->path),
-                               DEFAULT_UST_TRACE_PID_PATH "/%s-%d-%s", app->name, app->pid,
-                               datetime);
+                               DEFAULT_UST_TRACE_PID_PATH "/%s-%d-%s-%ld", app->name, app->pid,
+                               datetime, ua_sess->id);
                break;
        case LTTNG_BUFFER_PER_UID:
                ret = snprintf(ua_sess->path, sizeof(ua_sess->path),
@@ -2444,8 +2444,8 @@ static void shadow_copy_session(struct ust_app_session *ua_sess,
                switch (ua_sess->buffer_type) {
                case LTTNG_BUFFER_PER_PID:
                        ret = snprintf(tmp_shm_path, sizeof(tmp_shm_path),
-                                       "/" DEFAULT_UST_TRACE_PID_PATH "/%s-%d-%s",
-                                       app->name, app->pid, datetime);
+                                       "/" DEFAULT_UST_TRACE_PID_PATH "/%s-%d-%s-%ld",
+                                       app->name, app->pid, datetime, ua_sess->id);
                        break;
                case LTTNG_BUFFER_PER_UID:
                        ret = snprintf(tmp_shm_path, sizeof(tmp_shm_path),
@@ -3910,28 +3910,25 @@ error:
 }
 
 /*
- * Return ust app pointer or NULL if not found. RCU read side lock MUST be
+ * Check if a ust_app with a given pid is present. RCU read side lock MUST be
  * acquired before calling this function.
  */
-struct ust_app *ust_app_find_by_pid(pid_t pid)
+bool ust_app_with_pid_exists(pid_t pid)
 {
-       struct ust_app *app = NULL;
        struct lttng_ht_node_ulong *node;
        struct lttng_ht_iter iter;
+       bool present = false;
 
        lttng_ht_lookup(ust_app_ht, (void *)((unsigned long) pid), &iter);
        node = lttng_ht_iter_get_node_ulong(&iter);
        if (node == NULL) {
-               DBG2("UST app no found with pid %d", pid);
-               goto error;
+               DBG2("UST app not found with pid %d", pid);
+               goto end;
        }
 
-       DBG2("Found UST app by pid %d", pid);
-
-       app = caa_container_of(node, struct ust_app, pid_n);
-
-error:
-       return app;
+       present = true;
+end:
+       return present;
 }
 
 /*
@@ -4051,10 +4048,13 @@ void ust_app_add(struct ust_app *app)
        rcu_read_lock();
 
        /*
-        * On a re-registration, we want to kick out the previous registration of
-        * that pid
+        * Accept duplicate pid to accommodate the possibility of multiple
+        * lttng-ust per process. Both lttng-ust instance will register
+        * themselves and be unique in term of socket.
+        * All operations on pid should expects that multiple "app" be present
+        * with the same pid.
         */
-       lttng_ht_add_replace_ulong(ust_app_ht, &app->pid_n);
+       lttng_ht_add_ulong(ust_app_ht, &app->pid_n);
 
        /*
         * The socket _should_ be unique until _we_ call close. So, a add_unique
@@ -4328,17 +4328,9 @@ void ust_app_unregister(int sock)
        iter.iter.node = &lta->notify_sock_n.node;
        (void) lttng_ht_del(ust_app_ht_by_notify_sock, &iter);
 
-       /*
-        * Ignore return value since the node might have been removed before by an
-        * add replace during app registration because the PID can be reassigned by
-        * the OS.
-        */
        iter.iter.node = &lta->pid_n.node;
        ret = lttng_ht_del(ust_app_ht, &iter);
-       if (ret) {
-               DBG3("Unregister app by PID %d failed. This can happen on pid reuse",
-                               lta->pid);
-       }
+       assert(!ret);
 
        /* Free memory */
        call_rcu(&lta->pid_n.head, delete_ust_app_rcu);
This page took 0.02772 seconds and 5 git commands to generate.