Handle splice errors
[lttng-tools.git] / liblttsessiondcomm / liblttsessiondcomm.c
index 9c72a918ccc23d94584df20a3d0bb139b5ce7c6a..19bda83883df09ddd7db9700c8c946451b93c4cc 100644 (file)
@@ -38,6 +38,33 @@ static const char *lttcomm_readable_code[] = {
        [ LTTCOMM_ERR_INDEX(LTTCOMM_UND) ] = "Undefined command",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_SESSION) ] = "No session found",
        [ LTTCOMM_ERR_INDEX(LTTCOMM_LIST_FAIL) ] = "Unable to list traceable apps",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_APPS) ] = "No traceable apps found",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_SESS) ] = "No session found",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_TRACE) ] = "No trace found",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_FATAL) ] = "Fatal error of the session daemon",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_CREATE_FAIL) ] = "Create trace failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_START_FAIL) ] = "Start trace failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_STOP_FAIL) ] = "Stop trace failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_TRACEABLE) ] = "App is not traceable",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_SELECT_SESS) ] = "A session MUST be selected",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_EXIST_SESS) ] = "Session name already exist",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_NA) ] = "Kernel tracer not available",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_SESS_FAIL) ] = "Kernel create session failed",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_KERN_CHAN_FAIL) ] = "Kernel create channel failed",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_COMMAND_SOCK_READY) ] = "Kconsumerd command socket ready",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_SUCCESS_RECV_FD) ] = "Kconsumerd success on receiving fds",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_ERROR_RECV_FD) ] = "Kconsumerd error on receiving fds",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_POLL_ERROR) ] = "Kconsumerd error in polling thread",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_POLL_NVAL) ] = "Kconsumerd polling on closed fd",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_POLL_HUP) ] = "Kconsumerd all fd hung up",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_EXIT_SUCCESS) ] = "Kconsumerd exiting normally",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_EXIT_FAILURE) ] = "Kconsumerd exiting on error",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_OUTFD_ERROR) ] = "Kconsumerd error opening the tracefile",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_SPLICE_EBADF) ] = "Kconsumerd splice EBADF",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_SPLICE_EINVAL) ] = "Kconsumerd splice EINVAL",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_SPLICE_ENOMEM) ] = "Kconsumerd splice ENOMEM",
+       [ LTTCOMM_ERR_INDEX(KCONSUMERD_SPLICE_ESPIPE) ] = "Kconsumerd splice ESPIPE",
+       [ LTTCOMM_ERR_INDEX(LTTCOMM_NO_EVENT) ] = "No event found",
 };
 
 /*
@@ -67,27 +94,27 @@ const char *lttcomm_get_readable_code(enum lttcomm_return_code code)
  */
 int lttcomm_connect_unix_sock(const char *pathname)
 {
-    struct sockaddr_un sun;
-    int fd;
+       struct sockaddr_un sun;
+       int fd;
        int ret = 1;
 
-    fd = socket(PF_UNIX, SOCK_STREAM, 0);
+       fd = socket(PF_UNIX, SOCK_STREAM, 0);
        if (fd < 0) {
                perror("socket");
                goto error;
        }
 
-    memset(&sun, 0, sizeof(sun));
-    sun.sun_family = AF_UNIX;
-    strncpy(sun.sun_path, pathname, sizeof(sun.sun_path));
+       memset(&sun, 0, sizeof(sun));
+       sun.sun_family = AF_UNIX;
+       strncpy(sun.sun_path, pathname, sizeof(sun.sun_path));
 
-    ret = connect(fd, (struct sockaddr *) &sun, sizeof(sun));
-    if (ret < 0) {
-        perror("connect");
+       ret = connect(fd, (struct sockaddr *) &sun, sizeof(sun));
+       if (ret < 0) {
+               perror("connect");
                goto error;
-    }
+       }
 
-    return fd;
+       return fd;
 
 error:
        return -1;
@@ -223,3 +250,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;
+}
This page took 0.023656 seconds and 4 git commands to generate.