~ubuntu-branches/ubuntu/wily/syslog-ng/wily-proposed

« back to all changes in this revision

Viewing changes to lib/ivykis/lib/iv_private.h

  • Committer: Package Import Robot
  • Author(s): Gergely Nagy, Gergely Nagy
  • Date: 2013-11-04 15:27:37 UTC
  • mfrom: (1.3.12)
  • Revision ID: package-import@ubuntu.com-20131104152737-mqh6eqtna2xk97jq
Tags: 3.5.1-1
[ Gergely Nagy <algernon@madhouse-project.org> ]
* New upstream release.
  + Support auto-loading modules (Closes: #650814)
  + The SMTP module is available in syslog-ng-mod-smtp (Closes: #722746)
  + New modules: amqp, geoip, stomp, redis and smtp.
  + Multi-line input support (indented multiline and regexp-based)
  + Template type hinting for the MongoDB destination and $(format-json)
  + Support for unit suffixes in the configuration file
  + New filters, template functions and other miscellaneous changes
* New (team) maintainer, Laszlo Boszormenyi, Attila Szalay and myself
  added to Uploaders.
* Ship /var/lib/syslog-ng in the syslog-ng-core package, instead of
  creating it in the init script. Thanks Michael Biebl
  <biebl@debian.org> for the report & assistance. (Closes: #699942, #719910)
* Use dh-systemd for proper systemd-related maintainer scripts. Based on
  a patch by Michael Biebl <biebl@debian.org>. (Closes: #713982,
  #690067)
* Do not wait for syslog-ng to settle down during installation / update.
  This also fixes installing via debootstrap and a fake
  start-stop-daemon. (Closes: #714254)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * ivykis, an event handling library
3
 
 * Copyright (C) 2002, 2003, 2009 Lennert Buytenhek
4
 
 * Dedicated to Marija Kulikova.
5
 
 *
6
 
 * This library is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU Lesser General Public License version
8
 
 * 2.1 as published by the Free Software Foundation.
9
 
 *
10
 
 * This library 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 Lesser General Public License version 2.1 for more details.
14
 
 *
15
 
 * You should have received a copy of the GNU Lesser General Public
16
 
 * License version 2.1 along with this library; if not, write to the
17
 
 * Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18
 
 * Boston, MA 02110-1301, USA.
19
 
 */
20
 
 
21
 
#include "iv.h"
22
 
#include "iv_avl.h"
23
 
#include "iv_list.h"
24
 
#include "config.h"
25
 
 
26
 
/*
27
 
 * Per-thread state.
28
 
 */
29
 
#define NEED_SELECT
30
 
 
31
 
struct iv_state {
32
 
        /* iv_main.c  */
33
 
        struct iv_fd_           *handled_fd;
34
 
        int                     numfds;
35
 
        int                     quit;
36
 
 
37
 
        /* iv_task.c  */
38
 
        struct iv_list_head     tasks;
39
 
 
40
 
        /* iv_timer.c  */
41
 
        struct timespec         time;
42
 
        int                     time_valid;
43
 
        int                     num_timers;
44
 
        struct ratnode          *timer_root;
45
 
 
46
 
        /* poll methods  */
47
 
        union {
48
 
#ifdef HAVE_SYS_DEVPOLL_H
49
 
#undef NEED_SELECT
50
 
                struct {
51
 
                        struct iv_avl_tree      fds;
52
 
                        int                     poll_fd;
53
 
                        struct iv_list_head     notify;
54
 
                } dev_poll;
55
 
#endif
56
 
 
57
 
#ifdef HAVE_EPOLL_CREATE
58
 
#undef NEED_SELECT
59
 
                struct {
60
 
                        int                     epoll_fd;
61
 
                        struct iv_list_head     notify;
62
 
                } epoll;
63
 
#endif
64
 
 
65
 
#ifdef HAVE_KQUEUE
66
 
#undef NEED_SELECT
67
 
                struct {
68
 
                        int                     kqueue_fd;
69
 
                        struct iv_list_head     notify;
70
 
                } kqueue;
71
 
#endif
72
 
 
73
 
#ifdef HAVE_POLL
74
 
#undef NEED_SELECT
75
 
                struct {
76
 
                        struct pollfd           *pfds;
77
 
                        struct iv_fd_           **fds;
78
 
                        int                     num_registered_fds;
79
 
                } poll;
80
 
#endif
81
 
 
82
 
#ifdef HAVE_PORT_CREATE
83
 
#undef NEED_SELECT
84
 
                struct {
85
 
                        int                     port_fd;
86
 
                        struct iv_list_head     notify;
87
 
                } port;
88
 
#endif
89
 
 
90
 
#ifdef NEED_SELECT
91
 
                struct {
92
 
                        struct iv_avl_tree      fds;
93
 
                        void                    *sets;
94
 
                        int                     setsize;
95
 
                        int                     fd_max;
96
 
                } select;
97
 
#endif
98
 
        };
99
 
};
100
 
 
101
 
#ifdef HAVE_THREAD
102
 
extern __thread struct iv_state *__st;
103
 
 
104
 
static inline struct iv_state *iv_get_state(void)
105
 
{
106
 
        return __st;
107
 
}
108
 
#else
109
 
#include <pthread.h>
110
 
 
111
 
extern pthread_key_t iv_state_key;
112
 
 
113
 
static inline struct iv_state *iv_get_state(void)
114
 
{
115
 
        return pthread_getspecific(iv_state_key);
116
 
}
117
 
#endif
118
 
 
119
 
static inline void barrier(void)
120
 
{
121
 
        __asm__ __volatile__("" : : : "memory");
122
 
}
123
 
 
124
 
 
125
 
/*
126
 
 * Private versions of the fd/task/timer structures, exposing their
127
 
 * internal state.  The user data fields of these structures MUST
128
 
 * match the definitions in the public header file iv.h.
129
 
 */
130
 
struct iv_fd_ {
131
 
        /*
132
 
         * User data.
133
 
         */
134
 
        int                     fd;
135
 
        void                    *cookie;
136
 
        void                    (*handler_in)(void *);
137
 
        void                    (*handler_out)(void *);
138
 
        void                    (*handler_err)(void *);
139
 
 
140
 
        /*
141
 
         * If this fd gathered any events during this polling round,
142
 
         * fd->list_active will be on iv_main()'s active list, and
143
 
         * fd->ready_bands will indicate which bands are currently
144
 
         * active.
145
 
         */
146
 
        struct iv_list_head     list_active;
147
 
        unsigned                ready_bands:3;
148
 
 
149
 
        /*
150
 
         * Reflects whether the fd has been registered with
151
 
         * iv_fd_register().  Will be zero in ->notify_fd() if the
152
 
         * fd is being unregistered.
153
 
         */
154
 
        unsigned                registered:1;
155
 
 
156
 
        /*
157
 
         * ->wanted_bands is set by the ivykis core to indicate
158
 
         * which bands currenty have handlers registered for them.
159
 
         */
160
 
        unsigned                wanted_bands:3;
161
 
 
162
 
        /*
163
 
         * ->registered_bands is maintained by the poll method to
164
 
         * indicate which bands are currently registered with the
165
 
         * kernel, so that the ivykis core knows when to call
166
 
         * the poll method's ->notify_fd() on an fd.
167
 
         */
168
 
        unsigned                registered_bands:3;
169
 
 
170
 
#if defined(HAVE_SYS_DEVPOLL_H) || defined(HAVE_EPOLL_CREATE) ||        \
171
 
    defined(HAVE_KQUEUE) || defined(HAVE_PORT_CREATE)
172
 
        /*
173
 
         * ->list_notify is used by poll methods that defer updating
174
 
         * kernel registrations to ->poll() time.
175
 
         */
176
 
        struct iv_list_head     list_notify;
177
 
#endif
178
 
 
179
 
        /*
180
 
         * This is for state internal to some of the poll methods:
181
 
         * ->avl_node is used by poll methods that maintain an
182
 
         * internal fd tree, and ->index is used by iv_method_poll
183
 
         * to maintain the index of this fd in the list of pollfds.
184
 
         */
185
 
        union {
186
 
#if defined(HAVE_SYS_DEVPOLL_H) || defined(NEED_SELECT)
187
 
                struct iv_avl_node      avl_node;
188
 
#endif
189
 
#ifdef HAVE_POLL
190
 
                int                     index;
191
 
#endif
192
 
        };
193
 
};
194
 
 
195
 
struct iv_task_ {
196
 
        /*
197
 
         * User data.
198
 
         */
199
 
        void                    *cookie;
200
 
        void                    (*handler)(void *);
201
 
 
202
 
        /*
203
 
         * Private data.
204
 
         */
205
 
        struct iv_list_head     list;
206
 
};
207
 
 
208
 
struct iv_timer_ {
209
 
        /*
210
 
         * User data.
211
 
         */
212
 
        struct timespec         expires;
213
 
        void                    *cookie;
214
 
        void                    (*handler)(void *);
215
 
 
216
 
        /*
217
 
         * Private data.
218
 
         */
219
 
        int                     index;
220
 
};
221
 
 
222
 
 
223
 
/*
224
 
 * Misc internal stuff.
225
 
 */
226
 
#define MASKIN          1
227
 
#define MASKOUT         2
228
 
#define MASKERR         4
229
 
 
230
 
struct iv_poll_method {
231
 
        char    *name;
232
 
        int     (*init)(struct iv_state *st);
233
 
        void    (*poll)(struct iv_state *st, 
234
 
                        struct iv_list_head *active, struct timespec *to);
235
 
        void    (*register_fd)(struct iv_state *st, struct iv_fd_ *fd);
236
 
        void    (*unregister_fd)(struct iv_state *st, struct iv_fd_ *fd);
237
 
        void    (*notify_fd)(struct iv_state *st, struct iv_fd_ *fd);
238
 
        int     (*notify_fd_sync)(struct iv_state *st, struct iv_fd_ *fd);
239
 
        void    (*deinit)(struct iv_state *st);
240
 
};
241
 
 
242
 
static inline void
243
 
__iv_list_steal_elements(struct iv_list_head *oldh, struct iv_list_head *newh)
244
 
{
245
 
        struct iv_list_head *first = oldh->next;
246
 
        struct iv_list_head *last = oldh->prev;
247
 
 
248
 
        last->next = newh;
249
 
        first->prev = newh;
250
 
 
251
 
        newh->next = oldh->next;
252
 
        newh->prev = oldh->prev;
253
 
 
254
 
        oldh->next = oldh;
255
 
        oldh->prev = oldh;
256
 
}
257
 
 
258
 
/* iv_main.c */
259
 
extern int maxfd;
260
 
extern struct iv_poll_method *method;
261
 
 
262
 
/* poll methods */
263
 
extern struct iv_poll_method iv_method_dev_poll;
264
 
extern struct iv_poll_method iv_method_epoll;
265
 
extern struct iv_poll_method iv_method_kqueue;
266
 
extern struct iv_poll_method iv_method_poll;
267
 
extern struct iv_poll_method iv_method_port;
268
 
extern struct iv_poll_method iv_method_select;
269
 
 
270
 
 
271
 
/* iv_fd.c */
272
 
struct iv_fd_ *iv_fd_avl_find(struct iv_avl_tree *root, int fd);
273
 
int iv_fd_avl_compare(struct iv_avl_node *_a, struct iv_avl_node *_b);
274
 
void iv_fd_make_ready(struct iv_list_head *active,
275
 
                      struct iv_fd_ *fd, int bands);
276
 
 
277
 
/* iv_task.c */
278
 
void iv_task_init(struct iv_state *st);
279
 
int iv_pending_tasks(struct iv_state *st);
280
 
void iv_run_tasks(struct iv_state *st);
281
 
 
282
 
/* iv_timer.c */
283
 
void __iv_invalidate_now(struct iv_state *st);
284
 
void iv_timer_init(struct iv_state *st);
285
 
int iv_pending_timers(struct iv_state *st);
286
 
int iv_get_soonest_timeout(struct iv_state *st, struct timespec *to);
287
 
void iv_run_timers(struct iv_state *st);
288
 
void iv_timer_deinit(struct iv_state *st);
289
 
 
290
 
/* iv_tls.c */
291
 
int iv_tls_total_state_size(void);
292
 
void iv_tls_thread_init(struct iv_state *st);
293
 
void iv_tls_thread_deinit(struct iv_state *st);