Commit | Line | Data |
---|---|---|
d4a1283e JD |
1 | /* |
2 | * Copyright (C) 2011 - Julien Desfossez <julien.desfossez@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 | |
82a3637f DG |
6 | * as published by the Free Software Foundation; only version 2 |
7 | * of the License. | |
d4a1283e JD |
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 | ||
1ce86c9a JD |
19 | #ifndef _LIBLTTKCONSUMERD_H |
20 | #define _LIBLTTKCONSUMERD_H | |
d4a1283e | 21 | |
e88129fc | 22 | #include <lttng-sessiond-comm.h> |
5dc18550 DG |
23 | #include "lttng-kconsumerd.h" |
24 | ||
1ce86c9a JD |
25 | /* |
26 | * When the receiving thread dies, we need to have a way to make | |
27 | * the polling thread exit eventually. | |
28 | * If all FDs hang up (normal case when the ltt-sessiond stops), | |
29 | * we can exit cleanly, but if there is a problem and for whatever | |
30 | * reason some FDs remain open, the consumer should still exit eventually. | |
31 | * | |
32 | * If the timeout is reached, it means that during this period | |
33 | * no events occurred on the FDs so we need to force an exit. | |
34 | * This case should not happen but it is a safety to ensure we won't block | |
35 | * the consumer indefinitely. | |
36 | * | |
37 | * The value of 2 seconds is an arbitrary choice. | |
38 | */ | |
39 | #define KCONSUMERD_POLL_GRACE_PERIOD 2000 | |
40 | ||
41 | struct kconsumerd_fd_list { | |
d4a1283e JD |
42 | struct cds_list_head head; |
43 | }; | |
44 | ||
45 | /* | |
46 | * Internal representation of the FDs, | |
47 | * sessiond_fd is used to identify uniquely a fd | |
48 | */ | |
1ce86c9a | 49 | struct kconsumerd_fd { |
d4a1283e JD |
50 | struct cds_list_head list; |
51 | int sessiond_fd; /* used to identify uniquely a fd with sessiond */ | |
52 | int consumerd_fd; /* fd to consume */ | |
53 | int out_fd; /* output file to write the data */ | |
54 | off_t out_fd_offset; /* write position in the output file descriptor */ | |
55 | char path_name[PATH_MAX]; /* tracefile name */ | |
5dc18550 | 56 | enum kconsumerd_fd_state state; |
d4a1283e JD |
57 | unsigned long max_sb_size; /* the subbuffer size for this channel */ |
58 | }; | |
59 | ||
c72c2927 JD |
60 | /* |
61 | * kconsumerd_init(void) | |
62 | * initialise the necessary environnement : | |
63 | * - inform the polling thread to update the polling array | |
64 | * - create the poll_pipe | |
65 | * - create the should_quit pipe (for signal handler) | |
66 | * returns the return code of pipe, 0 on success, -1 on error | |
67 | */ | |
4de84ad9 | 68 | int kconsumerd_init(void); |
c72c2927 JD |
69 | |
70 | /* | |
71 | * kconsumerd_send_error | |
72 | * send return code to ltt-sessiond | |
73 | * returns the return code of sendmsg : the number of bytes transmitted | |
74 | * or -1 on error. | |
75 | */ | |
1ce86c9a | 76 | int kconsumerd_send_error(enum lttcomm_return_code cmd); |
c72c2927 JD |
77 | |
78 | /* | |
79 | * kconsumerd_poll_socket | |
80 | * Poll on the should_quit pipe and the command socket | |
81 | * return -1 on error and should exit, 0 if data is | |
82 | * available on the command socket | |
83 | */ | |
4de84ad9 | 84 | int kconsumerd_poll_socket(struct pollfd *kconsumerd_sockpoll); |
c72c2927 JD |
85 | |
86 | /* | |
87 | * kconsumerd_thread_poll_fds | |
88 | * This thread polls the fds in the ltt_fd_list to consume the data | |
89 | * and write it to tracefile if necessary. | |
90 | */ | |
1ce86c9a | 91 | void *kconsumerd_thread_poll_fds(void *data); |
c72c2927 JD |
92 | |
93 | /* | |
94 | * kconsumerd_thread_receive_fds | |
95 | * This thread listens on the consumerd socket and | |
96 | * receives the file descriptors from ltt-sessiond | |
97 | */ | |
1ce86c9a | 98 | void *kconsumerd_thread_receive_fds(void *data); |
c72c2927 JD |
99 | |
100 | /* | |
101 | * kconsumerd_should_exit | |
102 | * Called from signal handler to ensure a clean exit | |
103 | */ | |
3dcd2721 | 104 | void kconsumerd_should_exit(void); |
c72c2927 JD |
105 | |
106 | /* | |
107 | * kconsumerd_cleanup | |
108 | * Cleanup the daemon's socket on exit | |
109 | */ | |
3dcd2721 | 110 | void kconsumerd_cleanup(void); |
c72c2927 JD |
111 | |
112 | /* | |
113 | * kconsumerd_set_error_socket | |
114 | * Set the error socket for communication with a session daemon | |
115 | */ | |
1ce86c9a | 116 | void kconsumerd_set_error_socket(int sock); |
c72c2927 JD |
117 | |
118 | /* | |
119 | * kconsumerd_set_command_socket_path | |
120 | * Set the command socket path for communication with a session daemon | |
121 | */ | |
1ce86c9a JD |
122 | void kconsumerd_set_command_socket_path(char *sock); |
123 | ||
124 | #endif /* _LIBLTTKCONSUMERD_H */ |