Rename traceable-app and change ust app call
authorDavid Goulet <david.goulet@polymtl.ca>
Tue, 27 Sep 2011 14:06:42 +0000 (10:06 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Tue, 27 Sep 2011 14:06:42 +0000 (10:06 -0400)
Rename traceable-app to ust-app.c/.h and all calls to ust_app_* to be
consistent with the code base.

Add a channel_ust_copy() to copy UST channel and event list. Mostly used
for channel copy between ust session and ust app.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
ltt-sessiond/Makefile.am
ltt-sessiond/channel.c
ltt-sessiond/channel.h
ltt-sessiond/ltt-sessiond.h
ltt-sessiond/main.c
ltt-sessiond/traceable-app.c [deleted file]
ltt-sessiond/traceable-app.h [deleted file]
ltt-sessiond/ust-app.c [new file with mode: 0644]
ltt-sessiond/ust-app.h [new file with mode: 0644]

index 5b70933719d356940386549c442bf463353374a7..cdcdfc60e83dad3430cfc85375d711432265aa5f 100644 (file)
@@ -15,7 +15,7 @@ ltt_sessiond_SOURCES = utils.c utils.h \
                        compat/poll.h $(COMPAT) \
                        trace-kernel.c trace-kernel.h \
                        trace-ust.c trace-ust.h \
-                       traceable-app.c traceable-app.h \
+                       ust-app.c ust-app.h \
                        ust-comm.c ust-comm.h \
                        ust-ctl.c ust-ctl.h \
                        kernel-ctl.c kernel-ctl.h \
index 818f6dcfd476d7d586a480da6ebd2219d7709729..350bab6ab5a87b96fc12934d3b88cc4df73eba96 100644 (file)
@@ -15,6 +15,7 @@
  * Place - Suite 330, Boston, MA  02111-1307, USA.
  */
 
+#include <string.h>
 #include <unistd.h>
 
 #include <lttng/lttng.h>
@@ -72,6 +73,35 @@ error_alloc:
        return NULL;
 }
 
+/*
+ * Copy two ltt ust channel. Dst and src must be already allocated.
+ */
+int channel_ust_copy(struct ltt_ust_channel *dst,
+               struct ltt_ust_channel *src)
+{
+       struct ltt_ust_event *uevent, *new_uevent;
+
+       memcpy(dst, src, sizeof(struct ltt_ust_channel));
+       CDS_INIT_LIST_HEAD(&dst->events.head);
+
+       cds_list_for_each_entry(uevent, &src->events.head, list) {
+               new_uevent = malloc(sizeof(struct ltt_ust_event));
+               if (new_uevent == NULL) {
+                       perror("malloc ltt_ust_event");
+                       goto error;
+               }
+
+               memcpy(new_uevent, uevent, sizeof(struct ltt_ust_event));
+               cds_list_add(&new_uevent->list, &dst->events.head);
+               dst->events.count++;
+       }
+
+       return 0;
+
+error:
+       return -1;
+}
+
 /*
  * Disable kernel channel of the kernel session.
  */
index f9a6fbd85a1de8c245de138f604cd48890d41148..4c368e619feca560e4d2f0752f74b7e343811cc9 100644 (file)
@@ -32,6 +32,8 @@ int channel_kernel_create(struct ltt_kernel_session *ksession,
 
 int channel_ust_create(struct ltt_ust_session *usession,
                struct lttng_channel *chan, int sock);
+int channel_ust_copy(struct ltt_ust_channel *dst,
+               struct ltt_ust_channel *src);
 int channel_ust_disable(struct ltt_ust_session *usession,
                struct ltt_ust_channel *uchan, int sock);
 int channel_ust_enable(struct ltt_ust_session *usession,
index 617ca54c40ae61a72bf9dfe1a7c4e84582a70817..c28572a86ab968c4dcfd6a8aa5924d3a68cf04fa 100644 (file)
@@ -22,7 +22,7 @@
 #define _LGPL_SOURCE
 #include <urcu/wfqueue.h>
 
-#include "traceable-app.h"
+#include "ust-app.h"
 
 #define DEFAULT_HOME_DIR            "/tmp"
 #define DEFAULT_UST_SOCK_DIR        DEFAULT_HOME_DIR "/ust-app-socks"
index 825fa4371cb67b0316fcf9ce8b6e677dd1f0f115..e1bf1e416b49be23b8ca860d21062249b70a01df 100644 (file)
@@ -50,7 +50,7 @@
 #include "kernel-ctl.h"
 #include "ltt-sessiond.h"
 #include "shm.h"
-#include "traceable-app.h"
+#include "ust-app.h"
 #include "ust-ctl.h"
 #include "utils.h"
 #include "ust-ctl.h"
@@ -344,7 +344,7 @@ static void cleanup(void)
        }
 
        DBG("Closing all UST sockets");
-       clean_traceable_apps_list();
+       ust_app_clean_list();
 
        pthread_mutex_destroy(&kconsumerd_pid_mutex);
 
@@ -986,7 +986,7 @@ static void *thread_manage_apps(void *data)
                                        }
 
                                        /* Register applicaton to the session daemon */
-                                       ret = register_traceable_app(&ust_cmd.reg_msg,
+                                       ret = ust_app_register(&ust_cmd.reg_msg,
                                                        ust_cmd.sock);
                                        if (ret < 0) {
                                                /* Only critical ENOMEM error can be returned here */
@@ -999,7 +999,7 @@ static void *thread_manage_apps(void *data)
                                                 * If the registration is not possible, we simply
                                                 * unregister the apps and continue
                                                 */
-                                               unregister_traceable_app(ust_cmd.sock);
+                                               ust_app_unregister(ust_cmd.sock);
                                        } else {
                                                /*
                                                 * We just need here to monitor the close of the UST
@@ -1028,7 +1028,7 @@ static void *thread_manage_apps(void *data)
                                        }
 
                                        /* Socket closed */
-                                       unregister_traceable_app(pollfd);
+                                       ust_app_unregister(pollfd);
                                        break;
                                }
                        }
@@ -1566,11 +1566,11 @@ static int create_ust_session(struct ltt_session *session,
 {
        int ret;
        struct ltt_ust_session *lus;
-       struct ltt_traceable_app *app;
+       struct ust_app *app;
 
        switch (domain->type) {
        case LTTNG_DOMAIN_UST_PID:
-               app = traceable_app_get_by_pid(domain->attr.pid);
+               app = ust_app_get_by_pid(domain->attr.pid);
                if (app == NULL) {
                        ret = LTTCOMM_APP_NOT_FOUND;
                        goto error;
@@ -1775,6 +1775,42 @@ error:
        return ret;
 }
 
+/*
+ * Copy channel from attributes and set it in the application channel list.
+ */
+static int copy_ust_channel_to_app(struct ltt_ust_session *usess,
+               struct lttng_channel *attr, struct ust_app *app)
+{
+       int ret;
+       struct ltt_ust_channel *uchan, *new_chan;
+
+       uchan = trace_ust_get_channel_by_name(attr->name, usess);
+       if (uchan == NULL) {
+               ret = LTTCOMM_FATAL;
+               goto error;
+       }
+
+       new_chan = trace_ust_create_channel(attr, usess->path);
+       if (new_chan == NULL) {
+               PERROR("malloc ltt_ust_channel");
+               ret = LTTCOMM_FATAL;
+               goto error;
+       }
+
+       ret = channel_ust_copy(new_chan, uchan);
+       if (ret < 0) {
+               ret = LTTCOMM_FATAL;
+               goto error;
+       }
+
+       /* Add channel to the ust app channel list */
+       cds_list_add(&new_chan->list, &app->channels.head);
+       app->channels.count++;
+
+error:
+       return ret;
+}
+
 /*
  * Command LTTNG_ENABLE_CHANNEL processed by the client thread.
  */
@@ -1806,10 +1842,10 @@ static int cmd_enable_channel(struct ltt_session *session,
        }
        case LTTNG_DOMAIN_UST_PID:
        {
-               struct ltt_ust_event *uevent, *new_uevent;
+               int sock;
+               struct ltt_ust_channel *uchan;
                struct ltt_ust_session *usess;
-               struct ltt_ust_channel *uchan, *app_chan;
-               struct ltt_traceable_app *app;
+               struct ust_app *app;
 
                usess = trace_ust_get_session_by_pid(&session->ust_session_list,
                                domain->attr.pid);
@@ -1818,59 +1854,29 @@ static int cmd_enable_channel(struct ltt_session *session,
                        goto error;
                }
 
-               app = traceable_app_get_by_pid(domain->attr.pid);
+               app = ust_app_get_by_pid(domain->attr.pid);
                if (app == NULL) {
                        ret = LTTCOMM_APP_NOT_FOUND;
                        goto error;
                }
+               sock = app->sock;
 
                uchan = trace_ust_get_channel_by_name(attr->name, usess);
                if (uchan == NULL) {
-                       ret = channel_ust_create(usess, attr, app->sock);
+                       ret = channel_ust_create(usess, attr, sock);
                } else {
-                       ret = channel_ust_enable(usess, uchan, app->sock);
+                       ret = channel_ust_enable(usess, uchan, sock);
                }
 
                if (ret != LTTCOMM_OK) {
                        goto error;
                }
 
-               /*TODO: This should be put in an external function */
-
-               /* Copy UST channel to add to the traceable app */
-               uchan = trace_ust_get_channel_by_name(attr->name, usess);
-               if (uchan == NULL) {
-                       ret = LTTCOMM_FATAL;
-                       goto error;
-               }
-
-               app_chan = trace_ust_create_channel(attr, session->path);
-               if (app_chan == NULL) {
-                       PERROR("malloc ltt_ust_channel");
-                       ret = LTTCOMM_FATAL;
+               ret = copy_ust_channel_to_app(usess, attr, app);
+               if (ret != LTTCOMM_OK) {
                        goto error;
                }
 
-               memcpy(app_chan, uchan, sizeof(struct ltt_ust_channel));
-               CDS_INIT_LIST_HEAD(&app_chan->events.head);
-
-               cds_list_for_each_entry(uevent, &uchan->events.head, list) {
-                       new_uevent = malloc(sizeof(struct ltt_ust_event));
-                       if (new_uevent == NULL) {
-                               PERROR("malloc ltt_ust_event");
-                               ret = LTTCOMM_FATAL;
-                               goto error;
-                       }
-
-                       memcpy(new_uevent, uevent, sizeof(struct ltt_ust_event));
-                       cds_list_add(&new_uevent->list, &app_chan->events.head);
-                       app_chan->events.count++;
-               }
-
-               /* Add channel to traceable_app */
-               cds_list_add(&app_chan->list, &app->channels.head);
-               app->channels.count++;
-
                DBG("UST channel %s created for app sock %d with pid %d",
                                attr->name, app->sock, domain->attr.pid);
                break;
diff --git a/ltt-sessiond/traceable-app.c b/ltt-sessiond/traceable-app.c
deleted file mode 100644 (file)
index 41dc511..0000000
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#define _GNU_SOURCE
-#include <errno.h>
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-
-#include <lttngerr.h>
-
-#include "traceable-app.h"
-
-/* Init ust traceabl application's list */
-static struct ltt_traceable_app_list ltt_traceable_app_list = {
-       .head = CDS_LIST_HEAD_INIT(ltt_traceable_app_list.head),
-       .lock = PTHREAD_MUTEX_INITIALIZER,
-       .count = 0,
-};
-
-/*
- * Add a traceable application structure to the global list.
- */
-static void add_traceable_app(struct ltt_traceable_app *lta)
-{
-       cds_list_add(&lta->list, &ltt_traceable_app_list.head);
-       ltt_traceable_app_list.count++;
-}
-
-/*
- * Delete a traceable application structure from the global list.
- */
-static void del_traceable_app(struct ltt_traceable_app *lta)
-{
-       struct ltt_ust_channel *chan;
-
-       cds_list_del(&lta->list);
-       /* Sanity check */
-       if (ltt_traceable_app_list.count > 0) {
-               ltt_traceable_app_list.count--;
-       }
-
-       cds_list_for_each_entry(chan, &lta->channels.head, list) {
-               trace_ust_destroy_channel(chan);
-       }
-}
-
-/*
- * Return pointer to traceable apps list.
- */
-struct ltt_traceable_app_list *get_traceable_apps_list(void)
-{
-       return &ltt_traceable_app_list;
-}
-
-/*
- * Acquire traceable apps list lock.
- */
-void lock_apps_list(void)
-{
-       pthread_mutex_lock(&ltt_traceable_app_list.lock);
-}
-
-/*
- * Release traceable apps list lock.
- */
-void unlock_apps_list(void)
-{
-       pthread_mutex_unlock(&ltt_traceable_app_list.lock);
-}
-
-/*
- * Iterate over the traceable apps list and return a pointer or NULL if not
- * found.
- */
-static struct ltt_traceable_app *find_app_by_sock(int sock)
-{
-       struct ltt_traceable_app *iter;
-
-       cds_list_for_each_entry(iter, &ltt_traceable_app_list.head, list) {
-               if (iter->sock == sock) {
-                       /* Found */
-                       return iter;
-               }
-       }
-
-       return NULL;
-}
-
-/*
- * Iterate over the traceable apps list and return a pointer or NULL if not
- * found.
- */
-struct ltt_traceable_app *traceable_app_get_by_pid(pid_t pid)
-{
-       struct ltt_traceable_app *iter;
-
-       cds_list_for_each_entry(iter, &ltt_traceable_app_list.head, list) {
-               if (iter->pid == pid) {
-                       /* Found */
-                       DBG2("Found traceable app by pid %d", pid);
-                       return iter;
-               }
-       }
-
-       DBG2("Traceable app with pid %d not found", pid);
-
-       return NULL;
-}
-
-/*
- * Using pid and uid (of the app), allocate a new ltt_traceable_app struct and
- * add it to the global traceable app list.
- *
- * On success, return 0, else return malloc ENOMEM.
- */
-int register_traceable_app(struct ust_register_msg *msg, int sock)
-{
-       struct ltt_traceable_app *lta;
-
-       lta = malloc(sizeof(struct ltt_traceable_app));
-       if (lta == NULL) {
-               perror("malloc");
-               return -ENOMEM;
-       }
-
-       lta->uid = msg->uid;
-       lta->gid = msg->gid;
-       lta->pid = msg->pid;
-       lta->ppid = msg->ppid;
-       lta->v_major = msg->major;
-       lta->v_minor = msg->minor;
-       lta->sock = sock;
-       strncpy(lta->name, msg->name, sizeof(lta->name));
-       lta->name[16] = '\0';
-       CDS_INIT_LIST_HEAD(&lta->channels.head);
-
-       lock_apps_list();
-       add_traceable_app(lta);
-       unlock_apps_list();
-
-       DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
-                       " (version %d.%d)", lta->pid, lta->ppid, lta->uid, lta->gid,
-                       lta->sock, lta->name, lta->v_major, lta->v_minor);
-
-       return 0;
-}
-
-/*
- * Unregister app by removing it from the global traceable app list and freeing
- * the data struct.
- *
- * The socket is already closed at this point so no close to sock.
- */
-void unregister_traceable_app(int sock)
-{
-       struct ltt_traceable_app *lta;
-
-       lock_apps_list();
-       lta = find_app_by_sock(sock);
-       if (lta) {
-               DBG("PID %d unregistered with sock %d", lta->pid, sock);
-               del_traceable_app(lta);
-               close(lta->sock);
-               free(lta);
-       }
-       unlock_apps_list();
-}
-
-/*
- * Return traceable_app_count
- */
-unsigned int get_app_count(void)
-{
-       unsigned int count;
-
-       lock_apps_list();
-       count = ltt_traceable_app_list.count;
-       unlock_apps_list();
-
-       return count;
-}
-
-/*
- * Free and clean all traceable apps of the global list.
- */
-void clean_traceable_apps_list(void)
-{
-       struct ltt_traceable_app *iter, *tmp;
-
-       /*
-        * Don't acquire list lock here. This function should be called from
-        * cleanup() functions meaning that the program will exit.
-        */
-       cds_list_for_each_entry_safe(iter, tmp, &ltt_traceable_app_list.head, list) {
-               del_traceable_app(iter);
-               close(iter->sock);
-               free(iter);
-       }
-}
diff --git a/ltt-sessiond/traceable-app.h b/ltt-sessiond/traceable-app.h
deleted file mode 100644 (file)
index 39f97f2..0000000
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; only version 2
- * of the License.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- */
-
-#ifndef _TRACEABLE_APP_H 
-#define _TRACEABLE_APP_H
-
-#include <stdint.h>
-#include <urcu/list.h>
-
-#include "trace-ust.h"
-
-/*
- * Application registration data structure.
- */
-struct ust_register_msg {
-       uint32_t major;
-       uint32_t minor;
-       pid_t pid;
-       pid_t ppid;
-       uid_t uid;
-       gid_t gid;
-       char name[16];
-};
-
-/*
- * Traceable application list.
- */
-struct ltt_traceable_app_list {
-       /*
-        * This lock protects any read/write access to the list and count (which is
-        * basically the list size). All public functions in traceable-app.c
-        * acquire this lock and release it before returning. If none of those
-        * functions are used, the lock MUST be acquired in order to iterate or/and
-        * do any actions on that list.
-        */
-       pthread_mutex_t lock;
-
-       /*
-        * Number of element in the list. The session list lock MUST be acquired if
-        * this counter is used when iterating over the session list.
-        */
-       unsigned int count;
-
-       /* Linked list head */
-       struct cds_list_head head;
-};
-
-/* Registered traceable applications. Libust registers to the session daemon
- * and a linked list is kept of all running traceable app.
- */
-struct ltt_traceable_app {
-       int sock;            /* Communication socket with the application */
-       pid_t pid;
-       pid_t ppid;
-       uid_t uid;           /* User ID that owns the apps */
-       gid_t gid;           /* Group ID that owns the apps */
-       uint32_t v_major;    /* Verion major number */
-       uint32_t v_minor;    /* Verion minor number */
-       char name[17];       /* Process name (short) */
-       struct ltt_ust_channel_list channels;
-       struct cds_list_head list;
-};
-
-int register_traceable_app(struct ust_register_msg *msg, int sock);
-void unregister_traceable_app(int sock);
-unsigned int get_app_count(void);
-
-void lock_apps_list(void);
-void unlock_apps_list(void);
-void clean_traceable_apps_list(void);
-struct ltt_traceable_app_list *get_traceable_apps_list(void);
-
-struct ltt_traceable_app *traceable_app_get_by_pid(pid_t pid);
-
-#endif /* _TRACEABLE_APP_H */
diff --git a/ltt-sessiond/ust-app.c b/ltt-sessiond/ust-app.c
new file mode 100644 (file)
index 0000000..ea06255
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; only version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#define _GNU_SOURCE
+#include <errno.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include <lttngerr.h>
+
+#include "ust-app.h"
+
+/* Init ust traceable application's list */
+static struct ust_app_list ust_app_list = {
+       .head = CDS_LIST_HEAD_INIT(ust_app_list.head),
+       .lock = PTHREAD_MUTEX_INITIALIZER,
+       .count = 0,
+};
+
+/*
+ * Add a traceable application structure to the global list.
+ */
+static void add_app_to_list(struct ust_app *lta)
+{
+       cds_list_add(&lta->list, &ust_app_list.head);
+       ust_app_list.count++;
+}
+
+/*
+ * Delete a traceable application structure from the global list.
+ */
+static void del_app_from_list(struct ust_app *lta)
+{
+       struct ltt_ust_channel *chan;
+
+       cds_list_del(&lta->list);
+       /* Sanity check */
+       if (ust_app_list.count > 0) {
+               ust_app_list.count--;
+       }
+
+       cds_list_for_each_entry(chan, &lta->channels.head, list) {
+               trace_ust_destroy_channel(chan);
+       }
+}
+
+/*
+ * Iterate over the traceable apps list and return a pointer or NULL if not
+ * found.
+ */
+static struct ust_app *find_app_by_sock(int sock)
+{
+       struct ust_app *iter;
+
+       cds_list_for_each_entry(iter, &ust_app_list.head, list) {
+               if (iter->sock == sock) {
+                       /* Found */
+                       return iter;
+               }
+       }
+
+       return NULL;
+}
+
+/*
+ * Return pointer to traceable apps list.
+ */
+struct ust_app_list *ust_app_get_list(void)
+{
+       return &ust_app_list;
+}
+
+/*
+ * Acquire traceable apps list lock.
+ */
+void ust_app_lock_list(void)
+{
+       pthread_mutex_lock(&ust_app_list.lock);
+}
+
+/*
+ * Release traceable apps list lock.
+ */
+void ust_app_unlock_list(void)
+{
+       pthread_mutex_unlock(&ust_app_list.lock);
+}
+
+/*
+ * Iterate over the traceable apps list and return a pointer or NULL if not
+ * found.
+ */
+struct ust_app *ust_app_get_by_pid(pid_t pid)
+{
+       struct ust_app *iter;
+
+       cds_list_for_each_entry(iter, &ust_app_list.head, list) {
+               if (iter->pid == pid) {
+                       /* Found */
+                       DBG2("Found traceable app by pid %d", pid);
+                       return iter;
+               }
+       }
+
+       DBG2("Traceable app with pid %d not found", pid);
+
+       return NULL;
+}
+
+/*
+ * Using pid and uid (of the app), allocate a new ust_app struct and
+ * add it to the global traceable app list.
+ *
+ * On success, return 0, else return malloc ENOMEM.
+ */
+int ust_app_register(struct ust_register_msg *msg, int sock)
+{
+       struct ust_app *lta;
+
+       lta = malloc(sizeof(struct ust_app));
+       if (lta == NULL) {
+               perror("malloc");
+               return -ENOMEM;
+       }
+
+       lta->uid = msg->uid;
+       lta->gid = msg->gid;
+       lta->pid = msg->pid;
+       lta->ppid = msg->ppid;
+       lta->v_major = msg->major;
+       lta->v_minor = msg->minor;
+       lta->sock = sock;
+       strncpy(lta->name, msg->name, sizeof(lta->name));
+       lta->name[16] = '\0';
+       CDS_INIT_LIST_HEAD(&lta->channels.head);
+
+       ust_app_lock_list();
+       add_app_to_list(lta);
+       ust_app_unlock_list();
+
+       DBG("App registered with pid:%d ppid:%d uid:%d gid:%d sock:%d name:%s"
+                       " (version %d.%d)", lta->pid, lta->ppid, lta->uid, lta->gid,
+                       lta->sock, lta->name, lta->v_major, lta->v_minor);
+
+       return 0;
+}
+
+/*
+ * Unregister app by removing it from the global traceable app list and freeing
+ * the data struct.
+ *
+ * The socket is already closed at this point so no close to sock.
+ */
+void ust_app_unregister(int sock)
+{
+       struct ust_app *lta;
+
+       ust_app_lock_list();
+       lta = find_app_by_sock(sock);
+       if (lta) {
+               DBG("PID %d unregistered with sock %d", lta->pid, sock);
+               del_app_from_list(lta);
+               close(lta->sock);
+               free(lta);
+       }
+       ust_app_unlock_list();
+}
+
+/*
+ * Return traceable_app_count
+ */
+unsigned int ust_app_list_count(void)
+{
+       unsigned int count;
+
+       ust_app_lock_list();
+       count = ust_app_list.count;
+       ust_app_unlock_list();
+
+       return count;
+}
+
+/*
+ * Free and clean all traceable apps of the global list.
+ */
+void ust_app_clean_list(void)
+{
+       struct ust_app *iter, *tmp;
+
+       /*
+        * Don't acquire list lock here. This function should be called from
+        * cleanup() functions meaning that the program will exit.
+        */
+       cds_list_for_each_entry_safe(iter, tmp, &ust_app_list.head, list) {
+               del_app_from_list(iter);
+               close(iter->sock);
+               free(iter);
+       }
+}
diff --git a/ltt-sessiond/ust-app.h b/ltt-sessiond/ust-app.h
new file mode 100644 (file)
index 0000000..f2d3d26
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; only version 2
+ * of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ */
+
+#ifndef _TRACEABLE_APP_H 
+#define _TRACEABLE_APP_H
+
+#include <stdint.h>
+#include <urcu/list.h>
+
+#include "trace-ust.h"
+
+/*
+ * Application registration data structure.
+ */
+struct ust_register_msg {
+       uint32_t major;
+       uint32_t minor;
+       pid_t pid;
+       pid_t ppid;
+       uid_t uid;
+       gid_t gid;
+       char name[16];
+};
+
+/*
+ * Traceable application list.
+ */
+struct ust_app_list{
+       /*
+        * This lock protects any read/write access to the list and count (which is
+        * basically the list size). All public functions in traceable-app.c
+        * acquire this lock and release it before returning. If none of those
+        * functions are used, the lock MUST be acquired in order to iterate or/and
+        * do any actions on that list.
+        */
+       pthread_mutex_t lock;
+
+       /*
+        * Number of element in the list. The session list lock MUST be acquired if
+        * this counter is used when iterating over the session list.
+        */
+       unsigned int count;
+
+       /* Linked list head */
+       struct cds_list_head head;
+};
+
+/* Registered traceable applications. Libust registers to the session daemon
+ * and a linked list is kept of all running traceable app.
+ */
+struct ust_app {
+       int sock;            /* Communication socket with the application */
+       pid_t pid;
+       pid_t ppid;
+       uid_t uid;           /* User ID that owns the apps */
+       gid_t gid;           /* Group ID that owns the apps */
+       uint32_t v_major;    /* Verion major number */
+       uint32_t v_minor;    /* Verion minor number */
+       char name[17];       /* Process name (short) */
+       struct ltt_ust_channel_list channels;
+       struct cds_list_head list;
+};
+
+int ust_app_register(struct ust_register_msg *msg, int sock);
+void ust_app_unregister(int sock);
+unsigned int ust_app_list_count(void);
+
+void ust_app_lock_list(void);
+void ust_app_unlock_list(void);
+void ust_app_clean_list(void);
+struct ust_app_list *ust_app_get_list(void);
+struct ust_app *ust_app_get_by_pid(pid_t pid);
+
+#endif /* _TRACEABLE_APP_H */
This page took 0.060277 seconds and 4 git commands to generate.