~ubuntu-branches/ubuntu/oneiric/rsyslog/oneiric

« back to all changes in this revision

Viewing changes to runtime/glbl.c

  • Committer: Dave Walker (Daviey)
  • Author(s): Scott Moser
  • Date: 2011-06-17 20:59:38 UTC
  • mfrom: (36.1.8 oneiric.merge)
  • Revision ID: davewalker@ubuntu.com-20110617205938-pfkizxz2wsgzi2ot
Tags: 5.8.1-1ubuntu1
* Resynchronise with Debian (LP: #794230).  Remaining changes:
  - Run as rsyslog:rsyslog, set $FileOwner to syslog
  - Replace init script with debian/rsyslog.upstart.
  - debian/rsyslog.logrotate: Use reload command to restart rsyslog
  - debian/rsyslog.conf: enable $RepeatedMsgReduction 
    to avoid bloating the syslog file (LP #453444)
  - Add debian/rsyslog.dmesg.upstart to save initial dmesg into a file.
    Install it in debian/rules.
  - debian/50-default.conf: set of default rules for syslog (forwarded to
    Debian #603160). remove file in postrm on purge. manage with ucf.
  - debian/rules: build with LDFLAGS=""
* Dropped:
  - debian/control: Bump build-dependency on debhelper
    debian now depends on dh >= 8
* New upstream release.
* Bump Standards-Version to 3.9.2. No further changes.
* Enable and install impstats module. (Closes: #620114)
* Update logcheck rule. (Closes: #616659)
* debian/rsyslog.init: Set correct compat level (5).
* The way rsyslog processes SIGHUP has changed. It no longer does a reload
  of its configuration, but simply closes all open files. To apply a changed
  configuration, rsyslogd needs to be restarted now.
  - Drop "reload" action from debian/rsyslog.init, map "force-reload" to
    "restart". (Closes: #580897)
  - Add "rotate" action to debian/rsyslog.init which sends SIGHUP to
    rsyslogd. Use that in debian/rsyslog.logrotate. (Closes: #626365)
  - Update debian/rsyslog-mysql.postinst and rsyslog-pgsql.postinst to use
    restart instead of reload.
  - Add a NEWS file explaining the changed SIGHUP handling.
* New upstream stable release.
* New upstream release.
  - Properly handle ANSI SQL strings in ompgsql. (Closes: #600479)
* New upstream release.
* debian/patches/02-pmaixforwardedfrom_type_nokeep.patch
  - Remove, merged upstream.
* debian/patches/03-epoll_create1-fallback.patch
  - Remove, merged upstream.
* debian/patches/03-epoll_create1-fallback.patch
  - If epoll_create1() is not available during runtime, fall back to
    epoll_create(). This fixes remote syslog when runnig rsyslog on a
    lenny kernel. (Closes: #617996)
* New upstream release.
* debian/rsyslog.links
  - Create symlink for rsyslog.service in multi-user.target.wants so rsyslog
    is enabled by default when using systemd.
* debian/patches/02-pmaixforwardedfrom_type_nokeep.patch
  - Fix build failure in aixforwardedfrom parser module by setting the
    module type to NOKEEP.
* debian/rsyslog.preinst
  - Remove old rsyslog.socket symlink from sockets.target.wants on upgrades
    as rsyslog uses syslog.socket now which is provided by systemd.
* debian/rsyslog.install
  - Stop installing rsyslog.socket.
* New upstream release.
* New upstream release.
  - Fix regression in imuxsock plugin which did no longer sanitize received
    messages. This makes 02-cleanup-trailing-lf.patch obsolete and also
    fixes the SQL syntax errors in the mysql output if the input contained
    NUL bytes. Closes: #614061
* Enable and install omprog output plugin. Closes: #552095
* Improve package description. Closes: #612948
  Thanks to Justin B Rye for the patch.
* debian/patches/02-cleanup-trailing-lf.patch
  - Fix regression in imuxsock plugin which did not remove a trailing LF
    anymore. Patch cherry-picked from upstream Git. Closes: #612829
* New upstream release.
* Enable and install parser modules.
* New upstream release.
* Upload to unstable.
* debian/patches/02-typo_fix_equation_sign.patch
  - Removed, merged upstream.
* debian/patches/03-atomic_operations.patch
  - Removed, merged upstream.
* debian/patches/03-atomic_operations.patch
  - Fix build failures on platforms which don't have 64 bit atomic
    operations. Patch cherry-picked from upstream Git. Closes: #600930
* New upstream development release.
* Remove patches, merged upstream
  - debian/patches/02-install_also_rsyslog_socket.patch
  - debian/patches/02-tls_loop_fix.patch
* debian/patches/02-typo_fix_equation_sign.patch
  - Fix small typo ("equation sign"). Closes: #575589
* debian/rsyslog.postinst
  - Remove pre-lenny migration code to rotate old log files from sysklogd.
* New upstream development release.
* debian/rsyslog.install
  - Install omruleset.so plugin: http://www.rsyslog.com/doc/omruleset.html
* debian/rsyslog.default
  - Start rsyslogd with native -c5 mode.
* Install systemd unit files which allow to run rsyslog in socket activation
  mode when systemd is used.
* debian/patches/02-install_also_rsyslog_socket.patch
  - When enabling rsyslog.service also enable rsyslog.socket. Patch
    cherry-picked from upstream Git.
* Bump debhelper compatibility level to 8. Update Build-Depends accordingly.

Show diffs side-by-side

added added

removed removed

Lines of Context:
31
31
#include "config.h"
32
32
#include <stdlib.h>
33
33
#include <sys/socket.h>
 
34
#include <sys/types.h>
 
35
#include <sys/stat.h>
 
36
#include <unistd.h>
34
37
#include <assert.h>
35
38
 
36
39
#include "rsyslog.h"
39
42
#include "cfsysline.h"
40
43
#include "glbl.h"
41
44
#include "prop.h"
 
45
#include "atomic.h"
 
46
#include "errmsg.h"
42
47
 
43
48
/* some defaults */
44
49
#ifndef DFLT_NETSTRM_DRVR
48
53
/* static data */
49
54
DEFobjStaticHelpers
50
55
DEFobjCurrIf(prop)
 
56
DEFobjCurrIf(errmsg)
51
57
 
52
58
/* static data
53
59
 * For this object, these variables are obviously what makes the "meat" of the
55
61
 */
56
62
static uchar *pszWorkDir = NULL;
57
63
static int bOptimizeUniProc = 1;        /* enable uniprocessor optimizations */
58
 
static int bHUPisRestart = 0;           /* should SIGHUP cause a full system restart? */
 
64
static int bParseHOSTNAMEandTAG = 1;    /* parser modification (based on startup params!) */
59
65
static int bPreserveFQDN = 0;           /* should FQDNs always be preserved? */
60
66
static int iMaxLine = 2048;             /* maximum length of a syslog message */
61
67
static int iDefPFFamily = PF_UNSPEC;     /* protocol family (IPv4, IPv6 or both) */
64
70
static int bDisableDNS = 0; /* don't look up IP addresses of remote messages */
65
71
static prop_t *propLocalHostName = NULL;/* our hostname as FQDN - read-only after startup */
66
72
static uchar *LocalHostName = NULL;/* our hostname  - read-only after startup */
 
73
static uchar *LocalHostNameOverride = NULL;/* user-overridden hostname - read-only after startup */
67
74
static uchar *LocalFQDNName = NULL;/* our hostname as FQDN - read-only after startup */
68
75
static uchar *LocalDomain;      /* our local domain name  - read-only after startup */
69
76
static char **StripDomains = NULL;/* these domains may be stripped before writing logs  - r/o after s.u., never touched by init */
72
79
static uchar *pszDfltNetstrmDrvrCAF = NULL; /* default CA file for the netstrm driver */
73
80
static uchar *pszDfltNetstrmDrvrKeyFile = NULL; /* default key file for the netstrm driver (server) */
74
81
static uchar *pszDfltNetstrmDrvrCertFile = NULL; /* default cert file for the netstrm driver (server) */
 
82
static int bTerminateInputs = 0;                /* global switch that inputs shall terminate ASAP (1=> terminate) */
 
83
#ifndef HAVE_ATOMIC_BUILTINS
 
84
static DEF_ATOMIC_HELPER_MUT(mutTerminateInputs);
 
85
#endif
 
86
#ifdef USE_UNLIMITED_SELECT
 
87
static int iFdSetSize = howmany(FD_SETSIZE, __NFDBITS) * sizeof (fd_mask); /* size of select() bitmask in bytes */
 
88
#endif
75
89
 
76
90
 
77
91
/* define a macro for the simple properties' set and get functions
93
107
        return(nameVar); \
94
108
}
95
109
 
 
110
SIMP_PROP(ParseHOSTNAMEandTAG, bParseHOSTNAMEandTAG, int)
96
111
SIMP_PROP(OptimizeUniProc, bOptimizeUniProc, int)
97
112
SIMP_PROP(PreserveFQDN, bPreserveFQDN, int)
98
 
SIMP_PROP(HUPisRestart, bHUPisRestart, int)
99
113
SIMP_PROP(MaxLine, iMaxLine, int)
100
114
SIMP_PROP(DefPFFamily, iDefPFFamily, int) /* note that in the future we may check the family argument */
101
115
SIMP_PROP(DropMalPTRMsgs, bDropMalPTRMsgs, int)
104
118
SIMP_PROP(LocalDomain, LocalDomain, uchar*)
105
119
SIMP_PROP(StripDomains, StripDomains, char**)
106
120
SIMP_PROP(LocalHosts, LocalHosts, char**)
 
121
#ifdef USE_UNLIMITED_SELECT
 
122
SIMP_PROP(FdSetSize, iFdSetSize, int)
 
123
#endif
107
124
 
108
125
SIMP_PROP_SET(LocalFQDNName, LocalFQDNName, uchar*)
109
126
SIMP_PROP_SET(LocalHostName, LocalHostName, uchar*)
117
134
#undef SIMP_PROP_GET
118
135
 
119
136
 
 
137
/* return global input termination status
 
138
 * rgerhards, 2009-07-20
 
139
 */
 
140
static int GetGlobalInputTermState(void)
 
141
{
 
142
        return ATOMIC_FETCH_32BIT(&bTerminateInputs, &mutTerminateInputs);
 
143
}
 
144
 
 
145
 
 
146
/* set global termiantion state to "terminate". Note that this is a
 
147
 * "once in a lifetime" action which can not be undone. -- gerhards, 2009-07-20
 
148
 */
 
149
static void SetGlobalInputTermination(void)
 
150
{
 
151
        ATOMIC_STORE_1_TO_INT(&bTerminateInputs, &mutTerminateInputs);
 
152
}
 
153
 
 
154
 
 
155
/* This function is used to set the global work directory name. 
 
156
 * It verifies that the provided directory actually exists and
 
157
 * emits an error message if not.
 
158
 * rgerhards, 2011-02-16
 
159
 */
 
160
static rsRetVal setWorkDir(void __attribute__((unused)) *pVal, uchar *pNewVal)
 
161
{
 
162
        DEFiRet;
 
163
        struct stat sb;
 
164
 
 
165
        if(stat((char*) pNewVal, &sb) != 0) {
 
166
                errmsg.LogError(0, RS_RET_ERR_WRKDIR, "$WorkDirectory: %s can not be "
 
167
                                "accessed, probably does not exist - directive ignored", pNewVal);
 
168
                ABORT_FINALIZE(RS_RET_ERR_WRKDIR);
 
169
        }
 
170
 
 
171
        if(!S_ISDIR(sb.st_mode)) {
 
172
                errmsg.LogError(0, RS_RET_ERR_WRKDIR, "$WorkDirectory: %s not a directory - directive ignored", 
 
173
                                pNewVal);
 
174
                ABORT_FINALIZE(RS_RET_ERR_WRKDIR);
 
175
        }
 
176
 
 
177
        free(pszWorkDir);
 
178
        pszWorkDir = pNewVal;
 
179
 
 
180
finalize_it:
 
181
        RETiRet;
 
182
}
 
183
 
120
184
/* return our local hostname. if it is not set, "[localhost]" is returned
121
185
 */
122
186
static uchar*
124
188
{
125
189
        uchar *pszRet;
126
190
 
 
191
        if(LocalHostNameOverride != NULL) {
 
192
                pszRet = LocalHostNameOverride;
 
193
                goto done;
 
194
        }
 
195
 
127
196
        if(LocalHostName == NULL)
128
197
                pszRet = (uchar*) "[localhost]";
129
198
        else {
132
201
                else
133
202
                        pszRet = LocalHostName;
134
203
        }
 
204
done:
135
205
        return(pszRet);
136
206
}
137
207
 
150
220
                prop.Destruct(&propLocalHostName);
151
221
 
152
222
        CHKiRet(prop.Construct(&propLocalHostName));
153
 
        if(LocalHostName == NULL)
154
 
                pszName = (uchar*) "[localhost]";
155
 
        else {
156
 
                if(GetPreserveFQDN() == 1)
157
 
                        pszName = LocalFQDNName;
158
 
                else
159
 
                        pszName = LocalHostName;
 
223
        if(LocalHostNameOverride == NULL) {
 
224
                if(LocalHostName == NULL)
 
225
                        pszName = (uchar*) "[localhost]";
 
226
                else {
 
227
                        if(GetPreserveFQDN() == 1)
 
228
                                pszName = LocalFQDNName;
 
229
                        else
 
230
                                pszName = LocalHostName;
 
231
                }
 
232
        } else { /* local hostname is overriden via config */
 
233
                pszName = LocalHostNameOverride;
160
234
        }
 
235
        DBGPRINTF("GenerateLocalHostName uses '%s'\n", pszName);
161
236
        CHKiRet(prop.SetString(propLocalHostName, pszName, ustrlen(pszName)));
162
237
        CHKiRet(prop.ConstructFinalize(propLocalHostName));
163
238
 
165
240
        RETiRet;
166
241
}
167
242
 
 
243
 
168
244
/* return our local hostname as a string property
169
245
 */
170
246
static prop_t*
241
317
        pIf->GetWorkDir = GetWorkDir;
242
318
        pIf->GenerateLocalHostNameProperty = GenerateLocalHostNameProperty;
243
319
        pIf->GetLocalHostNameProp = GetLocalHostNameProp;
 
320
        pIf->SetGlobalInputTermination = SetGlobalInputTermination;
 
321
        pIf->GetGlobalInputTermState = GetGlobalInputTermState;
244
322
#define SIMP_PROP(name) \
245
323
        pIf->Get##name = Get##name; \
246
324
        pIf->Set##name = Set##name;
247
325
        SIMP_PROP(MaxLine);
248
326
        SIMP_PROP(OptimizeUniProc);
 
327
        SIMP_PROP(ParseHOSTNAMEandTAG);
249
328
        SIMP_PROP(PreserveFQDN);
250
 
        SIMP_PROP(HUPisRestart);
251
329
        SIMP_PROP(DefPFFamily);
252
330
        SIMP_PROP(DropMalPTRMsgs);
253
331
        SIMP_PROP(Option_DisallowWarning);
261
339
        SIMP_PROP(DfltNetstrmDrvrCAF)
262
340
        SIMP_PROP(DfltNetstrmDrvrKeyFile)
263
341
        SIMP_PROP(DfltNetstrmDrvrCertFile)
 
342
#ifdef USE_UNLIMITED_SELECT
 
343
        SIMP_PROP(FdSetSize)
 
344
#endif
264
345
#undef  SIMP_PROP
265
346
finalize_it:
266
347
ENDobjQueryInterface(glbl)
287
368
                free(pszDfltNetstrmDrvrCertFile);
288
369
                pszDfltNetstrmDrvrCertFile = NULL;
289
370
        }
 
371
        if(LocalHostNameOverride != NULL) {
 
372
                free(LocalHostNameOverride);
 
373
                LocalHostNameOverride = NULL;
 
374
        }
290
375
        if(pszWorkDir != NULL) {
291
376
                free(pszWorkDir);
292
377
                pszWorkDir = NULL;
293
378
        }
294
379
        bDropMalPTRMsgs = 0;
295
380
        bOptimizeUniProc = 1;
296
 
        bHUPisRestart = 0;
297
381
        bPreserveFQDN = 0;
 
382
#ifdef USE_UNLIMITED_SELECT
 
383
        iFdSetSize = howmany(FD_SETSIZE, __NFDBITS) * sizeof (fd_mask);
 
384
#endif
298
385
        return RS_RET_OK;
299
386
}
300
387
 
307
394
BEGINAbstractObjClassInit(glbl, 1, OBJ_IS_CORE_MODULE) /* class, version */
308
395
        /* request objects we use */
309
396
        CHKiRet(objUse(prop, CORE_COMPONENT));
 
397
        CHKiRet(objUse(errmsg, CORE_COMPONENT));
310
398
 
311
399
        /* register config handlers (TODO: we need to implement a way to unregister them) */
312
 
        CHKiRet(regCfSysLineHdlr((uchar *)"workdirectory", 0, eCmdHdlrGetWord, NULL, &pszWorkDir, NULL));
 
400
        CHKiRet(regCfSysLineHdlr((uchar *)"workdirectory", 0, eCmdHdlrGetWord, setWorkDir, NULL, NULL));
313
401
        CHKiRet(regCfSysLineHdlr((uchar *)"dropmsgswithmaliciousdnsptrrecords", 0, eCmdHdlrBinary, NULL, &bDropMalPTRMsgs, NULL));
314
402
        CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdriver", 0, eCmdHdlrGetWord, NULL, &pszDfltNetstrmDrvr, NULL));
315
403
        CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdrivercafile", 0, eCmdHdlrGetWord, NULL, &pszDfltNetstrmDrvrCAF, NULL));
316
404
        CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdriverkeyfile", 0, eCmdHdlrGetWord, NULL, &pszDfltNetstrmDrvrKeyFile, NULL));
317
405
        CHKiRet(regCfSysLineHdlr((uchar *)"defaultnetstreamdrivercertfile", 0, eCmdHdlrGetWord, NULL, &pszDfltNetstrmDrvrCertFile, NULL));
 
406
        CHKiRet(regCfSysLineHdlr((uchar *)"localhostname", 0, eCmdHdlrGetWord, NULL, &LocalHostNameOverride, NULL));
318
407
        CHKiRet(regCfSysLineHdlr((uchar *)"optimizeforuniprocessor", 0, eCmdHdlrBinary, NULL, &bOptimizeUniProc, NULL));
319
 
        CHKiRet(regCfSysLineHdlr((uchar *)"hupisrestart", 0, eCmdHdlrBinary, NULL, &bHUPisRestart, NULL));
320
408
        CHKiRet(regCfSysLineHdlr((uchar *)"preservefqdn", 0, eCmdHdlrBinary, NULL, &bPreserveFQDN, NULL));
321
409
        CHKiRet(regCfSysLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, NULL));
 
410
 
 
411
        INIT_ATOMIC_HELPER_MUT(mutTerminateInputs);
322
412
ENDObjClassInit(glbl)
323
413
 
324
414
 
338
428
                free(pszWorkDir);
339
429
        if(LocalHostName != NULL)
340
430
                free(LocalHostName);
 
431
        free(LocalHostNameOverride);
341
432
        if(LocalFQDNName != NULL)
342
433
                free(LocalFQDNName);
343
434
        objRelease(prop, CORE_COMPONENT);
 
435
        DESTROY_ATOMIC_HELPER_MUT(mutTerminateInputs);
344
436
ENDObjClassExit(glbl)
345
437
 
346
438
/* vi:set ai: