~ubuntu-branches/ubuntu/gutsy/syslog-ng/gutsy-updates

« back to all changes in this revision

Viewing changes to src/afprogram.c

  • Committer: Bazaar Package Importer
  • Author(s): Magosányi Árpád (mag)
  • Date: 2004-03-13 18:35:37 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20040313183537-g0fsc2j2y1wbxage
Tags: 1.6.2-3
* changed manpage to better reflect -v. Closes: #228377
* fixed build-depends, hopefully correctly now:( Closes: #237668

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
 *
20
20
 * Inspired by nsyslog, originally written by Darren Reed.
21
21
 *
22
 
 * $Id: afprogram.c,v 1.5 2001/07/08 17:04:21 bazsi Exp $
 
22
 * $Id: afprogram.c,v 1.7 2003/01/31 14:26:48 bazsi Exp $
23
23
 *
24
24
 ***************************************************************************/
25
25
 
37
37
#include <fcntl.h>
38
38
 
39
39
#include "afprogram.c.x"
 
40
#include "macros.h"
40
41
 
41
42
/* CLASS:
42
43
   (class
44
45
     (super log_dest_driver)
45
46
     (vars
46
47
       (progname string)
47
 
       (dest object io_fd)))
 
48
       (dest object io_fd)
 
49
       (template_output string)
 
50
       (template_escape . int)
 
51
       (cfg object syslog_config)))
48
52
*/
49
53
 
50
54
/* CLASS:
55
59
       (pid simple pid_t)
56
60
       (dest object io_fd)))
57
61
*/
 
62
void
 
63
afprogram_dest_set_template(struct log_dest_driver *c, char *t)
 
64
{
 
65
        CAST(afprogram_dest, self, c);
 
66
 
 
67
        self->template_output = c_format("%z", t);
 
68
}
 
69
 
 
70
void
 
71
afprogram_dest_set_template_escape(struct log_dest_driver *c, int enable)
 
72
{
 
73
        CAST(afprogram_dest, self, c);
 
74
 
 
75
        self->template_escape = enable;
 
76
}
 
77
 
58
78
 
59
79
static void do_kill_child(struct resource *c)
60
80
{
94
114
        }
95
115
        else {
96
116
                NEW(afprogram_child, prg);
 
117
                self->cfg = cfg;
97
118
 
98
119
                prg->super.kill = do_kill_child;
99
120
                prg->pid = pid;
101
122
 
102
123
                close(msgpipe[0]);
103
124
                self->dest = io_write(make_io_fd(cfg->backend, msgpipe[1], NULL),
104
 
                                      make_pkt_buffer(cfg->log_fifo_size),
 
125
                                      make_pkt_buffer_ext(0, cfg->log_fifo_size, 0),
105
126
                                      NULL);
106
127
                REMEMBER_RESOURCE(cfg->resources, &self->dest->super.super);
107
128
        }
109
130
        return ST_OK | ST_GOON;
110
131
}
111
132
 
112
 
static void do_handle_afprogram_dest(struct log_handler *c, 
 
133
 
 
134
 
 
135
static void
 
136
do_handle_afprogram_dest(struct log_handler *c, 
113
137
                                     struct log_info *msg)
114
138
{
115
139
        CAST(afprogram_dest, self, c);
116
140
 
117
 
        if (self->dest)
118
 
                A_WRITE_STRING(&self->dest->buffer->super, 
119
 
                               c_format("<%i>%S %S %S\n", 
120
 
                                        msg->pri, 
121
 
                                        msg->date, 
122
 
                                        msg->host, 
123
 
                                        msg->msg));
 
141
        if (self->dest) {
 
142
                struct ol_string *msg_line;
 
143
 
 
144
                if (self->template_output) {
 
145
                        msg_line = c_format("<%i>%fS",
 
146
                                            msg->pri,
 
147
                                            expand_macros(
 
148
                                                    self->cfg,
 
149
                                                    self->template_output,
 
150
                                                    self->template_escape, msg));
 
151
                } else {
 
152
                        msg_line = c_format("<%i>%S %S %S\n",
 
153
                                            msg->pri,
 
154
                                            msg->date, msg->host, msg->msg);
 
155
                }
 
156
                A_WRITE_STRING(&self->dest->buffer->super, msg_line);
 
157
        } 
124
158
        log_info_free(msg);
125
159
}
126
160