Add work-in-progress lttng-ust-comm
authorMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 20 Aug 2011 18:36:39 +0000 (14:36 -0400)
committerMathieu Desnoyers <mathieu.desnoyers@efficios.com>
Sat, 20 Aug 2011 18:36:39 +0000 (14:36 -0400)
Signed-off-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
libust/Makefile.am
libust/lttng-ust-comm.c [new file with mode: 0644]

index 0fa4a2b56a83f24e940cbc2c2e004c29be49ca7c..d72d4691f5ff654f9ec69102ade7ad6e4c7936c9 100644 (file)
@@ -28,6 +28,7 @@ libust_la_LIBADD = \
        -lrt \
        -luuid \
        $(top_builddir)/snprintf/libustsnprintf.la \
-       $(top_builddir)/libringbuffer/libringbuffer.la
+       $(top_builddir)/libringbuffer/libringbuffer.la \
+       $(top_builddir)/liblttng-sessiond-comm/liblttng-sessiond-comm.la
 
 libust_la_CFLAGS = -DUST_COMPONENT="libust" -fno-strict-aliasing
diff --git a/libust/lttng-ust-comm.c b/libust/lttng-ust-comm.c
new file mode 100644 (file)
index 0000000..759a445
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * lttng-ust-comm.c
+ *
+ * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
+ * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; only
+ * version 2.1 of the License.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <errno.h>
+#include <lttng-sessiond-comm.h>
+#include <ust/usterr-signal-safe.h>
+
+/* Socket from app (connect) to session daemon (listen) for communication */
+static int global_apps_socket = -1;
+static char global_apps_sock_path[PATH_MAX] = DEFAULT_GLOBAL_APPS_UNIX_SOCK;
+
+/* TODO: allow global_apps_sock_path override */
+
+static int local_apps_socket = -1;
+static char local_apps_sock_path[PATH_MAX];
+
+static
+int connect_global_apps_socket(void)
+{
+       int ret;
+
+       ret = lttcomm_connect_unix_sock(global_apps_sock_path);
+       if (ret < 0)
+               return ret;
+       global_apps_socket = ret;
+
+       return 0;
+}
+
+static
+int connect_local_apps_socket(void)
+{
+       const char *home_dir;
+       int ret;
+
+       home_dir = (const char *) getenv("HOME");
+       if (!home_dir)
+               return -ENOENT;
+       snprintf(local_apps_sock_path, PATH_MAX,
+                DEFAULT_HOME_APPS_UNIX_SOCK, home_dir);
+
+       ret = lttcomm_connect_unix_sock(local_apps_sock_path);
+       if (ret < 0)
+               return ret;
+       local_apps_socket = ret;
+
+
+       return 0;
+}
+
+static
+int register_app_to_sessiond(int socket)
+{
+       ssize_t ret;
+       struct {
+               pid_t pid;
+               uid_t uid;
+       } reg_msg;
+
+       reg_msg.pid = getpid();
+       reg_msg.uid = getuid();
+
+       ret = lttcomm_send_unix_sock(socket, &reg_msg, sizeof(reg_msg));
+       if (ret >= 0 && ret != sizeof(reg_msg))
+               return -EIO;
+       return ret;
+}
+
+/*
+ * sessiond monitoring thread: monitor presence of global and per-user
+ * sessiond by polling the application common named pipe.
+ */
+/* TODO */
+
+void __attribute__((constructor)) lttng_ust_comm_init(void)
+{
+       int ret;
+
+       init_usterr();
+
+#if 0
+       /* Connect to the global sessiond apps socket */
+       ret = connect_global_apps_socket();
+       if (ret) {
+               ERR("Error connecting to global apps socket");
+       }
+#endif //0
+
+       /* Connect to the per-user (local) sessiond apps socket */
+       ret = connect_local_apps_socket();
+       if (ret) {
+               ERR("Error connecting to local apps socket");
+       }
+
+       if (global_apps_socket >= 0) {
+               ret = register_app_to_sessiond(global_apps_socket);
+               if (ret < 0) {
+                       ERR("Error registering app to global apps socket");
+               }
+       }
+       if (local_apps_socket >= 0) {
+               ret = register_app_to_sessiond(local_apps_socket);
+               if (ret < 0) {
+                       ERR("Error registering app to local apps socket");
+               }
+       }
+}
+
+void __attribute__((destructor)) lttng_ust_comm_exit(void)
+{
+       int ret;
+
+#if 0
+       ERR("dest %d", global_apps_socket);
+       if (global_apps_socket >= 0) {
+               ret = unregister_app_to_sessiond(global_apps_socket);
+               if (ret < 0) {
+                       ERR("Error registering app to global apps socket");
+               }
+               ret = close(global_apps_socket);
+               if (ret) {
+                       ERR("Error closing global apps socket");
+               }
+       }
+#endif
+       if (local_apps_socket >= 0) {
+               ret = close(local_apps_socket);
+               if (ret) {
+                       ERR("Error closing local apps socket");
+               }
+       }
+}
This page took 0.027167 seconds and 4 git commands to generate.