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
384
398
GenerateLocalHostNameProperty(void)
389
if(propLocalHostName != NULL)
390
prop.Destruct(&propLocalHostName);
392
CHKiRet(prop.Construct(&propLocalHostName));
406
if(propLocalHostNameToDelete != NULL)
407
prop.Destruct(&propLocalHostNameToDelete);
393
409
if(LocalHostNameOverride == NULL) {
394
410
if(LocalHostName == NULL)
395
411
pszName = (uchar*) "[localhost]";
403
419
pszName = LocalHostNameOverride;
405
421
DBGPRINTF("GenerateLocalHostName uses '%s'\n", pszName);
406
CHKiRet(prop.SetString(propLocalHostName, pszName, ustrlen(pszName)));
407
CHKiRet(prop.ConstructFinalize(propLocalHostName));
423
if(propLocalHostName == NULL)
424
pszPrev = (uchar*)""; /* make sure strcmp() below does not match */
426
prop.GetString(propLocalHostName, &pszPrev, &lenPrev);
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;
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)