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 program is free software; you can redistribute it and/or
12
* modify it under the terms of the GNU General Public License
13
* as published by the Free Software Foundation; either version 2
14
* of the License, or (at your option) any later version.
16
* This program is distributed in the hope that it will be useful,
17
* but WITHOUT ANY WARRANTY; without even the implied warranty of
18
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
* GNU General Public License for more details.
21
* You should have received a copy of the GNU General Public License
22
* along with this program; if not, write to the Free Software
23
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25
* A copy of the GPL can be found in the file "COPYING" in this distribution.
36
#include "linkedlist.h"
37
#include "iminternal.h"
39
static linkedList_t llMsgs;
42
/* destructs an iminternal object
44
static rsRetVal iminternalDestruct(iminternal_t *pThis)
48
assert(pThis != NULL);
50
if(pThis->pMsg != NULL)
51
MsgDestruct(pThis->pMsg);
59
/* Construct an iminternal object
61
static rsRetVal iminternalConstruct(iminternal_t **ppThis)
66
assert(ppThis != NULL);
68
if((pThis = (iminternal_t*) calloc(1, sizeof(iminternal_t))) == NULL) {
69
ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
73
if(iRet != RS_RET_OK) {
75
iminternalDestruct(pThis);
84
/* add a message to the linked list
85
* Note: the pMsg reference counter is not incremented. Consequently,
86
* the caller must NOT decrement it. The caller actually hands over
87
* full ownership of the pMsg object.
88
* The interface of this function is modelled after syslogd/logmsg(),
89
* for which it is an "replacement".
91
rsRetVal iminternalAddMsg(int pri, msg_t *pMsg, int flags)
98
CHKiRet(iminternalConstruct(&pThis));
102
pThis->flags = flags;
104
CHKiRet(llAppend(&llMsgs, NULL, (void*) pThis));
107
if(iRet != RS_RET_OK) {
108
dbgprintf("iminternalAddMsg() error %d - can not otherwise report this error, message lost\n", iRet);
110
iminternalDestruct(pThis);
117
/* pull the first error message from the linked list, remove it
118
* from the list and return it to the caller. The caller is
119
* responsible for freeing the message!
121
rsRetVal iminternalRemoveMsg(int *pPri, msg_t **ppMsg, int *pFlags)
125
linkedListCookie_t llCookie = NULL;
127
assert(pPri != NULL);
128
assert(ppMsg != NULL);
129
assert(pFlags != NULL);
131
CHKiRet(llGetNextElt(&llMsgs, &llCookie, (void*)&pThis));
133
*pFlags = pThis->flags;
134
*ppMsg = pThis->pMsg;
135
pThis->pMsg = NULL; /* we do no longer own it - important for destructor */
137
if(llDestroyRootElt(&llMsgs) != RS_RET_OK) {
138
dbgprintf("Root element of iminternal linked list could not be destroyed - there is "
139
"nothing we can do against it, we ignore it for now. Things may go wild "
140
"from here on. This is most probably a program logic error.\n");
147
/* tell the caller if we have any messages ready for processing.
148
* 0 means we have none, everything else means there is at least
151
rsRetVal iminternalHaveMsgReady(int* pbHaveOne)
153
assert(pbHaveOne != NULL);
155
return llGetNumElts(&llMsgs, pbHaveOne);
159
/* initialize the iminternal subsystem
160
* must be called once at the start of the program
162
rsRetVal modInitIminternal(void)
166
iRet = llInit(&llMsgs, iminternalDestruct, NULL, NULL);
172
/* de-initialize the iminternal subsystem
173
* must be called once at the end of the program
174
* Note: the error list must have been pulled first. We do
175
* NOT care if there are any errors left - we simply destroy
178
rsRetVal modExitIminternal(void)
182
iRet = llDestroy(&llMsgs);