+/*
+ * Set sessiond socket path by putting it in the global sessiond_sock_path
+ * variable.
+ */
+static int set_session_daemon_path(void)
+{
+ int ret;
+
+ /* Are we in the tracing group ? */
+ ret = check_tracing_group(tracing_group);
+ if (ret < 0 && getuid() != 0) {
+ if (sprintf(sessiond_sock_path, DEFAULT_HOME_CLIENT_UNIX_SOCK,
+ getenv("HOME")) < 0) {
+ return -ENOMEM;
+ }
+ } else {
+ strncpy(sessiond_sock_path, DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
+ sizeof(DEFAULT_GLOBAL_CLIENT_UNIX_SOCK));
+ }
+
+ return 0;
+}
+
+/*
+ * Connect to the LTTng session daemon.
+ *
+ * On success, return 0. On error, return -1.
+ */
+static int connect_sessiond(void)
+{
+ int ret;
+
+ ret = set_session_daemon_path();
+ if (ret < 0) {
+ return ret;
+ }
+
+ /* Connect to the sesssion daemon */
+ ret = lttcomm_connect_unix_sock(sessiond_sock_path);
+ if (ret < 0) {
+ return ret;
+ }
+
+ sessiond_socket = ret;
+ connected = 1;
+
+ return 0;
+}
+
+/*
+ * Clean disconnect the session daemon.
+ */
+static int disconnect_sessiond(void)
+{
+ int ret = 0;
+
+ if (connected) {
+ ret = lttcomm_close_unix_sock(sessiond_socket);
+ sessiond_socket = 0;
+ connected = 0;
+ }
+
+ return ret;
+}
+