~ubuntu-branches/debian/sid/rsyslog/sid

« back to all changes in this revision

Viewing changes to runtime/glbl.c

  • Committer: Package Import Robot
  • Author(s): Michael Biebl, Michael Biebl, Daniel Pocock
  • Date: 2014-03-11 19:52:49 UTC
  • mfrom: (1.1.37)
  • Revision ID: package-import@ubuntu.com-20140311195249-phbsh9be8lebawti
Tags: 7.4.8-1
[ Michael Biebl ]
* New upstream release.
* Update Build-Depends:
  - Bump libestr-dev to (>= 0.1.9).
  - Tighten liblognorm-dev to (<< 1.0.0).
  - Replace libjson0-dev with libjson-c-dev, we no longer need the
    transitional package.
* Bump Standards-Version to 3.9.5. No further changes.

[ Daniel Pocock ]
* Make template parameter not mandatory in mongodb output plugin. Patch
  cherry-picked from upstream Git. (Closes: #740869, #721277)
* Ensure JSON templates are NUL terminated. Patch cherry-picked from
  upstream Git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
#include <sys/types.h>
33
33
#include <sys/stat.h>
34
34
#include <unistd.h>
 
35
#include <pthread.h>
35
36
#include <assert.h>
36
37
 
37
38
#include "rsyslog.h"
71
72
static int bDisableDNS = 0; /* don't look up IP addresses of remote messages */
72
73
static prop_t *propLocalIPIF = NULL;/* IP address to report for the local host (default is 127.0.0.1) */
73
74
static prop_t *propLocalHostName = NULL;/* our hostname as FQDN - read-only after startup */
 
75
static prop_t *propLocalHostNameToDelete = NULL;/* see GenerateLocalHostName function hdr comment! */
74
76
static uchar *LocalHostName = NULL;/* our hostname  - read-only after startup, except HUP */
75
77
static uchar *LocalHostNameOverride = NULL;/* user-overridden hostname - read-only after startup */
76
78
static uchar *LocalFQDNName = NULL;/* our hostname as FQDN - read-only after startup, except HUP */
379
381
/* generate the local hostname property. This must be done after the hostname info
380
382
 * has been set as well as PreserveFQDN.
381
383
 * rgerhards, 2009-06-30
 
384
 * NOTE: This function tries to avoid locking by not destructing the previous value
 
385
 * immediately. This is so that current readers can  continue to use the previous name.
 
386
 * Otherwise, we would need to use read/write locks to protect the update process.
 
387
 * In order to do so, we save the previous value and delete it when we are called again
 
388
 * the next time. Note that this in theory is racy and can lead to a double-free.
 
389
 * In practice, however, the window of exposure to trigger this is extremely short
 
390
 * and as this functions is very infrequently being called (on HUP), the trigger
 
391
 * condition for this bug is so highly unlikely that it never occurs in practice.
 
392
 * Probably if you HUP rsyslog every few milliseconds, but who does that...
 
393
 * To further reduce risk potential, we do only update the property when there
 
394
 * actually is a hostname change, which makes it even less likely.
 
395
 * rgerhards, 2013-10-28
382
396
 */
383
397
static rsRetVal
384
398
GenerateLocalHostNameProperty(void)
385
399
{
386
 
        DEFiRet;
 
400
        uchar *pszPrev;
 
401
        int lenPrev;
 
402
        prop_t *hostnameNew;
387
403
        uchar *pszName;
388
 
 
389
 
        if(propLocalHostName != NULL)
390
 
                prop.Destruct(&propLocalHostName);
391
 
 
392
 
        CHKiRet(prop.Construct(&propLocalHostName));
 
404
        DEFiRet;
 
405
 
 
406
        if(propLocalHostNameToDelete != NULL)
 
407
                prop.Destruct(&propLocalHostNameToDelete);
 
408
 
393
409
        if(LocalHostNameOverride == NULL) {
394
410
                if(LocalHostName == NULL)
395
411
                        pszName = (uchar*) "[localhost]";
403
419
                pszName = LocalHostNameOverride;
404
420
        }
405
421
        DBGPRINTF("GenerateLocalHostName uses '%s'\n", pszName);
406
 
        CHKiRet(prop.SetString(propLocalHostName, pszName, ustrlen(pszName)));
407
 
        CHKiRet(prop.ConstructFinalize(propLocalHostName));
 
422
 
 
423
        if(propLocalHostName == NULL)
 
424
                pszPrev = (uchar*)""; /* make sure strcmp() below does not match */
 
425
        else
 
426
                prop.GetString(propLocalHostName, &pszPrev, &lenPrev);
 
427
 
 
428
        if(ustrcmp(pszPrev, pszName)) {
 
429
                /* we need to update */
 
430
                CHKiRet(prop.Construct(&hostnameNew));
 
431
                CHKiRet(prop.SetString(hostnameNew, pszName, ustrlen(pszName)));
 
432
                CHKiRet(prop.ConstructFinalize(hostnameNew));
 
433
                propLocalHostNameToDelete = propLocalHostName;
 
434
                propLocalHostName = hostnameNew;
 
435
        }
408
436
 
409
437
finalize_it:
410
438
        RETiRet;
445
473
        return(pszWorkDir == NULL ? (uchar*) "" : pszWorkDir);
446
474
}
447
475
 
 
476
/* return the "raw" working directory, which means
 
477
 * NULL if unset.
 
478
 */
 
479
const uchar *
 
480
glblGetWorkDirRaw(void)
 
481
{
 
482
        return pszWorkDir;
 
483
}
448
484
 
449
485
/* return the current default netstream driver */
450
486
static uchar*
667
703
        free(LocalHostNameOverride);
668
704
        free(LocalFQDNName);
669
705
        objRelease(prop, CORE_COMPONENT);
 
706
        if(propLocalHostNameToDelete != NULL)
 
707
                prop.Destruct(&propLocalHostNameToDelete);
670
708
        DESTROY_ATOMIC_HELPER_MUT(mutTerminateInputs);
671
709
ENDObjClassExit(glbl)
672
710