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

« back to all changes in this revision

Viewing changes to tools/iminternal.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Biebl
  • Date: 2009-04-08 00:59:14 UTC
  • mfrom: (1.1.9 upstream) (3.2.6 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090408005914-gfyay7o45szt05zl
Tags: 3.20.5-1
* New upstream release.
* debian/rsyslog.logcheck.ignore.server
  - Install a logcheck ignore file for rsyslog (using dh_installlogcheck).
    Thanks to Kim Holviala for the patch. Closes: #522164

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* iminternal.c
 
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
 
5
 * adapted.
 
6
 * 
 
7
 * File begun on 2007-08-03 by RGerhards
 
8
 *
 
9
 * Copyright 2007 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
 
 
31
#include <stdio.h>
 
32
#include <stdlib.h>
 
33
#include <string.h>
 
34
#include <assert.h>
 
35
 
 
36
#include "syslogd.h"
 
37
#include "linkedlist.h"
 
38
#include "iminternal.h"
 
39
 
 
40
static linkedList_t llMsgs;
 
41
 
 
42
 
 
43
/* destructs an iminternal object
 
44
 */
 
45
static rsRetVal iminternalDestruct(iminternal_t *pThis)
 
46
{
 
47
        DEFiRet;
 
48
 
 
49
        assert(pThis != NULL);
 
50
 
 
51
        if(pThis->pMsg != NULL)
 
52
                msgDestruct(&pThis->pMsg);
 
53
 
 
54
        free(pThis);
 
55
 
 
56
        RETiRet;
 
57
}
 
58
 
 
59
 
 
60
/* Construct an iminternal object
 
61
 */
 
62
static rsRetVal iminternalConstruct(iminternal_t **ppThis)
 
63
{
 
64
        DEFiRet;
 
65
        iminternal_t *pThis;
 
66
 
 
67
        assert(ppThis != NULL);
 
68
 
 
69
        if((pThis = (iminternal_t*) calloc(1, sizeof(iminternal_t))) == NULL) {
 
70
                ABORT_FINALIZE(RS_RET_OUT_OF_MEMORY);
 
71
        }
 
72
 
 
73
finalize_it:
 
74
        if(iRet != RS_RET_OK) {
 
75
                if(pThis != NULL)
 
76
                        iminternalDestruct(pThis);
 
77
        }
 
78
 
 
79
        *ppThis = pThis;
 
80
 
 
81
        RETiRet;
 
82
}
 
83
 
 
84
 
 
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".
 
91
 */
 
92
rsRetVal iminternalAddMsg(int pri, msg_t *pMsg, int flags)
 
93
{
 
94
        DEFiRet;
 
95
        iminternal_t *pThis;
 
96
 
 
97
        assert(pMsg != NULL);
 
98
 
 
99
        CHKiRet(iminternalConstruct(&pThis));
 
100
 
 
101
        pThis->pri = pri;
 
102
        pThis->pMsg = pMsg;
 
103
        pThis->flags = flags;
 
104
 
 
105
        CHKiRet(llAppend(&llMsgs,  NULL, (void*) pThis));
 
106
 
 
107
finalize_it:
 
108
        if(iRet != RS_RET_OK) {
 
109
                dbgprintf("iminternalAddMsg() error %d - can not otherwise report this error, message lost\n", iRet);
 
110
                if(pThis != NULL)
 
111
                        iminternalDestruct(pThis);
 
112
        }
 
113
 
 
114
        RETiRet;
 
115
}
 
116
 
 
117
 
 
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!
 
121
 */
 
122
rsRetVal iminternalRemoveMsg(int *pPri, msg_t **ppMsg, int *pFlags)
 
123
{
 
124
        DEFiRet;
 
125
        iminternal_t *pThis;
 
126
        linkedListCookie_t llCookie = NULL;
 
127
 
 
128
        assert(pPri != NULL);
 
129
        assert(ppMsg != NULL);
 
130
        assert(pFlags != NULL);
 
131
 
 
132
        CHKiRet(llGetNextElt(&llMsgs, &llCookie, (void*)&pThis));
 
133
        *pPri = pThis->pri;
 
134
        *pFlags = pThis->flags;
 
135
        *ppMsg = pThis->pMsg;
 
136
        pThis->pMsg = NULL; /* we do no longer own it - important for destructor */
 
137
 
 
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");
 
142
        }
 
143
 
 
144
finalize_it:
 
145
        RETiRet;
 
146
}
 
147
 
 
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
 
150
 * one message ready.
 
151
 */
 
152
rsRetVal iminternalHaveMsgReady(int* pbHaveOne)
 
153
{
 
154
        assert(pbHaveOne != NULL);
 
155
 
 
156
        return llGetNumElts(&llMsgs, pbHaveOne);
 
157
}
 
158
 
 
159
 
 
160
/* initialize the iminternal subsystem
 
161
 * must be called once at the start of the program
 
162
 */
 
163
rsRetVal modInitIminternal(void)
 
164
{
 
165
        DEFiRet;
 
166
 
 
167
        iRet = llInit(&llMsgs, iminternalDestruct, NULL, NULL);
 
168
 
 
169
        RETiRet;
 
170
}
 
171
 
 
172
 
 
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
 
177
 * them.
 
178
 */
 
179
rsRetVal modExitIminternal(void)
 
180
{
 
181
        DEFiRet;
 
182
 
 
183
        iRet = llDestroy(&llMsgs);
 
184
 
 
185
        RETiRet;
 
186
}
 
187
 
 
188
/*
 
189
 * vi:set ai:
 
190
 */