1 /* omdiscard.c 2 * This is the implementation of the built-in discard output module. 3 * 4 * NOTE: read comments in module-template.h to understand how this file 5 * works! 6 * 7 * File begun on 2007-07-24 by RGerhards 8 * 9 * Copyright 2007-2013 Adiscon GmbH. 10 * 11 * This file is part of rsyslog. 12 * 13 * Licensed under the Apache License, Version 2.0 (the "License"); 14 * you may not use this file except in compliance with the License. 15 * You may obtain a copy of the License at 16 * 17 * http://www.apache.org/licenses/LICENSE-2.0 18 * -or- 19 * see COPYING.ASL20 in the source distribution 20 * 21 * Unless required by applicable law or agreed to in writing, software 22 * distributed under the License is distributed on an "AS IS" BASIS, 23 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 24 * See the License for the specific language governing permissions and 25 * limitations under the License. 26 */ 27 #include "config.h" 28 #include "rsyslog.h" 29 #include <stdio.h> 30 #include <stdarg.h> 31 #include <stdlib.h> 32 #include <string.h> 33 #include <assert.h> 34 #include "syslogd.h" 35 #include "syslogd-types.h" 36 #include "omdiscard.h" 37 #include "module-template.h" 38 #include "errmsg.h" 39 40 MODULE_TYPE_OUTPUT 41 MODULE_TYPE_NOKEEP 42 43 /* internal structures 44 */ 45 DEF_OMOD_STATIC_DATA 46 47 typedef struct _instanceData { 48 EMPTY_STRUCT 49 } instanceData; 50 51 typedef struct wrkrInstanceData { 52 instanceData *pData; 53 } wrkrInstanceData_t; 54 55 /* we do not need a createInstance()! 56 BEGINcreateInstance 57 CODESTARTcreateInstance 58 ENDcreateInstance 59 */ 60 61 62 BEGINcreateWrkrInstance 63 CODESTARTcreateWrkrInstance 64 ENDcreateWrkrInstance 65 66 67 BEGINdbgPrintInstInfo 68 CODESTARTdbgPrintInstInfo 69 /* do nothing */ 70 ENDdbgPrintInstInfo 71 72 73 BEGINisCompatibleWithFeature 74 CODESTARTisCompatibleWithFeature 75 /* we are not compatible with repeated msg reduction feature, so do not allow it */ 76 ENDisCompatibleWithFeature 77 78 79 BEGINtryResume 80 CODESTARTtryResume 81 ENDtryResume 82 83 BEGINdoAction_NoStrings 84 CODESTARTdoAction 85 (void)pMsgData; /* Suppress compiler warning on unused var */ 86 dbgprintf("\n"); 87 iRet = RS_RET_DISCARDMSG; 88 ENDdoAction 89 90 91 BEGINfreeInstance 92 CODESTARTfreeInstance 93 /* we do not have instance data, so we do not need to 94 * do anything here. -- rgerhards, 2007-07-25 95 */ 96 ENDfreeInstance 97 98 99 BEGINfreeWrkrInstance 100 CODESTARTfreeWrkrInstance 101 ENDfreeWrkrInstance 102 103 104 BEGINparseSelectorAct 105 CODESTARTparseSelectorAct 106 CODE_STD_STRING_REQUESTparseSelectorAct(0) 107 pData = NULL; /* this action does not have any instance data */ 108 p = *pp; 109 110 if(*p == '~') { 111 dbgprintf("discard\n"); 112 LogMsg(0, RS_RET_DEPRECATED, LOG_WARNING, 113 "warning: ~ action is deprecated, consider " 114 "using the 'stop' statement instead"); 115 } else { 116 iRet = RS_RET_CONFLINE_UNPROCESSED; 117 } 118 /* we do not use the macro 119 * CODE_STD_FINALIZERparseSelectorAct 120 * here as this causes a Coverity ID "false positive" (CID 185431). 121 * We don't see an issue with using the copy&pasted code as it is unlikly 122 * to change for this (outdated) module. 123 */ 124 finalize_it: ATTR_UNUSED; /* semi-colon needed according to gcc doc! */ 125 if(iRet == RS_RET_OK || iRet == RS_RET_OK_WARN || iRet == RS_RET_SUSPENDED) { 126 *ppModData = pData; 127 *pp = p; 128 } else { 129 /* cleanup, we failed */ 130 if(*ppOMSR != NULL) { 131 OMSRdestruct(*ppOMSR); 132 *ppOMSR = NULL; 133 } 134 } 135 /* END modified macro text */ 136 ENDparseSelectorAct 137 138 139 BEGINmodExit 140 CODESTARTmodExit 141 ENDmodExit 142 143 144 BEGINqueryEtryPt 145 CODESTARTqueryEtryPt 146 CODEqueryEtryPt_STD_OMOD_QUERIES 147 CODEqueryEtryPt_STD_OMOD8_QUERIES 148 ENDqueryEtryPt 149 150 151 BEGINmodInit(Discard) 152 CODESTARTmodInit 153 *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ 154 CODEmodInit_QueryRegCFSLineHdlr 155 ENDmodInit 156 /* 157 * vi:set ai: 158 */ 159