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

« back to all changes in this revision

Viewing changes to lib/ivykis/lib/iv_method_poll.c

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS), Gergely Nagy
  • Date: 2011-10-11 14:30:48 UTC
  • mfrom: (1.3.7)
  • Revision ID: package-import@ubuntu.com-20111011143048-r1iljux9xbvj3lwh
Tags: 3.3.1.dfsg-1
* New upstream release with important fixes from upstream git tree with
  non-free manpages removed.
* Drop syslog-ng.conf(5) (closes: #496521).
* syslog-ng(8) is generated, and does not mention -Q anymore
  (closes: #616069).
* Supports CAP_SYSLOG on recent kernels (closes: #630172).
* Does not use g_timeout_add_seconds anymore (closes: #609154).

[ Gergely Nagy <algernon@madhouse-project.org> ]
* Update debian/copyright to DEP-5 format.
* Simplified the logrotate file by merging identical entries.
* Include local configuration files from /etc/syslog-ng/conf.d/ (Closes:
  #609050).
* Update syslog-ng.conf to be fully 3.3 compliant.
* Compress both source and binaries (except the syslog-ng meta
  package) with xz, instead of gzip.
* Use dpkg triggers to restart syslog-ng when appropriate.
* Include DFSG-free manual pages for all binaries.
* Build with Hardening enabled.
* Mention syslog(3) in /etc/default/syslog-ng, instead of
  <linux/kernel.h> (Closes: #608605)
* Support 'status' in the init script.
  Patch from Peter Eisentraut <petere@debian.org> (Closes: #644458)
* Build-Depend on libevtlog-dev (>= 0.2.12-5~) for correct shlibs.
* Use [linux-any] in Build-Depends instead of hardcoded links.
  (Closes: #634715)
* Use $SYSLOGNG_OPTS in the init script when reloading syslog-ng.
  (Closes: #589081)

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 <stdio.h>
 
22
#include <stdlib.h>
 
23
#include <stddef.h>
 
24
#include <string.h>
 
25
#include <syslog.h>
 
26
#include <sys/poll.h>
 
27
#include "iv_private.h"
 
28
#include "iv_thr.h"
 
29
 
 
30
#ifndef POLLMSG
 
31
#define POLLMSG         0
 
32
#endif
 
33
 
 
34
#ifndef POLLRDHUP
 
35
#define POLLRDHUP       0
 
36
#endif
 
37
 
 
38
#define SET_IN          (POLLIN | POLLPRI | POLLHUP | POLLRDNORM | \
 
39
                         POLLRDBAND | POLLMSG | POLLRDHUP)
 
40
#define SET_OUT         (POLLOUT | POLLWRNORM | POLLWRBAND)
 
41
#define SET_ERR         (POLLERR)
 
42
 
 
43
TLS_BLOCK_START
 
44
{
 
45
   struct pollfd        *pfds;
 
46
   struct iv_fd_        **fds;
 
47
   int                  num_registered_fds;
 
48
}
 
49
TLS_BLOCK_END;
 
50
 
 
51
#define pfds       __tls_deref(pfds)
 
52
#define fds        __tls_deref(fds)
 
53
#define num_registered_fds     __tls_deref(num_registered_fds)
 
54
 
 
55
static int iv_poll_init(int maxfd)
 
56
{
 
57
        pfds = malloc(maxfd * sizeof(struct pollfd));
 
58
        if (pfds == NULL)
 
59
                return -1;
 
60
 
 
61
        fds = malloc(maxfd * sizeof(struct iv_fd_ *));
 
62
        if (fds == NULL) {
 
63
                free(pfds);
 
64
                return -1;
 
65
        }
 
66
 
 
67
        num_registered_fds = 0;
 
68
 
 
69
        return 0;
 
70
}
 
71
 
 
72
static void iv_poll_poll(int numfds, struct list_head *active, int msec)
 
73
{
 
74
        int ret;
 
75
        int i;
 
76
 
 
77
#if _AIX
 
78
        /*
 
79
         * AIX sometimes leaves errno uninitialized even if poll
 
80
         * returns -1.
 
81
         */
 
82
        errno = EINTR;
 
83
#endif
 
84
 
 
85
        ret = poll(pfds, num_registered_fds, msec);
 
86
        if (ret < 0) {
 
87
                if (errno == EINTR)
 
88
                        return;
 
89
 
 
90
                fprintf(stderr, "iv_poll_poll: got error %d[%s]", errno,
 
91
                       strerror(errno));
 
92
                abort();
 
93
        }
 
94
 
 
95
        for (i = 0; i < num_registered_fds; i++) {
 
96
                struct iv_fd_ *fd = fds[i];
 
97
 
 
98
                if (pfds[i].revents & (SET_IN | SET_ERR))
 
99
                        iv_fd_make_ready(active, fd, MASKIN);
 
100
                if (pfds[i].revents & (SET_OUT | SET_ERR))
 
101
                        iv_fd_make_ready(active, fd, MASKOUT);
 
102
                if (pfds[i].revents & SET_ERR)
 
103
                        iv_fd_make_ready(active, fd, MASKERR);
 
104
        }
 
105
}
 
106
 
 
107
static void iv_poll_register_fd(struct iv_fd_ *fd)
 
108
{
 
109
        fd->index = -1;
 
110
}
 
111
 
 
112
static int bits_to_poll_mask(int bits)
 
113
{
 
114
        int mask;
 
115
 
 
116
        mask = 0;
 
117
        if (bits & MASKIN)
 
118
                mask |= SET_IN;
 
119
        if (bits & MASKOUT)
 
120
                mask |= SET_OUT;
 
121
        if (bits)
 
122
                mask |= SET_ERR;
 
123
 
 
124
        return mask;
 
125
}
 
126
 
 
127
static void iv_poll_notify_fd(struct iv_fd_ *fd, int wanted)
 
128
{
 
129
        if (fd->registered_bands == wanted)
 
130
                return;
 
131
 
 
132
        if (fd->index == -1 && wanted) {
 
133
                fd->index = num_registered_fds++;
 
134
                pfds[fd->index].fd = fd->fd;
 
135
                pfds[fd->index].events = bits_to_poll_mask(wanted);
 
136
                fds[fd->index] = fd;
 
137
        } else if (fd->index != -1 && !wanted) {
 
138
                if (fd->index != num_registered_fds - 1) {
 
139
                        struct iv_fd_ *last = fds[num_registered_fds - 1];
 
140
 
 
141
                        last->index = fd->index;
 
142
                        pfds[fd->index] = pfds[num_registered_fds - 1];
 
143
                        fds[fd->index] = last;
 
144
                }
 
145
                num_registered_fds--;
 
146
 
 
147
                fd->index = -1;
 
148
        } else {
 
149
                pfds[fd->index].events = bits_to_poll_mask(wanted);
 
150
        }
 
151
 
 
152
        fd->registered_bands = wanted;
 
153
}
 
154
 
 
155
static void iv_poll_deinit(void)
 
156
{
 
157
        free(fds);
 
158
        free(pfds);
 
159
}
 
160
 
 
161
 
 
162
struct iv_poll_method iv_method_poll = {
 
163
        .name           = "poll",
 
164
        .init           = iv_poll_init,
 
165
        .poll           = iv_poll_poll,
 
166
        .register_fd    = iv_poll_register_fd,
 
167
        .notify_fd      = iv_poll_notify_fd,
 
168
        .deinit         = iv_poll_deinit,
 
169
};