Add kconsumerd thread function and sockets
[lttng-tools.git] / liblttsessiondcomm / liblttsessiondcomm.h
CommitLineData
fac6795d
DG
1/* Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU General Public License
5 * as published by the Free Software Foundation; either version 2
6 * of the License, or (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16 *
17 */
18
19#ifndef _LIBLTTSESSIONDCOMM_H
20#define _LIBLTTSESSIONDCOMM_H
21
22#include <limits.h>
23#include <uuid/uuid.h>
24
d6f42150
DG
25#define LTTNG_RUNDIR "/var/run/lttng"
26
fac6795d 27/* Default unix socket path */
d6f42150
DG
28#define DEFAULT_GLOBAL_CLIENT_UNIX_SOCK LTTNG_RUNDIR "/client-ltt-sessiond"
29#define DEFAULT_GLOBAL_APPS_UNIX_SOCK LTTNG_RUNDIR "/apps-ltt-sessiond"
fac6795d
DG
30#define DEFAULT_HOME_APPS_UNIX_SOCK "%s/.apps-ltt-sessiond"
31#define DEFAULT_HOME_CLIENT_UNIX_SOCK "%s/.client-ltt-sessiond"
32
d6f42150
DG
33/* Kernel consumer path */
34#define KCONSUMERD_PATH LTTNG_RUNDIR "/kconsumerd"
35#define KCONSUMERD_CMD_SOCK_PATH KCONSUMERD_PATH "/command"
36#define KCONSUMERD_ERR_SOCK_PATH KCONSUMERD_PATH "/error"
37
fac6795d
DG
38/* Queue size of listen(2) */
39#define MAX_LISTEN 10
40
fac6795d
DG
41/* Get the error code index from 0 since
42 * LTTCOMM_OK start at 1000
43 */
686204ab 44#define LTTCOMM_ERR_INDEX(code) (code - LTTCOMM_OK)
fac6795d
DG
45
46enum lttcomm_command_type {
47 LTTNG_CREATE_SESSION,
48 LTTNG_DESTROY_SESSION,
49 LTTNG_FORCE_SUBBUF_SWITCH,
50 LTTNG_GET_ALL_SESSION,
51 LTTNG_GET_SOCK_PATH,
52 LTTNG_GET_SUBBUF_NUM_SIZE,
53 LTTNG_LIST_MARKERS,
54 LTTNG_LIST_SESSIONS,
1657e9bb 55 LTTNG_LIST_TRACES,
fac6795d
DG
56 LTTNG_LIST_TRACE_EVENTS,
57 LTTNG_SETUP_TRACE,
58 LTTNG_SET_SOCK_PATH,
59 LTTNG_SET_SUBBUF_NUM,
60 LTTNG_SET_SUBBUF_SIZE,
61 UST_ALLOC_TRACE,
62 UST_CREATE_TRACE,
63 UST_DESTROY_TRACE,
64 UST_DISABLE_MARKER,
65 UST_ENABLE_MARKER,
66 UST_LIST_APPS,
67 UST_START_TRACE,
68 UST_STOP_TRACE,
69};
70
71/*
72 * lttcomm error code.
73 */
74enum lttcomm_return_code {
75 LTTCOMM_OK = 1000, /* Ok */
76 LTTCOMM_ERR, /* Unknown Error */
77 LTTCOMM_UND, /* Undefine command */
78 LTTCOMM_ALLOC_FAIL, /* Trace allocation fail */
79 LTTCOMM_NO_SESSION, /* No session found */
80 LTTCOMM_CREATE_FAIL, /* Create trace fail */
81 LTTCOMM_SESSION_FAIL, /* Create session fail */
82 LTTCOMM_START_FAIL, /* Start tracing fail */
520ff687 83 LTTCOMM_STOP_FAIL, /* Stop tracing fail */
fac6795d 84 LTTCOMM_LIST_FAIL, /* Listing apps fail */
e065084a 85 LTTCOMM_NO_APPS, /* No traceable application */
57167058 86 LTTCOMM_NO_SESS, /* No sessions available */
ce3d728c 87 LTTCOMM_NO_TRACE, /* No trace exist */
ca95a216 88 LTTCOMM_FATAL, /* Session daemon had a fatal error */
379473d2
DG
89 LTTCOMM_NO_TRACEABLE, /* Error for non traceable app */
90 LTTCOMM_SELECT_SESS, /* Must select a session */
27673bb6 91 LTTCOMM_EXIST_SESS, /* Session name already exist */
fac6795d
DG
92 LTTCOMM_NR, /* Last element */
93};
94
95/*
96 * Data structure for ltt-session received message
97 */
98struct lttcomm_session_msg {
99 /* Common data to almost all command */
100 enum lttcomm_command_type cmd_type;
8028d920 101 uuid_t session_id;
fac6795d
DG
102 char trace_name[NAME_MAX];
103 char session_name[NAME_MAX];
104 pid_t pid;
105 union {
106 struct {
107 int auto_session;
108 } create_session;
109 /* Marker data */
110 struct {
111 char channel[NAME_MAX];
112 char marker[NAME_MAX];
113 } marker;
114 /* SET_SOCK_PATH */
115 struct {
116 char sock_path[PATH_MAX];
117 } sock_path;
118 /* SET_SUBBUF_NUM */
119 struct {
120 unsigned int subbuf_num;
121 char channel[NAME_MAX];
122 } subbuf_num;
123 /* SET_SUBBUF_SIZE */
124 struct {
125 unsigned int subbuf_size;
126 char channel[NAME_MAX];
127 } subbuf_size;
128 } u;
129};
130
131/*
ca95a216
DG
132 * Data structure for the lttng client response.
133 *
134 * This data structure is the control struct use in
135 * the header of the transmission. NEVER put variable
136 * size data in here.
fac6795d
DG
137 */
138struct lttcomm_lttng_msg {
139 enum lttcomm_command_type cmd_type;
140 enum lttcomm_return_code ret_code;
8028d920 141 uuid_t session_id;
fac6795d
DG
142 pid_t pid;
143 char trace_name[NAME_MAX];
ca95a216 144 unsigned int size_payload;
fac6795d
DG
145};
146
147extern int lttcomm_create_unix_sock(const char *pathname);
148extern int lttcomm_connect_unix_sock(const char *pathname);
149extern int lttcomm_accept_unix_sock(int sock);
150extern int lttcomm_listen_unix_sock(int sock);
87378cf5 151extern int lttcomm_close_unix_sock(int sock);
fac6795d
DG
152extern ssize_t lttcomm_recv_unix_sock(int sock, void *buf, size_t len);
153extern ssize_t lttcomm_send_unix_sock(int sock, void *buf, size_t len);
154extern const char *lttcomm_get_readable_code(enum lttcomm_return_code code);
155
156#endif /* _LIBLTTSESSIONDCOMM_H */
This page took 0.028611 seconds and 4 git commands to generate.