4 * Copyright (C) 2011 David Goulet <david.goulet@polymtl.ca>
5 * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; only
10 * version 2.1 of the License.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <sys/types.h>
23 #include <sys/socket.h>
26 #include <lttng-sessiond-comm.h>
27 #include <ust/usterr-signal-safe.h>
29 /* Socket from app (connect) to session daemon (listen) for communication */
30 static int global_apps_socket
= -1;
31 static char global_apps_sock_path
[PATH_MAX
] = DEFAULT_GLOBAL_APPS_UNIX_SOCK
;
33 /* TODO: allow global_apps_sock_path override */
35 static int local_apps_socket
= -1;
36 static char local_apps_sock_path
[PATH_MAX
];
39 int connect_global_apps_socket(void)
43 ret
= lttcomm_connect_unix_sock(global_apps_sock_path
);
46 global_apps_socket
= ret
;
52 int connect_local_apps_socket(void)
57 home_dir
= (const char *) getenv("HOME");
60 snprintf(local_apps_sock_path
, PATH_MAX
,
61 DEFAULT_HOME_APPS_UNIX_SOCK
, home_dir
);
63 ret
= lttcomm_connect_unix_sock(local_apps_sock_path
);
66 local_apps_socket
= ret
;
73 int register_app_to_sessiond(int socket
)
81 reg_msg
.pid
= getpid();
82 reg_msg
.uid
= getuid();
84 ret
= lttcomm_send_unix_sock(socket
, ®_msg
, sizeof(reg_msg
));
85 if (ret
>= 0 && ret
!= sizeof(reg_msg
))
91 * sessiond monitoring thread: monitor presence of global and per-user
92 * sessiond by polling the application common named pipe.
96 void __attribute__((constructor
)) lttng_ust_comm_init(void)
103 /* Connect to the global sessiond apps socket */
104 ret
= connect_global_apps_socket();
106 ERR("Error connecting to global apps socket");
110 /* Connect to the per-user (local) sessiond apps socket */
111 ret
= connect_local_apps_socket();
113 ERR("Error connecting to local apps socket");
116 if (global_apps_socket
>= 0) {
117 ret
= register_app_to_sessiond(global_apps_socket
);
119 ERR("Error registering app to global apps socket");
122 if (local_apps_socket
>= 0) {
123 ret
= register_app_to_sessiond(local_apps_socket
);
125 ERR("Error registering app to local apps socket");
130 void __attribute__((destructor
)) lttng_ust_comm_exit(void)
135 ERR("dest %d", global_apps_socket
);
136 if (global_apps_socket
>= 0) {
137 ret
= unregister_app_to_sessiond(global_apps_socket
);
139 ERR("Error registering app to global apps socket");
141 ret
= close(global_apps_socket
);
143 ERR("Error closing global apps socket");
147 if (local_apps_socket
>= 0) {
148 ret
= close(local_apps_socket
);
150 ERR("Error closing local apps socket");