2
* This file set implements the internal messages input module for rsyslog.
3
* Note: we currently do not have an input module spec, but
4
* we will have one in the future. This module needs then to be
7
* File begun on 2007-08-03 by RGerhards
9
* Copyright 2007 Rainer Gerhards and Adiscon GmbH.
11
* This file is part of rsyslog.
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.
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.
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/>.
26
* A copy of the GPL can be found in the file "COPYING" in this distribution.
37
#include "linkedlist.h"
38
#include "iminternal.h"
40
static linkedList_t llMsgs;
43
/* destructs an iminternal object
45
static rsRetVal iminternalDestruct(iminternal_t *pThis)
49
assert(pThis != NULL);
51
if(pThis->pMsg != NULL)
52
msgDestruct(&pThis->pMsg);
60
/* Construct an iminternal object
62
static rsRetVal iminternalConstruct(iminternal_t **ppThis)
67
assert(ppThis != NULL);
69
if((pThis = (iminternal_t*) calloc(1, sizeof(iminternal_t))) == NULL) {
70
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
74
if(iRet != RS_RET_OK) {
76
iminternalDestruct(pThis);
85
/* add a message to the linked list
86
* Note: the pMsg reference counter is not incremented. Consequently,
87
* the caller must NOT decrement it. The caller actually hands over
88
* full ownership of the pMsg object.
89
* The interface of this function is modelled after syslogd/logmsg(),
90
* for which it is an "replacement".
92
rsRetVal iminternalAddMsg(int pri, msg_t *pMsg, int flags)
99
CHKiRet(iminternalConstruct(&pThis));
103
pThis->flags = flags;
105
CHKiRet(llAppend(&llMsgs, NULL, (void*) pThis));
108
if(iRet != RS_RET_OK) {
109
dbgprintf("iminternalAddMsg() error %d - can not otherwise report this error, message lost\n", iRet);
111
iminternalDestruct(pThis);
118
/* pull the first error message from the linked list, remove it
119
* from the list and return it to the caller. The caller is
120
* responsible for freeing the message!
122
rsRetVal iminternalRemoveMsg(int *pPri, msg_t **ppMsg, int *pFlags)
126
linkedListCookie_t llCookie = NULL;
128
assert(pPri != NULL);
129
assert(ppMsg != NULL);
130
assert(pFlags != NULL);
132
CHKiRet(llGetNextElt(&llMsgs, &llCookie, (void*)&pThis));
134
*pFlags = pThis->flags;
135
*ppMsg = pThis->pMsg;
136
pThis->pMsg = NULL; /* we do no longer own it - important for destructor */
138
if(llDestroyRootElt(&llMsgs) != RS_RET_OK) {
139
dbgprintf("Root element of iminternal linked list could not be destroyed - there is "
140
"nothing we can do against it, we ignore it for now. Things may go wild "
141
"from here on. This is most probably a program logic error.\n");
148
/* tell the caller if we have any messages ready for processing.
149
* 0 means we have none, everything else means there is at least
152
rsRetVal iminternalHaveMsgReady(int* pbHaveOne)
154
assert(pbHaveOne != NULL);
156
return llGetNumElts(&llMsgs, pbHaveOne);
160
/* initialize the iminternal subsystem
161
* must be called once at the start of the program
163
rsRetVal modInitIminternal(void)
167
iRet = llInit(&llMsgs, iminternalDestruct, NULL, NULL);
173
/* de-initialize the iminternal subsystem
174
* must be called once at the end of the program
175
* Note: the error list must have been pulled first. We do
176
* NOT care if there are any errors left - we simply destroy
179
rsRetVal modExitIminternal(void)
183
iRet = llDestroy(&llMsgs);