Add close unix socket function to libcomm API
authorDavid Goulet <david.goulet@polymtl.ca>
Wed, 27 Apr 2011 15:34:10 +0000 (11:34 -0400)
committerDavid Goulet <david.goulet@polymtl.ca>
Wed, 27 Apr 2011 15:35:58 +0000 (11:35 -0400)
Using clean_exit everywhere in lttng now and adding
the session daemon disconnect to that clean exit function.

Also fix the recv <= 0 for process client msg on the
session daemon side in order to not send back empty data.

Signed-off-by: David Goulet <david.goulet@polymtl.ca>
include/lttng/liblttngctl.h
liblttngctl/liblttngctl.c
liblttsessiondcomm/liblttsessiondcomm.c
liblttsessiondcomm/liblttsessiondcomm.h
ltt-sessiond/ltt-sessiond.c
lttng/lttng.c

index df97313429143d2eb6902f2cd1a80747babe61d7..a3bdff80708284fbf2ba2c68a5ee44860ed4c095 100644 (file)
@@ -45,6 +45,7 @@ struct lttng_session {
 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);
index a15a26dff82f2e348cff63455829402ef780aa6d..7c5af7fe784e3169ed841e66413e6048e149f953 100644 (file)
@@ -280,6 +280,24 @@ int lttng_connect_sessiond(void)
        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
  *
index 0e9c290fed0ca96453a8cbee96f00efd0e8c5203..8413f6b08eb6c0aa863e5bf2028eae0281419421 100644 (file)
@@ -226,3 +226,21 @@ ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len)
 
        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;
+}
index 6d6290d0a455cf34e2ec6ed043bdb471864a63f3..83dcdc377ddbeaeebcc7eb35d8a54389185efc99 100644 (file)
@@ -135,6 +135,7 @@ extern int lttcomm_create_unix_sock(const char *pathname);
 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);
index 3590d7e444c685147cf74c3a2ece2e1de2831367..eee4cc84fb1729cc02afc36a3f04d23251bc7d3d 100644 (file)
@@ -217,7 +217,7 @@ static void *thread_manage_clients(void *data)
                 * request of the client.
                 */
                ret = lttcomm_recv_unix_sock(sock, &lsm, sizeof(lsm));
-               if (ret < 0) {
+               if (ret <= 0) {
                        continue;
                }
 
@@ -897,6 +897,7 @@ static void sighandler(int sig)
 {
        switch (sig) {
                case SIGPIPE:
+                       return;
                case SIGINT:
                case SIGTERM:
                        cleanup();
index 9ef92a7d418418bf005361084421920c409989e3..40cf52bc6a3b02059a1ea8635c412737f8a5f71f 100644 (file)
@@ -357,6 +357,9 @@ static void sighandler(int sig)
 void clean_exit(int code)
 {
        DBG("Clean exit");
+       if (lttng_disconnect_sessiond() < 0) {
+               ERR("Session daemon disconnect failed.");
+       }
        exit(code);
 }
 
@@ -376,12 +379,12 @@ int main(int argc, char *argv[])
 
        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) {
@@ -394,7 +397,7 @@ int main(int argc, char *argv[])
                DBG("Kernel tracing activated");
                if (getuid() != 0) {
                        ERR("%s must be setuid root", progname);
-                       return -EPERM;
+                       clean_exit(-EPERM);
                }
        }
 
@@ -402,13 +405,15 @@ int main(int argc, char *argv[])
         * 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;
 }
This page took 0.030559 seconds and 5 git commands to generate.