extern int lttng_create_session(char *name, uuid_t *session_id);
extern int lttng_destroy_session(uuid_t *uuid);
extern int lttng_connect_sessiond(void);
+extern int lttng_disconnect_sessiond(void);
extern int lttng_set_tracing_group(const char *name);
extern int lttng_check_session_daemon(void);
extern const char *lttng_get_readable_code(int code);
return 0;
}
+/*
+ * lttng_disconnect_sessiond
+ *
+ * Clean disconnect the session daemon.
+ */
+int lttng_disconnect_sessiond(void)
+{
+ int ret = 0;
+
+ if (connected) {
+ ret = lttcomm_close_unix_sock(sessiond_socket);
+ sessiond_socket = 0;
+ connected = 0;
+ }
+
+ return ret;
+}
+
/*
* lttng_set_current_session_uuid
*
return ret;
}
+
+/*
+ * lttcomm_close_unix_sock
+ *
+ * Shutdown cleanly a unix socket.
+ */
+int lttcomm_close_unix_sock(int sock)
+{
+ int ret;
+
+ /* Shutdown receptions and transmissions */
+ ret = shutdown(sock, SHUT_RDWR);
+ if (ret < 0) {
+ perror("shutdown");
+ }
+
+ return ret;
+}
extern int lttcomm_connect_unix_sock(const char *pathname);
extern int lttcomm_accept_unix_sock(int sock);
extern int lttcomm_listen_unix_sock(int sock);
+extern int lttcomm_close_unix_sock(int sock);
extern ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len);
extern ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len);
extern const char *lttcomm_get_readable_code(enum lttcomm_return_code code);
* request of the client.
*/
ret = lttcomm_recv_unix_sock(sock, &lsm, sizeof(lsm));
- if (ret < 0) {
+ if (ret <= 0) {
continue;
}
{
switch (sig) {
case SIGPIPE:
+ return;
case SIGINT:
case SIGTERM:
cleanup();
void clean_exit(int code)
{
DBG("Clean exit");
+ if (lttng_disconnect_sessiond() < 0) {
+ ERR("Session daemon disconnect failed.");
+ }
exit(code);
}
ret = parse_args(argc, (const char **) argv);
if (ret < 0) {
- return EXIT_FAILURE;
+ clean_exit(EXIT_FAILURE);
}
ret = set_signal_handler();
if (ret < 0) {
- return ret;
+ clean_exit(ret);
}
if (opt_tracing_group != NULL) {
DBG("Kernel tracing activated");
if (getuid() != 0) {
ERR("%s must be setuid root", progname);
- return -EPERM;
+ clean_exit(-EPERM);
}
}
* If no, a daemon will be spawned.
*/
if (opt_no_sessiond == 0 && (check_ltt_sessiond() < 0)) {
- return EXIT_FAILURE;
+ clean_exit(EXIT_FAILURE);
}
ret = process_client_opt();
if (ret < 0) {
- return ret;
+ clean_exit(ret);
}
+ clean_exit(0);
+
return 0;
}