Fix possible NULL UST session on start trace
[lttng-tools.git] / lttng-sessiond / ust-app.h
1 /*
2 * Copyright (C) 2011 - David Goulet <david.goulet@polymtl.ca>
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; only version 2
7 * of the License.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17 */
18
19 #ifndef _LTT_UST_APP_H
20 #define _LTT_UST_APP_H
21
22 #include <stdint.h>
23 #include <urcu/list.h>
24
25 #include "trace-ust.h"
26
27 #define UST_APP_EVENT_LIST_SIZE 32
28
29 /*
30 * Application registration data structure.
31 */
32 struct ust_register_msg {
33 uint32_t major;
34 uint32_t minor;
35 pid_t pid;
36 pid_t ppid;
37 uid_t uid;
38 gid_t gid;
39 char name[16];
40 };
41
42 /*
43 * Global applications HT used by the session daemon.
44 */
45 struct cds_lfht *ust_app_ht;
46
47 struct cds_lfht *ust_app_sock_key_map;
48
49 struct ust_app_key {
50 pid_t pid;
51 int sock;
52 struct cds_lfht_node node;
53 };
54
55 struct ust_app_event {
56 int enabled;
57 int handle;
58 struct lttng_ust_object_data *obj;
59 char name[LTTNG_UST_SYM_NAME_LEN];
60 struct cds_lfht *ctx;
61 struct cds_lfht_node node;
62 };
63
64 struct ust_app_channel {
65 int enabled;
66 int handle;
67 char name[LTTNG_UST_SYM_NAME_LEN];
68 struct lttng_ust_channel attr;
69 struct lttng_ust_object_data *obj;
70 struct ltt_ust_stream_list streams;
71 struct cds_lfht *ctx;
72 struct cds_lfht *events;
73 struct cds_lfht_node node;
74 };
75
76 struct ust_app_session {
77 int enabled;
78 int handle; /* Used has unique identifier */
79 unsigned int uid;
80 struct ltt_ust_metadata *metadata;
81 struct lttng_ust_object_data *obj;
82 struct cds_lfht *channels; /* Registered channels */
83 struct cds_lfht_node node;
84 };
85
86 /*
87 * Registered traceable applications. Libust registers to the session daemon
88 * and a linked list is kept of all running traceable app.
89 */
90 struct ust_app {
91 pid_t ppid;
92 uid_t uid; /* User ID that owns the apps */
93 gid_t gid; /* Group ID that owns the apps */
94 uint32_t v_major; /* Verion major number */
95 uint32_t v_minor; /* Verion minor number */
96 char name[17]; /* Process name (short) */
97 struct cds_lfht *sessions;
98 struct cds_lfht_node node;
99 struct ust_app_key key;
100 };
101
102 #ifdef HAVE_LIBLTTNG_UST_CTL
103
104 int ust_app_register(struct ust_register_msg *msg, int sock);
105 void ust_app_unregister(int sock);
106 int ust_app_add_channel_all(struct ltt_ust_session *usess,
107 struct ltt_ust_channel *uchan);
108 int ust_app_add_event_all(struct ltt_ust_session *usess,
109 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent);
110 unsigned long ust_app_list_count(void);
111 int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app);
112 int ust_app_start_trace_all(struct ltt_ust_session *usess);
113 int ust_app_list_events(struct lttng_event **events);
114 void ust_app_global_update(struct ltt_ust_session *usess, int sock);
115
116 void ust_app_clean_list(void);
117 void ust_app_ht_alloc(void);
118 struct cds_lfht *ust_app_get_ht(void);
119 struct ust_app *ust_app_find_by_pid(pid_t pid);
120
121 #else /* HAVE_LIBLTTNG_UST_CTL */
122
123 static inline
124 int ust_app_start_trace(struct ltt_ust_session *usess, struct ust_app *app)
125 {
126 return 0;
127 }
128 static inline
129 int ust_app_start_trace_all(struct ltt_ust_session *usess)
130 {
131 return 0;
132 }
133 static inline
134 int ust_app_list_events(struct lttng_event **events)
135 {
136 return 0;
137 }
138 static inline
139 int ust_app_register(struct ust_register_msg *msg, int sock)
140 {
141 return -ENOSYS;
142 }
143 static inline
144 void ust_app_unregister(int sock)
145 {
146 }
147 static inline
148 unsigned int ust_app_list_count(void)
149 {
150 return 0;
151 }
152 static inline
153 void ust_app_lock_list(void)
154 {
155 }
156 static inline
157 void ust_app_unlock_list(void)
158 {
159 }
160 static inline
161 void ust_app_clean_list(void)
162 {
163 }
164 static inline
165 struct ust_app_list *ust_app_get_list(void)
166 {
167 return NULL;
168 }
169 static inline
170 struct ust_app *ust_app_get_by_pid(pid_t pid)
171 {
172 return NULL;
173 }
174 static inline
175 int ust_app_add_channel_all(struct ltt_ust_session *usess,
176 struct ltt_ust_channel *uchan)
177 {
178 return 0;
179 }
180 static inline
181 int ust_app_add_event_all(struct ltt_ust_session *usess,
182 struct ltt_ust_channel *uchan, struct ltt_ust_event *uevent)
183 {
184 return 0;
185 }
186 static inline
187 struct cds_lfht *ust_app_get_ht(void)
188 {
189 return NULL;
190 }
191 static inline
192 void ust_app_ht_alloc(void)
193 {
194 }
195 static inline
196 void ust_app_global_update(struct ltt_ust_session *usess, int sock)
197 {
198 }
199
200 #endif /* HAVE_LIBLTTNG_UST_CTL */
201
202 #endif /* _LTT_UST_APP_H */
This page took 0.033677 seconds and 4 git commands to generate.