| 1 | /* |
| 2 | * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca> |
| 3 | * Julien Desfossez <julien.desfossez@polymtl.ca> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | * |
| 19 | */ |
| 20 | |
| 21 | #ifndef _LIBLTTSESSIONDCOMM_H |
| 22 | #define _LIBLTTSESSIONDCOMM_H |
| 23 | |
| 24 | #include <limits.h> |
| 25 | |
| 26 | #include <lttng/lttng.h> |
| 27 | #include "lttng-share.h" |
| 28 | |
| 29 | /* Default unix socket path */ |
| 30 | #define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK LTTNG_RUNDIR "/client-ltt-sessiond" |
| 31 | #define DEFAULT_GLOBAL_APPS_UNIX_SOCK LTTNG_RUNDIR "/apps-ltt-sessiond" |
| 32 | #define DEFAULT_HOME_APPS_UNIX_SOCK "%s/.apps-ltt-sessiond" |
| 33 | #define DEFAULT_HOME_CLIENT_UNIX_SOCK "%s/.client-ltt-sessiond" |
| 34 | |
| 35 | /* Queue size of listen(2) */ |
| 36 | #define MAX_LISTEN 10 |
| 37 | |
| 38 | /* Get the error code index from 0 since |
| 39 | * LTTCOMM_OK start at 1000 |
| 40 | */ |
| 41 | #define LTTCOMM_ERR_INDEX(code) (code - LTTCOMM_OK) |
| 42 | |
| 43 | enum lttcomm_sessiond_command { |
| 44 | /* Tracer context command */ |
| 45 | LTTNG_KERNEL_ADD_CONTEXT, |
| 46 | LTTNG_KERNEL_CREATE_CHANNEL, |
| 47 | LTTNG_KERNEL_DISABLE_CHANNEL, |
| 48 | LTTNG_KERNEL_DISABLE_EVENT, |
| 49 | LTTNG_KERNEL_DISABLE_ALL_EVENT, |
| 50 | LTTNG_KERNEL_ENABLE_CHANNEL, |
| 51 | LTTNG_KERNEL_ENABLE_EVENT, |
| 52 | LTTNG_KERNEL_ENABLE_ALL_EVENT, |
| 53 | LTTNG_KERNEL_LIST_EVENTS, |
| 54 | /* Session daemon context command */ |
| 55 | LTTNG_CREATE_SESSION, |
| 56 | LTTNG_DESTROY_SESSION, |
| 57 | LTTNG_LIST_SESSIONS, |
| 58 | LTTNG_LIST_TRACES, |
| 59 | LTTNG_LIST_EVENTS, |
| 60 | LTTNG_LIST_TRACEABLE_APPS, |
| 61 | LTTNG_START_TRACE, |
| 62 | LTTNG_STOP_TRACE, |
| 63 | }; |
| 64 | |
| 65 | /* |
| 66 | * lttcomm error code. |
| 67 | */ |
| 68 | enum lttcomm_return_code { |
| 69 | LTTCOMM_OK = 1000, /* Ok */ |
| 70 | LTTCOMM_ERR, /* Unknown Error */ |
| 71 | LTTCOMM_UND, /* Undefine command */ |
| 72 | LTTCOMM_ALLOC_FAIL, /* Trace allocation fail */ |
| 73 | LTTCOMM_NO_SESSION, /* No session found */ |
| 74 | LTTCOMM_CREATE_FAIL, /* Create trace fail */ |
| 75 | LTTCOMM_SESSION_FAIL, /* Create session fail */ |
| 76 | LTTCOMM_START_FAIL, /* Start tracing fail */ |
| 77 | LTTCOMM_STOP_FAIL, /* Stop tracing fail */ |
| 78 | LTTCOMM_LIST_FAIL, /* Listing apps fail */ |
| 79 | LTTCOMM_NO_APPS, /* No traceable application */ |
| 80 | LTTCOMM_SESS_NOT_FOUND, /* Session name not found */ |
| 81 | LTTCOMM_NO_TRACE, /* No trace exist */ |
| 82 | LTTCOMM_FATAL, /* Session daemon had a fatal error */ |
| 83 | LTTCOMM_NO_TRACEABLE, /* Error for non traceable app */ |
| 84 | LTTCOMM_SELECT_SESS, /* Must select a session */ |
| 85 | LTTCOMM_EXIST_SESS, /* Session name already exist */ |
| 86 | LTTCOMM_NO_EVENT, /* No event found */ |
| 87 | LTTCOMM_KERN_NA, /* Kernel tracer unavalable */ |
| 88 | LTTCOMM_KERN_SESS_FAIL, /* Kernel create session failed */ |
| 89 | LTTCOMM_KERN_CHAN_FAIL, /* Kernel create channel failed */ |
| 90 | LTTCOMM_KERN_CHAN_NOT_FOUND, /* Kernel channel not found */ |
| 91 | LTTCOMM_KERN_CHAN_DISABLE_FAIL, /* Kernel disable channel failed */ |
| 92 | LTTCOMM_KERN_CHAN_ENABLE_FAIL, /* Kernel enable channel failed */ |
| 93 | LTTCOMM_KERN_CONTEXT_FAIL, /* Kernel add context failed */ |
| 94 | LTTCOMM_KERN_ENABLE_FAIL, /* Kernel enable event failed */ |
| 95 | LTTCOMM_KERN_DISABLE_FAIL, /* Kernel disable event failed */ |
| 96 | LTTCOMM_KERN_META_FAIL, /* Kernel open metadata failed */ |
| 97 | LTTCOMM_KERN_START_FAIL, /* Kernel start trace failed */ |
| 98 | LTTCOMM_KERN_STOP_FAIL, /* Kernel stop trace failed */ |
| 99 | LTTCOMM_KERN_CONSUMER_FAIL, /* Kernel consumer start failed */ |
| 100 | LTTCOMM_KERN_STREAM_FAIL, /* Kernel create stream failed */ |
| 101 | LTTCOMM_KERN_DIR_FAIL, /* Kernel trace directory creation failed */ |
| 102 | LTTCOMM_KERN_DIR_EXIST, /* Kernel trace directory exist */ |
| 103 | LTTCOMM_KERN_NO_SESSION, /* No kernel session found */ |
| 104 | LTTCOMM_KERN_LIST_FAIL, /* Kernel listing events failed */ |
| 105 | KCONSUMERD_COMMAND_SOCK_READY, /* when kconsumerd command socket ready */ |
| 106 | KCONSUMERD_SUCCESS_RECV_FD, /* success on receiving fds */ |
| 107 | KCONSUMERD_ERROR_RECV_FD, /* error on receiving fds */ |
| 108 | KCONSUMERD_POLL_ERROR, /* Error in polling thread in kconsumerd */ |
| 109 | KCONSUMERD_POLL_NVAL, /* Poll on closed fd */ |
| 110 | KCONSUMERD_POLL_HUP, /* All fds have hungup */ |
| 111 | KCONSUMERD_EXIT_SUCCESS, /* kconsumerd exiting normally */ |
| 112 | KCONSUMERD_EXIT_FAILURE, /* kconsumerd exiting on error */ |
| 113 | KCONSUMERD_OUTFD_ERROR, /* error opening the tracefile */ |
| 114 | KCONSUMERD_SPLICE_EBADF, /* EBADF from splice(2) */ |
| 115 | KCONSUMERD_SPLICE_EINVAL, /* EINVAL from splice(2) */ |
| 116 | KCONSUMERD_SPLICE_ENOMEM, /* ENOMEM from splice(2) */ |
| 117 | KCONSUMERD_SPLICE_ESPIPE, /* ESPIPE from splice(2) */ |
| 118 | /* MUST be last element */ |
| 119 | LTTCOMM_NR, /* Last element */ |
| 120 | }; |
| 121 | |
| 122 | /* |
| 123 | * Data structure received from lttng client to session daemon. |
| 124 | */ |
| 125 | struct lttcomm_session_msg { |
| 126 | u32 cmd_type; /* enum lttcomm_sessiond_command */ |
| 127 | char session_name[NAME_MAX]; |
| 128 | char path[PATH_MAX]; |
| 129 | pid_t pid; |
| 130 | union { |
| 131 | struct { |
| 132 | char channel_name[NAME_MAX]; |
| 133 | char name[NAME_MAX]; |
| 134 | } disable; |
| 135 | /* Event data */ |
| 136 | struct { |
| 137 | char channel_name[NAME_MAX]; |
| 138 | struct lttng_event event; |
| 139 | } enable; |
| 140 | /* Create channel */ |
| 141 | struct { |
| 142 | struct lttng_channel chan; |
| 143 | } channel; |
| 144 | /* Context */ |
| 145 | struct { |
| 146 | char channel_name[NAME_MAX]; |
| 147 | char event_name[NAME_MAX]; |
| 148 | struct lttng_kernel_context ctx; |
| 149 | } context; |
| 150 | } u; |
| 151 | }; |
| 152 | |
| 153 | /* |
| 154 | * Data structure for the response from sessiond to the lttng client. |
| 155 | */ |
| 156 | struct lttcomm_lttng_msg { |
| 157 | u32 cmd_type; /* enum lttcomm_sessiond_command */ |
| 158 | u32 ret_code; /* enum lttcomm_return_code */ |
| 159 | u32 pid; /* pid_t */ |
| 160 | u32 data_size; |
| 161 | /* Contains: trace_name + data */ |
| 162 | char payload[]; |
| 163 | }; |
| 164 | |
| 165 | /* |
| 166 | * Data structures for the kconsumerd communications |
| 167 | * |
| 168 | * The header structure is sent to the kconsumerd daemon to inform |
| 169 | * how many lttcomm_kconsumerd_msg it is about to receive |
| 170 | */ |
| 171 | struct lttcomm_kconsumerd_header { |
| 172 | u32 payload_size; |
| 173 | u32 cmd_type; /* enum kconsumerd_command */ |
| 174 | }; |
| 175 | |
| 176 | /* lttcomm_kconsumerd_msg represents a file descriptor to consume the |
| 177 | * data and a path name to write it |
| 178 | */ |
| 179 | struct lttcomm_kconsumerd_msg { |
| 180 | char path_name[PATH_MAX]; |
| 181 | int fd; |
| 182 | u32 state; /* enum lttcomm_kconsumerd_fd_state */ |
| 183 | unsigned long max_sb_size; /* the subbuffer size for this channel */ |
| 184 | }; |
| 185 | |
| 186 | extern int lttcomm_create_unix_sock(const char *pathname); |
| 187 | extern int lttcomm_connect_unix_sock(const char *pathname); |
| 188 | extern int lttcomm_accept_unix_sock(int sock); |
| 189 | extern int lttcomm_listen_unix_sock(int sock); |
| 190 | extern int lttcomm_close_unix_sock(int sock); |
| 191 | extern ssize_t lttcomm_send_fds_unix_sock(int sock, void *buf, int *fds, size_t nb_fd, size_t len); |
| 192 | extern ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len); |
| 193 | extern ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len); |
| 194 | extern const char *lttcomm_get_readable_code(enum lttcomm_return_code code); |
| 195 | |
| 196 | #endif /* _LIBLTTSESSIONDCOMM_H */ |