+ /* If socket exist, we check if the daemon listens for connect. */
+ ret = access(sock_path, F_OK);
+ if (ret < 0) {
+ /* Not alive */
+ return -1;
+ }
+
+ ret = lttcomm_connect_unix_sock(sock_path);
+ if (ret < 0) {
+ /* Not alive */
+ return -1;
+ }
+
+ ret = lttcomm_close_unix_sock(ret);
+ if (ret < 0) {
+ perror("lttcomm_close_unix_sock");
+ }
+
+ return 0;
+}
+
+/*
+ * Set sessiond socket path by putting it in the global sessiond_sock_path
+ * variable.
+ */
+static int set_session_daemon_path(void)
+{
+ int ret;
+ int in_tgroup = 0; /* In tracing group */
+ uid_t uid;
+
+ uid = getuid();
+
+ if (uid != 0) {
+ /* Are we in the tracing group ? */
+ in_tgroup = check_tracing_group(tracing_group);
+ }
+
+ if (uid == 0) {
+ /* Root */
+ copy_string(sessiond_sock_path,
+ DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
+ sizeof(sessiond_sock_path));
+ } else if (in_tgroup) {
+ /* Tracing group */
+ copy_string(sessiond_sock_path,
+ DEFAULT_GLOBAL_CLIENT_UNIX_SOCK,
+ sizeof(sessiond_sock_path));
+
+ ret = try_connect_sessiond(sessiond_sock_path);
+ if (ret < 0) {
+ /* Global session daemon not available */
+ if (snprintf(sessiond_sock_path, sizeof(sessiond_sock_path),
+ DEFAULT_HOME_CLIENT_UNIX_SOCK,
+ getenv("HOME")) < 0) {
+ return -ENOMEM;
+ }
+ }
+ } else {
+ /* Not in tracing group and not root, default */