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

« back to all changes in this revision

Viewing changes to lib/ivykis/modules/test/iv_popen_test.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) 2010 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 <iv.h>
 
24
#include <iv_popen.h>
 
25
 
 
26
#define NUM             4
 
27
 
 
28
struct req {
 
29
        struct iv_popen_request popen_req;
 
30
        char *argv[3];
 
31
        struct iv_fd popen_fd;
 
32
        struct iv_timer closeit;
 
33
};
 
34
 
 
35
static void done(struct req *req, int timeout)
 
36
{
 
37
        iv_popen_request_close(&req->popen_req);
 
38
 
 
39
        iv_fd_unregister(&req->popen_fd);
 
40
        close(req->popen_fd.fd);
 
41
 
 
42
        if (!timeout)
 
43
                iv_timer_unregister(&req->closeit);
 
44
}
 
45
 
 
46
static void got_data(void *_req)
 
47
{
 
48
        struct req *req = _req;
 
49
        char buf[1024];
 
50
        int ret;
 
51
 
 
52
        ret = read(req->popen_fd.fd, buf, sizeof(buf));
 
53
        if (ret <= 0) {
 
54
                if (ret == 0) {
 
55
                        fprintf(stderr, "got EOF\n");
 
56
                        done(req, 0);
 
57
                } else if (errno != EAGAIN && errno != EINTR) {
 
58
                        perror("read");
 
59
                        done(req, 0);
 
60
                }
 
61
 
 
62
                return;
 
63
        }
 
64
 
 
65
        printf("%p: ", req);
 
66
        fwrite(buf, 1, ret, stdout);
 
67
}
 
68
 
 
69
static void do_close(void *_req)
 
70
{
 
71
        struct req *req = _req;
 
72
 
 
73
        printf("%p: timeout expired, closing the popen request\n", req);
 
74
        done(req, 1);
 
75
}
 
76
 
 
77
static void open_child_request(struct req *req)
 
78
{
 
79
        int f;
 
80
 
 
81
        IV_POPEN_REQUEST_INIT(&req->popen_req);
 
82
        req->popen_req.file = "/usr/bin/vmstat";
 
83
        req->argv[0] = "/usr/bin/vmstat";
 
84
        req->argv[1] = "1";
 
85
        req->argv[2] = NULL;
 
86
        req->popen_req.argv = req->argv;
 
87
        req->popen_req.type = "r";
 
88
        f = iv_popen_request_submit(&req->popen_req);
 
89
 
 
90
        printf("submitted the popen request, fd is %d\n", f);
 
91
 
 
92
        IV_FD_INIT(&req->popen_fd);
 
93
        req->popen_fd.fd = f;
 
94
        req->popen_fd.cookie = req;
 
95
        req->popen_fd.handler_in = got_data;
 
96
        iv_fd_register(&req->popen_fd);
 
97
 
 
98
        IV_TIMER_INIT(&req->closeit);
 
99
        iv_validate_now();
 
100
        req->closeit.expires = iv_now;
 
101
        req->closeit.expires.tv_sec += 5;
 
102
        req->closeit.cookie = req;
 
103
        req->closeit.handler = do_close;
 
104
        iv_timer_register(&req->closeit);
 
105
}
 
106
 
 
107
int main()
 
108
{
 
109
        struct req req[NUM];
 
110
        int i;
 
111
 
 
112
        iv_init();
 
113
 
 
114
        for (i = 0; i < NUM; i++)
 
115
                open_child_request(&req[i]);
 
116
 
 
117
        iv_main();
 
118
 
 
119
        iv_deinit();
 
120
 
 
121
        return 0;
 
122
}