~ubuntu-branches/ubuntu/karmic/rsyslog/karmic-200908151517

« back to all changes in this revision

Viewing changes to plugins/omtesting/omtesting.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2008-04-23 16:46:39 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080423164639-5acmt8a4vpxjgnxw
Tags: 3.14.2-3
* debian/rsyslog-doc.install
  - Fix a typo in the install path of the dia files. Closes: #477489
    Thanks to Justin B Rye for the patch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* omtesting.c
 
2
 *
 
3
 * This module is a testing aid. It is not meant to be used in production. I have
 
4
 * initially written it to introduce delays of custom length to action processing.
 
5
 * This is needed for development of new message queueing methods. However, I think
 
6
 * there are other uses for this module. For example, I can envision that it is a good
 
7
 * thing to have an output module that requests a retry on every "n"th invocation
 
8
 * and such things. I implement only what I need. But should further testing needs
 
9
 * arise, it makes much sense to add them here.
 
10
 *
 
11
 * This module will become part of the CVS and the rsyslog project because I think
 
12
 * it is a generally useful debugging, testing and development aid for everyone
 
13
 * involved with rsyslog.
 
14
 *
 
15
 * CURRENT SUPPORTED COMMANDS:
 
16
 *
 
17
 * :omtesting:sleep <seconds> <milliseconds>
 
18
 *
 
19
 * Must be specified exactly as above. Keep in mind milliseconds are a millionth
 
20
 * of a second!
 
21
 *
 
22
 * NOTE: read comments in module-template.h to understand how this file
 
23
 *       works!
 
24
 *
 
25
 * Copyright 2007 Rainer Gerhards and Adiscon GmbH.
 
26
 *
 
27
 * This file is part of rsyslog.
 
28
 *
 
29
 * Rsyslog is free software: you can redistribute it and/or modify
 
30
 * it under the terms of the GNU General Public License as published by
 
31
 * the Free Software Foundation, either version 3 of the License, or
 
32
 * (at your option) any later version.
 
33
 *
 
34
 * Rsyslog is distributed in the hope that it will be useful,
 
35
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
36
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
37
 * GNU General Public License for more details.
 
38
 *
 
39
 * You should have received a copy of the GNU General Public License
 
40
 * along with Rsyslog.  If not, see <http://www.gnu.org/licenses/>.
 
41
 *
 
42
 * A copy of the GPL can be found in the file "COPYING" in this distribution.
 
43
 */
 
44
#include "config.h"
 
45
#include "rsyslog.h"
 
46
#include <stdio.h>
 
47
#include <stdarg.h>
 
48
#include <stdlib.h>
 
49
#include <string.h>
 
50
#include <ctype.h>
 
51
#include <assert.h>
 
52
#include "syslogd.h"
 
53
#include "syslogd-types.h"
 
54
#include "module-template.h"
 
55
 
 
56
MODULE_TYPE_OUTPUT
 
57
 
 
58
/* internal structures
 
59
 */
 
60
DEF_OMOD_STATIC_DATA
 
61
 
 
62
typedef struct _instanceData {
 
63
        int     iWaitSeconds;
 
64
        int     iWaitUSeconds;  /* milli-seconds (one million of a second, just to make sure...) */
 
65
} instanceData;
 
66
 
 
67
BEGINcreateInstance
 
68
CODESTARTcreateInstance
 
69
        pData->iWaitSeconds = 1;
 
70
        pData->iWaitUSeconds = 0;
 
71
ENDcreateInstance
 
72
 
 
73
 
 
74
BEGINdbgPrintInstInfo
 
75
CODESTARTdbgPrintInstInfo
 
76
        dbgprintf("Action delays rule by %d second(s) and %d millisecond(s)\n",
 
77
                  pData->iWaitSeconds, pData->iWaitUSeconds);
 
78
        /* do nothing */
 
79
ENDdbgPrintInstInfo
 
80
 
 
81
 
 
82
BEGINisCompatibleWithFeature
 
83
CODESTARTisCompatibleWithFeature
 
84
        /* we are not compatible with repeated msg reduction feature, so do not allow it */
 
85
ENDisCompatibleWithFeature
 
86
 
 
87
 
 
88
BEGINtryResume
 
89
CODESTARTtryResume
 
90
ENDtryResume
 
91
 
 
92
BEGINdoAction
 
93
CODESTARTdoAction
 
94
        struct timeval tvSelectTimeout;
 
95
 
 
96
        dbgprintf("sleep(%d, %d)\n", pData->iWaitSeconds, pData->iWaitUSeconds);
 
97
        tvSelectTimeout.tv_sec = pData->iWaitSeconds;
 
98
        tvSelectTimeout.tv_usec = pData->iWaitUSeconds; /* milli seconds */
 
99
        select(0, NULL, NULL, NULL, &tvSelectTimeout);
 
100
        //dbgprintf(":omtesting: end doAction(), iRet %d\n", iRet);
 
101
ENDdoAction
 
102
 
 
103
 
 
104
BEGINfreeInstance
 
105
CODESTARTfreeInstance
 
106
        /* we do not have instance data, so we do not need to
 
107
         * do anything here. -- rgerhards, 2007-07-25
 
108
         */
 
109
ENDfreeInstance
 
110
 
 
111
 
 
112
BEGINparseSelectorAct
 
113
        int i;
 
114
        uchar szBuf[1024];
 
115
CODESTARTparseSelectorAct
 
116
CODE_STD_STRING_REQUESTparseSelectorAct(0)
 
117
        /* code here is quick and dirty - if you like, clean it up. But keep
 
118
         * in mind it is just a testing aid ;) -- rgerhards, 2007-12-31
 
119
         */
 
120
        if(!strncmp((char*) p, ":omtesting:", sizeof(":omtesting:") - 1)) {
 
121
                p += sizeof(":omtesting:") - 1; /* eat indicator sequence (-1 because of '\0'!) */
 
122
        } else {
 
123
                ABORT_FINALIZE(RS_RET_CONFLINE_UNPROCESSED);
 
124
        }
 
125
 
 
126
        /* ok, if we reach this point, we have something for us */
 
127
        if((iRet = createInstance(&pData)) != RS_RET_OK)
 
128
                goto finalize_it;
 
129
        
 
130
        /* check mode */
 
131
        for(i = 0 ; *p && !isspace((char) *p) && ((unsigned) i < sizeof(szBuf) - 1) ; ++i) {
 
132
                szBuf[i] = (uchar) *p++;
 
133
        }
 
134
        szBuf[i] = '\0';
 
135
        if(isspace(*p))
 
136
                ++p;
 
137
 
 
138
        if(!strcmp((char*) szBuf, "sleep")) {
 
139
                /* parse seconds */
 
140
                for(i = 0 ; *p && !isspace(*p) && ((unsigned) i < sizeof(szBuf) - 1) ; ++i) {
 
141
                        szBuf[i] = *p++;
 
142
                }
 
143
                szBuf[i] = '\0';
 
144
                if(isspace(*p))
 
145
                        ++p;
 
146
                pData->iWaitSeconds = atoi((char*) szBuf);
 
147
                /* parse milliseconds */
 
148
                for(i = 0 ; *p && !isspace(*p) && ((unsigned) i < sizeof(szBuf) - 1) ; ++i) {
 
149
                        szBuf[i] = *p++;
 
150
                }
 
151
                szBuf[i] = '\0';
 
152
                if(isspace(*p))
 
153
                        ++p;
 
154
                pData->iWaitUSeconds = atoi((char*) szBuf);
 
155
        }
 
156
        /* once there are other modes, here is the spot to add it! */
 
157
        else {
 
158
                dbgprintf("invalid mode '%s', doing 'sleep 1 0' - fix your config\n", szBuf);
 
159
        }
 
160
 
 
161
CODE_STD_FINALIZERparseSelectorAct
 
162
ENDparseSelectorAct
 
163
 
 
164
 
 
165
BEGINmodExit
 
166
CODESTARTmodExit
 
167
ENDmodExit
 
168
 
 
169
 
 
170
BEGINqueryEtryPt
 
171
CODESTARTqueryEtryPt
 
172
CODEqueryEtryPt_STD_OMOD_QUERIES
 
173
ENDqueryEtryPt
 
174
 
 
175
 
 
176
BEGINmodInit()
 
177
CODESTARTmodInit
 
178
        *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
 
179
CODEmodInit_QueryRegCFSLineHdlr
 
180
ENDmodInit
 
181
/*
 
182
 * vi:set ai:
 
183
 */