~ubuntu-branches/ubuntu/lucid/rsyslog/lucid-updates

« back to all changes in this revision

Viewing changes to plugins/omstdout/omstdout.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-06-23 12:12:43 UTC
  • mfrom: (1.1.11 upstream) (3.2.8 sid)
  • Revision ID: james.westby@ubuntu.com-20090623121243-d2fejarzidywnn17
Tags: 4.2.0-1
* New upstream release of the now stable v4 branch.
  - Fix warnings when /etc/rsyslog.d/ is empty. Closes: #530228
* debian/patches/imudp_multiple_udp_sockets.patch
  - Removed, merged upstream.
* debian/rsyslog.default
  - Set default compat mode to '4'.
* debian/rsyslog.logcheck.ignore.server
  - Update logcheck rules files to also ignore rsyslogd and imklog stop
    messages.
* debian/control
  - Bump Standards-Version to 3.8.2. No further changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* omstdout.c
 
2
 * send all output to stdout - this is primarily a test driver (but may
 
3
 * be used for weired use cases). Not tested for robustness!
 
4
 *
 
5
 * NOTE: read comments in module-template.h for more specifics!
 
6
 *
 
7
 * File begun on 2009-03-19 by RGerhards
 
8
 *
 
9
 * Copyright 2009 Rainer Gerhards and Adiscon GmbH.
 
10
 *
 
11
 * This file is part of rsyslog.
 
12
 *
 
13
 * Rsyslog is free software: you can redistribute it and/or modify
 
14
 * it under the terms of the GNU General Public License as published by
 
15
 * the Free Software Foundation, either version 3 of the License, or
 
16
 * (at your option) any later version.
 
17
 *
 
18
 * Rsyslog is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
 * GNU General Public License for more details.
 
22
 *
 
23
 * You should have received a copy of the GNU General Public License
 
24
 * along with Rsyslog.  If not, see <http://www.gnu.org/licenses/>.
 
25
 *
 
26
 * A copy of the GPL can be found in the file "COPYING" in this distribution.
 
27
 */
 
28
#include "config.h"
 
29
#include "rsyslog.h"
 
30
#include <stdio.h>
 
31
#include <stdarg.h>
 
32
#include <stdlib.h>
 
33
#include <string.h>
 
34
#include <assert.h>
 
35
#include <signal.h>
 
36
#include <errno.h>
 
37
#include <unistd.h>
 
38
#include "dirty.h"
 
39
#include "syslogd-types.h"
 
40
#include "srUtils.h"
 
41
#include "template.h"
 
42
#include "module-template.h"
 
43
#include "errmsg.h"
 
44
#include "cfsysline.h"
 
45
 
 
46
MODULE_TYPE_OUTPUT
 
47
 
 
48
/* internal structures
 
49
 */
 
50
DEF_OMOD_STATIC_DATA
 
51
 
 
52
/* config variables */
 
53
static int bUseArrayInterface;          /* shall action use array instead of string template interface? */
 
54
 
 
55
 
 
56
typedef struct _instanceData {
 
57
        int bUseArrayInterface;         /* uses action use array instead of string template interface? */
 
58
} instanceData;
 
59
 
 
60
BEGINcreateInstance
 
61
CODESTARTcreateInstance
 
62
ENDcreateInstance
 
63
 
 
64
 
 
65
BEGINisCompatibleWithFeature
 
66
CODESTARTisCompatibleWithFeature
 
67
        if(eFeat == sFEATURERepeatedMsgReduction)
 
68
                iRet = RS_RET_OK;
 
69
ENDisCompatibleWithFeature
 
70
 
 
71
 
 
72
BEGINfreeInstance
 
73
CODESTARTfreeInstance
 
74
ENDfreeInstance
 
75
 
 
76
 
 
77
BEGINdbgPrintInstInfo
 
78
CODESTARTdbgPrintInstInfo
 
79
ENDdbgPrintInstInfo
 
80
 
 
81
 
 
82
BEGINtryResume
 
83
CODESTARTtryResume
 
84
ENDtryResume
 
85
 
 
86
BEGINdoAction
 
87
        char **szParams;
 
88
        char *toWrite;
 
89
        int iParamVal;
 
90
        int iParam;
 
91
        int iBuf;
 
92
        char szBuf[65564];
 
93
CODESTARTdoAction
 
94
        if(pData->bUseArrayInterface) {
 
95
                /* if we use array passing, we need to put together a string
 
96
                 * ourselves. At this point, please keep in mind that omstdout is
 
97
                 * primarily a testing aid. Other modules may do different processing
 
98
                 * if they would like to support downlevel versions which do not support
 
99
                 * array-passing, but also use that interface on cores who do...
 
100
                 * So this code here is also more or less an example of how to do that.
 
101
                 * rgerhards, 2009-04-03
 
102
                 */
 
103
                szParams = (char**) (ppString[0]);
 
104
                /* In array-passing mode, ppString[] contains a NULL-terminated array
 
105
                 * of char *pointers.
 
106
                 */
 
107
                iParam = 0;
 
108
                iBuf = 0;
 
109
                while(szParams[iParam] != NULL) {
 
110
                        if(iParam > 0)
 
111
                                szBuf[iBuf++] = ','; /* all but first need a delimiter */
 
112
                        iParamVal = 0;
 
113
                        while(szParams[iParam][iParamVal] != '\0' && iBuf < sizeof(szBuf)) {
 
114
                                szBuf[iBuf++] = szParams[iParam][iParamVal++];
 
115
                        }
 
116
                        ++iParam;
 
117
                }
 
118
                szBuf[iBuf] = '\0';
 
119
                toWrite = szBuf;
 
120
        } else {
 
121
                toWrite = (char*) ppString[0];
 
122
        }
 
123
        write(1, toWrite, strlen(toWrite)); /* 1 is stdout! */
 
124
ENDdoAction
 
125
 
 
126
 
 
127
BEGINparseSelectorAct
 
128
        int iTplOpts;
 
129
CODESTARTparseSelectorAct
 
130
CODE_STD_STRING_REQUESTparseSelectorAct(1)
 
131
        /* first check if this config line is actually for us */
 
132
        if(strncmp((char*) p, ":omstdout:", sizeof(":omstdout:") - 1)) {
 
133
                ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED);
 
134
        }
 
135
 
 
136
        /* ok, if we reach this point, we have something for us */
 
137
        p += sizeof(":omstdout:") - 1; /* eat indicator sequence  (-1 because of '\0'!) */
 
138
        CHKiRet(createInstance(&pData));
 
139
 
 
140
        /* check if a non-standard template is to be applied */
 
141
        if(*(p-1) == ';')
 
142
                --p;
 
143
        iTplOpts = (bUseArrayInterface == 0) ? 0 : OMSR_TPL_AS_ARRAY;
 
144
        CHKiRet(cflineParseTemplateName(&p, *ppOMSR, 0, iTplOpts, (uchar*) "RSYSLOG_FileFormat"));
 
145
        pData->bUseArrayInterface = bUseArrayInterface;
 
146
CODE_STD_FINALIZERparseSelectorAct
 
147
ENDparseSelectorAct
 
148
 
 
149
 
 
150
BEGINmodExit
 
151
CODESTARTmodExit
 
152
ENDmodExit
 
153
 
 
154
 
 
155
BEGINqueryEtryPt
 
156
CODESTARTqueryEtryPt
 
157
CODEqueryEtryPt_STD_OMOD_QUERIES
 
158
ENDqueryEtryPt
 
159
 
 
160
 
 
161
 
 
162
/* Reset config variables for this module to default values.
 
163
 */
 
164
static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
 
165
{
 
166
        DEFiRet;
 
167
        bUseArrayInterface = 0;
 
168
        RETiRet;
 
169
}
 
170
 
 
171
 
 
172
BEGINmodInit()
 
173
        rsRetVal localRet;
 
174
        rsRetVal (*pomsrGetSupportedTplOpts)(unsigned long *pOpts);
 
175
        unsigned long opts;
 
176
        int bArrayPassingSupported;             /* does core support template passing as an array? */
 
177
CODESTARTmodInit
 
178
        *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
 
179
CODEmodInit_QueryRegCFSLineHdlr
 
180
        /* check if the rsyslog core supports parameter passing code */
 
181
        bArrayPassingSupported = 0;
 
182
        localRet = pHostQueryEtryPt((uchar*)"OMSRgetSupportedTplOpts", &pomsrGetSupportedTplOpts);
 
183
        if(localRet == RS_RET_OK) {
 
184
                /* found entry point, so let's see if core supports array passing */
 
185
                CHKiRet((*pomsrGetSupportedTplOpts)(&opts));
 
186
                if(opts & OMSR_TPL_AS_ARRAY)
 
187
                        bArrayPassingSupported = 1;
 
188
        } else if(localRet != RS_RET_ENTRY_POINT_NOT_FOUND) {
 
189
                ABORT_FINALIZE(localRet); /* Something else went wrong, what is not acceptable */
 
190
        }
 
191
        DBGPRINTF("omstdout: array-passing is %ssupported by rsyslog core.\n", bArrayPassingSupported ? "" : "not ");
 
192
 
 
193
        if(bArrayPassingSupported) {
 
194
                /* enable config comand only if core supports it */
 
195
                CHKiRet(omsdRegCFSLineHdlr((uchar *)"actionomstdoutarrayinterface", 0, eCmdHdlrBinary, NULL,
 
196
                                           &bUseArrayInterface, STD_LOADABLE_MODULE_ID));
 
197
        }
 
198
        CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler,
 
199
                                    resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
 
200
ENDmodInit
 
201
 
 
202
/* vi:set ai:
 
203
 */