summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2012-05-04 00:57:24 +0200
committerMichael Biebl <biebl@debian.org>2012-05-04 00:57:24 +0200
commite1ab13c77be9fbe3e2e5dfe3357fcd9f991b71b5 (patch)
treea7f3807198f5b1c7007bb754f3aabcd650eaa35a
parent09756e0e7c8b90e7f8621c37fe480c7683c8a8cb (diff)
downloadrsyslog-upstream/5.8.11.tar.gz
Imported Upstream version 5.8.11upstream/5.8.11
-rw-r--r--ChangeLog27
-rw-r--r--config.h.in3
-rwxr-xr-xconfigure52
-rw-r--r--configure.ac18
-rw-r--r--doc/manual.html2
-rw-r--r--doc/omudpspoof.html20
-rw-r--r--doc/rsyslog_conf_global.html9
-rw-r--r--doc/v5compatibility.html1
-rw-r--r--plugins/imptcp/imptcp.c4
-rw-r--r--plugins/imuxsock/imuxsock.c14
-rw-r--r--plugins/ommysql/ommysql.c20
-rw-r--r--runtime/glbl.c108
-rw-r--r--runtime/msg.c24
-rw-r--r--runtime/queue.c54
-rw-r--r--runtime/ruleset.c10
-rw-r--r--runtime/ruleset.h15
-rw-r--r--tools/syslogd.c171
17 files changed, 376 insertions, 176 deletions
diff --git a/ChangeLog b/ChangeLog
index de33a6c..7cfc3a0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,31 @@
---------------------------------------------------------------------------
+Version 5.8.11 [V5-stable] 2012-05-03
+- bugfix: ommysql did not properly init/exit the mysql runtime library
+ this could lead to segfaults. Triggering condition: multiple action
+ instances using ommysql. Thanks to Tomas Heinrich for reporting this
+ problem and providing an initial patch (which my solution is based on,
+ I need to add more code to clean the mess up).
+- bugfix: rsyslog did not terminate when delayable inputs were blocked
+ due to unvailable sources. Fixes:
+ http://bugzilla.adiscon.com/show_bug.cgi?id=299
+ Thanks to Marcin M for bringing up this problem and Andre Lorbach
+ for helping to reproduce and fix it.
+- bugfix: active input in "light delay state" could block rsyslog
+ termination, at least for prolonged period of time
+- bugfix: imptcp input name could not be set
+ config directive was accepted, but had no effect
+- bugfix: assigned ruleset was lost when using disk queues
+ This looked quite hard to diagnose for disk-assisted queues, as the
+ pure memory part worked well, but ruleset info was lost for messages
+ stored inside the disk queue.
+- bugfix: hostname was not requeried on HUP
+ Thanks to Per Jessen for reporting this bug and Marius Tomaschewski for
+ his help in testing the fix.
+- bugfix: inside queue.c, some thread cancel states were not correctly
+ reset. While this is a bug, we assume it did have no practical effect
+ because the reset as it was done was set to the state the code actually
+ had at this point. But better fix this...
+---------------------------------------------------------------------------
Version 5.8.10 [V5-stable] 2012-04-05
- bugfix: segfault on startup if $actionqueuefilename was missing for disk
queue config
diff --git a/config.h.in b/config.h.in
index f4ce4a7..c0ae0f7 100644
--- a/config.h.in
+++ b/config.h.in
@@ -116,6 +116,9 @@
/* Define to 1 if you have the `mkdir' function. */
#undef HAVE_MKDIR
+/* mysql_library_init available */
+#undef HAVE_MYSQL_LIBRARY_INIT
+
/* Define to 1 if you have the <netdb.h> header file. */
#undef HAVE_NETDB_H
diff --git a/configure b/configure
index f539f1c..8112d39 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.66 for rsyslog 5.8.10.
+# Generated by GNU Autoconf 2.66 for rsyslog 5.8.11.
#
# Report bugs to <rsyslog@lists.adiscon.com>.
#
@@ -562,8 +562,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='rsyslog'
PACKAGE_TARNAME='rsyslog'
-PACKAGE_VERSION='5.8.10'
-PACKAGE_STRING='rsyslog 5.8.10'
+PACKAGE_VERSION='5.8.11'
+PACKAGE_STRING='rsyslog 5.8.11'
PACKAGE_BUGREPORT='rsyslog@lists.adiscon.com'
PACKAGE_URL=''
@@ -1475,7 +1475,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
-\`configure' configures rsyslog 5.8.10 to adapt to many kinds of systems.
+\`configure' configures rsyslog 5.8.11 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
@@ -1545,7 +1545,7 @@ fi
if test -n "$ac_init_help"; then
case $ac_init_help in
- short | recursive ) echo "Configuration of rsyslog 5.8.10:";;
+ short | recursive ) echo "Configuration of rsyslog 5.8.11:";;
esac
cat <<\_ACEOF
@@ -1720,7 +1720,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
-rsyslog configure 5.8.10
+rsyslog configure 5.8.11
generated by GNU Autoconf 2.66
Copyright (C) 2010 Free Software Foundation, Inc.
@@ -2299,7 +2299,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
-It was created by rsyslog $as_me 5.8.10, which was
+It was created by rsyslog $as_me 5.8.11, which was
generated by GNU Autoconf 2.66. Invocation command line was
$ $0 $@
@@ -3114,7 +3114,7 @@ fi
# Define the identity of the package.
PACKAGE='rsyslog'
- VERSION='5.8.10'
+ VERSION='5.8.11'
cat >>confdefs.h <<_ACEOF
@@ -14894,6 +14894,33 @@ as_fn_error $? "MySQL library is missing
See \`config.log' for more details" "$LINENO" 5; }
fi
+ { $as_echo "$as_me:${as_lineno-$LINENO}: checking if we have mysql_library_init" >&5
+$as_echo_n "checking if we have mysql_library_init... " >&6; }
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $MYSQL_CFLAGS"
+ save_LIBS="$LIBS"
+ LIBS="$LIBS $MYSQL_LIBS"
+ cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h. */
+#include <mysql.h>
+ #include <stdio.h>
+int
+main ()
+{
+mysql_library_init(0, NULL, NULL)
+ ;
+ return 0;
+}
+_ACEOF
+if ac_fn_c_try_link "$LINENO"; then :
+ have_mysql_library_init=yes
+else
+ have_mysql_library_init=no
+fi
+rm -f core conftest.err conftest.$ac_objext \
+ conftest$ac_exeext conftest.$ac_ext
+ CFLAGS="$save_CFLAGS"
+ LIBS="$save_LIBS"
fi
if test x$enable_mysql = xyes; then
ENABLE_MYSQL_TRUE=
@@ -14903,6 +14930,11 @@ else
ENABLE_MYSQL_FALSE=
fi
+if test "$have_mysql_library_init" = "yes"; then
+
+$as_echo "#define HAVE_MYSQL_LIBRARY_INIT 1" >>confdefs.h
+
+fi
@@ -17336,7 +17368,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
-This file was extended by rsyslog $as_me 5.8.10, which was
+This file was extended by rsyslog $as_me 5.8.11, which was
generated by GNU Autoconf 2.66. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
@@ -17402,7 +17434,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
-rsyslog config.status 5.8.10
+rsyslog config.status 5.8.11
configured by $0, generated by GNU Autoconf 2.66,
with options \\"\$ac_cs_config\\"
diff --git a/configure.ac b/configure.ac
index e7a2619..ff50984 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2,7 +2,7 @@
# Process this file with autoconf to produce a configure script.
AC_PREREQ(2.61)
-AC_INIT([rsyslog],[5.8.10],[rsyslog@lists.adiscon.com])
+AC_INIT([rsyslog],[5.8.11],[rsyslog@lists.adiscon.com])
AM_INIT_AUTOMAKE
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -514,8 +514,24 @@ if test "x$enable_mysql" = "xyes"; then
[AC_MSG_FAILURE([MySQL library is missing])],
[`mysql_config --libs`]
)
+ AC_MSG_CHECKING(if we have mysql_library_init)
+ save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $MYSQL_CFLAGS"
+ save_LIBS="$LIBS"
+ LIBS="$LIBS $MYSQL_LIBS"
+ AC_TRY_LINK(
+ [#include <mysql.h>
+ #include <stdio.h>],
+ [mysql_library_init(0, NULL, NULL)],
+ [have_mysql_library_init=yes],
+ [have_mysql_library_init=no])
+ CFLAGS="$save_CFLAGS"
+ LIBS="$save_LIBS"
fi
AM_CONDITIONAL(ENABLE_MYSQL, test x$enable_mysql = xyes)
+if test "$have_mysql_library_init" = "yes"; then
+ AC_DEFINE([HAVE_MYSQL_LIBRARY_INIT], [1], [mysql_library_init available])
+fi
AC_SUBST(MYSQL_CFLAGS)
AC_SUBST(MYSQL_LIBS)
diff --git a/doc/manual.html b/doc/manual.html
index 29ac1ad..2ee8557 100644
--- a/doc/manual.html
+++ b/doc/manual.html
@@ -19,7 +19,7 @@ rsyslog support</a> available directly from the source!</p>
<p><b>Please visit the <a href="http://www.rsyslog.com/sponsors">rsyslog sponsor's page</a>
to honor the project sponsors or become one yourself!</b> We are very grateful for any help towards the
project goals.</p>
-<p><b>This documentation is for version 5.8.10 (v5-stable branch) of rsyslog.</b>
+<p><b>This documentation is for version 5.8.11 (v5-stable branch) of rsyslog.</b>
Visit the <i><a href="http://www.rsyslog.com/status">rsyslog status page</a></i></b>
to obtain current version information and project status.
</p><p><b>If you like rsyslog, you might
diff --git a/doc/omudpspoof.html b/doc/omudpspoof.html
index 16cb9b1..df14bbe 100644
--- a/doc/omudpspoof.html
+++ b/doc/omudpspoof.html
@@ -16,7 +16,7 @@ spoof the sender address. Also, it enables to circle through a number of
source ports.
<p><b>Configuration Directives</b>:</p>
<ul>
-<li><b>$ActionOMUDPSpoofSourceNameTemplate</b> &lt;templatename&gt;<br>
+<li><b>$ActionOMOMUDPSpoofSourceNameTemplate</b> &lt;templatename&gt;<br>
This is the name of the template that contains a
numerical IP address that is to be used as the source system IP address.
While it may often be a constant value, it can be generated as usual via the
@@ -28,7 +28,7 @@ So in essence, the default template spoofs the address of the system the message
was received from. This is considered the most important use case.
<li><b>$ActionOMUDPSpoofTargetHost</b> &lt;hostname&gt;<br>
Host that the messages shall be sent to.
-<li><b>$ActionUDPSpoofTargetPort</b> &lt;port&gt;<br>
+<li><b>$ActionOMUDPSpoofTargetPort</b> &lt;port&gt;<br>
Remote port that the messages shall be sent to.
<li><b>$ActionOMUDPSpoofDefaultTemplate</b> &lt;templatename&gt;<br>
This setting instructs omudpspoof to use a template different from the
@@ -53,7 +53,7 @@ care about the source port. This example is considered the typical use case for
omudpspoof.
</p>
<textarea rows="5" cols="80">$ModLoad omudpspoof
-$ActionUDPSpoofTargetHost server.example.com
+$ActionOMUDPSpoofTargetHost server.example.com
*.*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :omudpspoof:
</textarea>
@@ -64,10 +64,10 @@ source port 514 is used.
<textarea rows="8" cols="80">$ModLoad omudpspoof
$template spoofaddr,"192.0.2.1"
$template spooftemplate,"%rawmsg%"
-$ActionUDPSpoofSourceNameTemplate spoofaddr
-$ActionUDPSpoofTargetHost server.example.com
-$ActionUDPSpoofSourcePortStart 514
-$ActionUDPSpoofSourcePortEnd 514
+$ActionOMUDPSpoofSourceNameTemplate spoofaddr
+$ActionOMUDPSpoofTargetHost server.example.com
+$ActionOMUDPSpoofSourcePortStart 514
+$ActionOMUDPSpoofSourcePortEnd 514
*.*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :omudpspoof:;spooftemplate
</textarea>
<p>The following sample is similar to the previous, but uses as many defaults as possible.
@@ -77,8 +77,8 @@ have been changed, the previously set defaults will be used!
</p>
<textarea rows="5" cols="80">$ModLoad omudpspoof
$template spoofaddr,"192.0.2.1"
-$ActionUDPSpoofSourceNameTemplate spoofaddr
-$ActionUDPSpoofTargetHost server.example.com
+$ActionOMUDPSpoofSourceNameTemplate spoofaddr
+$ActionOMUDPSpoofTargetHost server.example.com
*.*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; :omudpspoof:
</textarea>
<p>[<a href="rsyslog_conf.html">rsyslog.conf overview</a>]
@@ -86,7 +86,7 @@ $ActionUDPSpoofTargetHost server.example.com
<p><font size="2">This documentation is part of the
<a href="http://www.rsyslog.com/">rsyslog</a>
project.<br>
-Copyright &copy; 2009 by <a href="http://www.gerhards.net/rainer">Rainer Gerhards</a> and
+Copyright &copy; 2009-2012 by <a href="http://www.gerhards.net/rainer">Rainer Gerhards</a> and
<a href="http://www.adiscon.com/">Adiscon</a>.
Released under the GNU GPL version 3 or higher.</font></p>
</body></html>
diff --git a/doc/rsyslog_conf_global.html b/doc/rsyslog_conf_global.html
index 21786a7..83eb876 100644
--- a/doc/rsyslog_conf_global.html
+++ b/doc/rsyslog_conf_global.html
@@ -152,15 +152,6 @@ our paper on <a href="multi_ruleset.html">using multiple rule sets in rsyslog</a
<li><a href="rsconf1_gssforwardservicename.html">$GssForwardServiceName</a></li>
<li><a href="rsconf1_gsslistenservicename.html">$GssListenServiceName</a></li>
<li><a href="rsconf1_gssmode.html">$GssMode</a></li>
-<li>$HUPisRestart [on/<b>off</b>] - if set to on, a HUP is a full daemon restart. This means any queued messages are discarded (depending
-on queue configuration, of course) all modules are unloaded and reloaded. This mode keeps compatible with sysklogd, but is
-not recommended for use with rsyslog. To do a full restart, simply stop and start the daemon. The default (since 4.5.1) is "off".
-If it is set to "off", a HUP will only close open files. This is a much quicker action and usually
-the only one that is needed e.g. for log rotation. <b>Restart-type HUPs (value "on") are depricated</b>
-and will go away in rsyslog v5. So it is a good idea to change anything that needs it, now.
-Usually that should not be a big issue, as the restart-type HUP can easily be replaced by
-something along the lines of &quot;/etc/init.d/rsyslog restart&quot;.
-</li>
<li><a href="rsconf1_includeconfig.html">$IncludeConfig</a></li><li>MainMsgQueueCheckpointInterval &lt;number&gt;</li>
<li><b>$LocalHostName</b> [name] - this directive permits to overwrite the system
hostname with the one specified in the directive. If the directive is given
diff --git a/doc/v5compatibility.html b/doc/v5compatibility.html
index cc875b7..fc4289c 100644
--- a/doc/v5compatibility.html
+++ b/doc/v5compatibility.html
@@ -16,6 +16,7 @@ available. This processing was redundant and had a lot a drawbacks.
For details, please see the
<a href="v4compatibility.html">rsyslog v4 compatibility notes</a> which elaborate
on the reasons and the (few) things you may need to change.
+<p>Please note that starting with 5.8.11 HUP will also requery the local hostname.
<h2>Queue on-disk format</h2>
<p>The queue information file format has been changed. When upgrading from v4 to
v5, make sure that the queue is emptied and no on-disk structure present. We did
diff --git a/plugins/imptcp/imptcp.c b/plugins/imptcp/imptcp.c
index 65fe703..91bdf8b 100644
--- a/plugins/imptcp/imptcp.c
+++ b/plugins/imptcp/imptcp.c
@@ -885,14 +885,14 @@ static rsRetVal addTCPListener(void __attribute__((unused)) *pVal, uchar *pNewVa
pSrv->bEmitMsgOnClose = cs.bEmitMsgOnClose;
pSrv->port = pNewVal;
pSrv->iAddtlFrameDelim = cs.iAddtlFrameDelim;
- cs.pszInputName = NULL; /* moved over to pSrv, we do not own */
pSrv->lstnIP = cs.lstnIP;
- cs.lstnIP = NULL; /* moved over to pSrv, we do not own */
pSrv->pRuleset = cs.pRuleset;
pSrv->pszInputName = (cs.pszInputName == NULL) ? UCHAR_CONSTANT("imptcp") : cs.pszInputName;
CHKiRet(prop.Construct(&pSrv->pInputName));
CHKiRet(prop.SetString(pSrv->pInputName, pSrv->pszInputName, ustrlen(pSrv->pszInputName)));
CHKiRet(prop.ConstructFinalize(pSrv->pInputName));
+ cs.pszInputName = NULL; /* moved over to pSrv, we do not own */
+ cs.lstnIP = NULL; /* moved over to pSrv, we do not own */
/* add to linked list */
pSrv->pNext = pSrvRoot;
diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c
index 5867f1c..9ad2421 100644
--- a/plugins/imuxsock/imuxsock.c
+++ b/plugins/imuxsock/imuxsock.c
@@ -281,16 +281,16 @@ addLstnSocketName(void __attribute__((unused)) *pVal, uchar *pNewVal)
} else {
listeners[nfd].bParseHost = 0;
}
- CHKiRet(prop.Construct(&(listeners[nfd].hostName)));
if(pLogHostName == NULL) {
- CHKiRet(prop.SetString(listeners[nfd].hostName, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName())));
+ listeners[nfd].hostName = NULL;
} else {
+ CHKiRet(prop.Construct(&(listeners[nfd].hostName)));
CHKiRet(prop.SetString(listeners[nfd].hostName, pLogHostName, ustrlen(pLogHostName)));
+ CHKiRet(prop.ConstructFinalize(listeners[nfd].hostName));
/* reset hostname for next socket */
free(pLogHostName);
pLogHostName = NULL;
}
- CHKiRet(prop.ConstructFinalize(listeners[nfd].hostName));
if(ratelimitInterval > 0) {
if((listeners[nfd].ht = create_hashtable(100, hash_from_key_fn, key_equals_fn, NULL)) == NULL) {
/* in this case, we simply turn of rate-limiting */
@@ -602,7 +602,7 @@ SubmitMsg(uchar *pRcv, int lenRcv, lstn_t *pLstn, struct ucred *cred)
pMsg->msgFlags = pLstn->flags;
}
- MsgSetRcvFrom(pMsg, pLstn->hostName);
+ MsgSetRcvFrom(pMsg, pLstn->hostName == NULL ? glbl.GetLocalHostNameProp() : pLstn->hostName);
CHKiRet(MsgSetRcvFromIP(pMsg, pLocalHostIP));
CHKiRet(submitMsg(pMsg));
@@ -864,7 +864,6 @@ CODESTARTafterRun
if(pInputName != NULL)
prop.Destruct(&pInputName);
-
ENDafterRun
@@ -958,11 +957,6 @@ CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(prop.SetString(pLocalHostIP, UCHAR_CONSTANT("127.0.0.1"), sizeof("127.0.0.1") - 1));
CHKiRet(prop.ConstructFinalize(pLocalHostIP));
- /* now init listen socket zero, the local log socket */
- CHKiRet(prop.Construct(&(listeners[0].hostName)));
- CHKiRet(prop.SetString(listeners[0].hostName, glbl.GetLocalHostName(), ustrlen(glbl.GetLocalHostName())));
- CHKiRet(prop.ConstructFinalize(listeners[0].hostName));
-
/* register config file handlers */
CHKiRet(omsdRegCFSLineHdlr((uchar *)"omitlocallogging", 0, eCmdHdlrBinary,
NULL, &bOmitLocalLogging, STD_LOADABLE_MODULE_ID));
diff --git a/plugins/ommysql/ommysql.c b/plugins/ommysql/ommysql.c
index 58e347b..7ff89f5 100644
--- a/plugins/ommysql/ommysql.c
+++ b/plugins/ommysql/ommysql.c
@@ -90,7 +90,6 @@ static void closeMySQL(instanceData *pData)
ASSERT(pData != NULL);
if(pData->f_hmysql != NULL) { /* just to be on the safe side... */
- mysql_server_end();
mysql_close(pData->f_hmysql);
pData->f_hmysql = NULL;
}
@@ -319,6 +318,11 @@ ENDparseSelectorAct
BEGINmodExit
CODESTARTmodExit
+# ifdef HAVE_MYSQL_LIBRARY_INIT
+ mysql_library_end();
+# else
+ mysql_server_end();
+# endif
ENDmodExit
@@ -346,6 +350,20 @@ CODESTARTmodInit
*ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */
CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(errmsg, CORE_COMPONENT));
+
+ /* we need to init the MySQL library. If that fails, we cannot run */
+ if(
+# ifdef HAVE_MYSQL_LIBRARY_INIT
+ mysql_library_init(0, NULL, NULL)
+# else
+ mysql_server_init(0, NULL, NULL)
+# endif
+ ) {
+ errmsg.LogError(0, NO_ERRCODE, "ommysql: mysql_server_init() failed, plugin "
+ "can not run");
+ ABORT_FINALIZE(RS_RET_ERR);
+ }
+
/* register our config handlers */
CHKiRet(omsdRegCFSLineHdlr((uchar *)"actionommysqlserverport", 0, eCmdHdlrInt, NULL, &iSrvPort, STD_LOADABLE_MODULE_ID));
CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, resetConfigVariables, NULL, STD_LOADABLE_MODULE_ID));
diff --git a/runtime/glbl.c b/runtime/glbl.c
index dea5a17..38e1f95 100644
--- a/runtime/glbl.c
+++ b/runtime/glbl.c
@@ -69,10 +69,10 @@ static int bDropMalPTRMsgs = 0;/* Drop messages which have malicious PTR records
static int option_DisallowWarning = 1; /* complain if message from disallowed sender is received */
static int bDisableDNS = 0; /* don't look up IP addresses of remote messages */
static prop_t *propLocalHostName = NULL;/* our hostname as FQDN - read-only after startup */
-static uchar *LocalHostName = NULL;/* our hostname - read-only after startup */
+static uchar *LocalHostName = NULL;/* our hostname - read-only after startup, except HUP */
static uchar *LocalHostNameOverride = NULL;/* user-overridden hostname - read-only after startup */
-static uchar *LocalFQDNName = NULL;/* our hostname as FQDN - read-only after startup */
-static uchar *LocalDomain; /* our local domain name - read-only after startup */
+static uchar *LocalFQDNName = NULL;/* our hostname as FQDN - read-only after startup, except HUP */
+static uchar *LocalDomain = NULL;/* our local domain name - read-only after startup, except HUP */
static char **StripDomains = NULL;/* these domains may be stripped before writing logs - r/o after s.u., never touched by init */
static char **LocalHosts = NULL;/* these hosts are logged with their hostname - read-only after startup, never touched by init */
static uchar *pszDfltNetstrmDrvr = NULL; /* module name of default netstream driver */
@@ -115,15 +115,12 @@ SIMP_PROP(DefPFFamily, iDefPFFamily, int) /* note that in the future we may chec
SIMP_PROP(DropMalPTRMsgs, bDropMalPTRMsgs, int)
SIMP_PROP(Option_DisallowWarning, option_DisallowWarning, int)
SIMP_PROP(DisableDNS, bDisableDNS, int)
-SIMP_PROP(LocalDomain, LocalDomain, uchar*)
SIMP_PROP(StripDomains, StripDomains, char**)
SIMP_PROP(LocalHosts, LocalHosts, char**)
#ifdef USE_UNLIMITED_SELECT
SIMP_PROP(FdSetSize, iFdSetSize, int)
#endif
-SIMP_PROP_SET(LocalFQDNName, LocalFQDNName, uchar*)
-SIMP_PROP_SET(LocalHostName, LocalHostName, uchar*)
SIMP_PROP_SET(DfltNetstrmDrvr, pszDfltNetstrmDrvr, uchar*) /* TODO: use custom function which frees existing value */
SIMP_PROP_SET(DfltNetstrmDrvrCAF, pszDfltNetstrmDrvrCAF, uchar*) /* TODO: use custom function which frees existing value */
SIMP_PROP_SET(DfltNetstrmDrvrKeyFile, pszDfltNetstrmDrvrKeyFile, uchar*) /* TODO: use custom function which frees existing value */
@@ -202,6 +199,19 @@ finalize_it:
RETiRet;
}
+/* set our local hostname. Free previous hostname, if it was already set.
+ * Note that we do now do this in a thread
+ * "once in a lifetime" action which can not be undone. -- gerhards, 2009-07-20
+ */
+static rsRetVal
+SetLocalHostName(uchar *newname)
+{
+ free(LocalHostName);
+ LocalHostName = newname;
+ return RS_RET_OK;
+}
+
+
/* return our local hostname. if it is not set, "[localhost]" is returned
*/
static uchar*
@@ -227,6 +237,26 @@ done:
}
+/* set our local domain name. Free previous domain, if it was already set.
+ */
+static rsRetVal
+SetLocalDomain(uchar *newname)
+{
+ free(LocalDomain);
+ LocalDomain = newname;
+ return RS_RET_OK;
+}
+
+
+/* return our local hostname. if it is not set, "[localhost]" is returned
+ */
+static uchar*
+GetLocalDomain(void)
+{
+ return LocalDomain;
+}
+
+
/* generate the local hostname property. This must be done after the hostname info
* has been set as well as PreserveFQDN.
* rgerhards, 2009-06-30
@@ -271,6 +301,14 @@ GetLocalHostNameProp(void)
}
+static rsRetVal
+SetLocalFQDNName(uchar *newname)
+{
+ free(LocalFQDNName);
+ LocalFQDNName = newname;
+ return RS_RET_OK;
+}
+
/* return the current localhost name as FQDN (requires FQDN to be set)
* TODO: we should set the FQDN ourselfs in here!
*/
@@ -373,30 +411,18 @@ ENDobjQueryInterface(glbl)
*/
static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __attribute__((unused)) *pVal)
{
- if(pszDfltNetstrmDrvr != NULL) {
- free(pszDfltNetstrmDrvr);
- pszDfltNetstrmDrvr = NULL;
- }
- if(pszDfltNetstrmDrvrCAF != NULL) {
- free(pszDfltNetstrmDrvrCAF);
- pszDfltNetstrmDrvrCAF = NULL;
- }
- if(pszDfltNetstrmDrvrKeyFile != NULL) {
- free(pszDfltNetstrmDrvrKeyFile);
- pszDfltNetstrmDrvrKeyFile = NULL;
- }
- if(pszDfltNetstrmDrvrCertFile != NULL) {
- free(pszDfltNetstrmDrvrCertFile);
- pszDfltNetstrmDrvrCertFile = NULL;
- }
- if(LocalHostNameOverride != NULL) {
- free(LocalHostNameOverride);
- LocalHostNameOverride = NULL;
- }
- if(pszWorkDir != NULL) {
- free(pszWorkDir);
- pszWorkDir = NULL;
- }
+ free(pszDfltNetstrmDrvr);
+ pszDfltNetstrmDrvr = NULL;
+ free(pszDfltNetstrmDrvrCAF);
+ pszDfltNetstrmDrvrCAF = NULL;
+ free(pszDfltNetstrmDrvrKeyFile);
+ pszDfltNetstrmDrvrKeyFile = NULL;
+ free(pszDfltNetstrmDrvrCertFile);
+ pszDfltNetstrmDrvrCertFile = NULL;
+ free(LocalHostNameOverride);
+ LocalHostNameOverride = NULL;
+ free(pszWorkDir);
+ pszWorkDir = NULL;
bDropMalPTRMsgs = 0;
bOptimizeUniProc = 1;
bPreserveFQDN = 0;
@@ -437,21 +463,15 @@ ENDObjClassInit(glbl)
* rgerhards, 2008-04-17
*/
BEGINObjClassExit(glbl, OBJ_IS_CORE_MODULE) /* class, version */
- if(pszDfltNetstrmDrvr != NULL)
- free(pszDfltNetstrmDrvr);
- if(pszDfltNetstrmDrvrCAF != NULL)
- free(pszDfltNetstrmDrvrCAF);
- if(pszDfltNetstrmDrvrKeyFile != NULL)
- free(pszDfltNetstrmDrvrKeyFile);
- if(pszDfltNetstrmDrvrCertFile != NULL)
- free(pszDfltNetstrmDrvrCertFile);
- if(pszWorkDir != NULL)
- free(pszWorkDir);
- if(LocalHostName != NULL)
- free(LocalHostName);
+ free(pszDfltNetstrmDrvr);
+ free(pszDfltNetstrmDrvrCAF);
+ free(pszDfltNetstrmDrvrKeyFile);
+ free(pszDfltNetstrmDrvrCertFile);
+ free(pszWorkDir);
+ free(LocalDomain);
+ free(LocalHostName);
free(LocalHostNameOverride);
- if(LocalFQDNName != NULL)
- free(LocalFQDNName);
+ free(LocalFQDNName);
objRelease(prop, CORE_COMPONENT);
DESTROY_ATOMIC_HELPER_MUT(mutTerminateInputs);
ENDObjClassExit(glbl)
diff --git a/runtime/msg.c b/runtime/msg.c
index 31863b2..7b94228 100644
--- a/runtime/msg.c
+++ b/runtime/msg.c
@@ -1057,6 +1057,12 @@ static rsRetVal MsgSerialize(msg_t *pThis, strm_t *pStrm)
objSerializePTR(pStrm, pCSAPPNAME, CSTR);
objSerializePTR(pStrm, pCSPROCID, CSTR);
objSerializePTR(pStrm, pCSMSGID, CSTR);
+
+ if(pThis->pRuleset != NULL) {
+ rulesetGetName(pThis->pRuleset);
+ CHKiRet(obj.SerializeProp(pStrm, UCHAR_CONSTANT("pszRuleset"), PROPTYPE_PSZ,
+ rulesetGetName(pThis->pRuleset)));
+ }
/* offset must be serialized after pszRawMsg, because we need that to obtain the correct
* MSG size.
@@ -1663,6 +1669,16 @@ void MsgSetRuleset(msg_t *pMsg, ruleset_t *pRuleset)
}
+/* rgerhards 2012-04-18: set associated ruleset (by ruleset name)
+ * If ruleset cannot be found, no update is done.
+ */
+static void
+MsgSetRulesetByName(msg_t *pMsg, cstr_t *rulesetName)
+{
+ rulesetGetRuleset(&(pMsg->pRuleset), rsCStrGetSzStrNoNULL(rulesetName));
+}
+
+
/* set TAG in msg object
* (rewritten 2009-06-18 rgerhards)
*/
@@ -1671,8 +1687,6 @@ void MsgSetTAG(msg_t *pMsg, uchar* pszBuf, size_t lenBuf)
uchar *pBuf;
assert(pMsg != NULL);
-dbgprintf("MsgSetTAG in: len %d, pszBuf: %s\n", lenBuf, pszBuf);
-
freeTAG(pMsg);
pMsg->iLenTAG = lenBuf;
@@ -1692,7 +1706,6 @@ dbgprintf("MsgSetTAG in: len %d, pszBuf: %s\n", lenBuf, pszBuf);
memcpy(pBuf, pszBuf, pMsg->iLenTAG);
pBuf[pMsg->iLenTAG] = '\0'; /* this also works with truncation! */
-dbgprintf("MsgSetTAG exit: pMsg->iLenTAG %d, pMsg->TAG.szBuf: %s\n", pMsg->iLenTAG, pMsg->TAG.szBuf);
}
@@ -3200,8 +3213,13 @@ rsRetVal MsgSetProperty(msg_t *pThis, var_t *pProp)
memcpy(&pThis->tRcvdAt, &pProp->val.vSyslogTime, sizeof(struct syslogTime));
} else if(isProp("tTIMESTAMP")) {
memcpy(&pThis->tTIMESTAMP, &pProp->val.vSyslogTime, sizeof(struct syslogTime));
+ } else if(isProp("pszRuleset")) {
+ MsgSetRulesetByName(pThis, pProp->val.pStr);
} else if(isProp("pszMSG")) {
dbgprintf("no longer supported property pszMSG silently ignored\n");
+ } else {
+ dbgprintf("unknown supported property '%s' silently ignored\n",
+ rsCStrGetSzStrNoNULL(pProp->pcsName));
}
finalize_it:
diff --git a/runtime/queue.c b/runtime/queue.c
index 9f31852..e968806 100644
--- a/runtime/queue.c
+++ b/runtime/queue.c
@@ -1715,7 +1715,7 @@ ConsumerReg(qqueue_t *pThis, wti_t *pWti)
}
/* but now cancellation is no longer permitted */
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &iCancelStateSave);
+ pthread_setcancelstate(iCancelStateSave, NULL);
finalize_it:
DBGPRINTF("regular consumer finished, iret=%d, szlog %d sz phys %d\n", iRet,
@@ -1768,7 +1768,7 @@ ConsumerDA(qqueue_t *pThis, wti_t *pWti)
}
/* but now cancellation is no longer permitted */
- pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &iCancelStateSave);
+ pthread_setcancelstate(iCancelStateSave, NULL);
/* now we are done, but need to re-aquire the mutex */
d_pthread_mutex_lock(pThis->mut);
@@ -1847,7 +1847,6 @@ qqueueStart(qqueue_t *pThis) /* this is the ConstructionFinalizer */
int wrk;
uchar *qName;
size_t lenBuf;
- int iQueueSizeSave;
ASSERT(pThis != NULL);
@@ -2245,8 +2244,13 @@ static inline rsRetVal
doEnqSingleObj(qqueue_t *pThis, flowControl_t flowCtlType, void *pUsr)
{
DEFiRet;
+ int err;
struct timespec t;
+ if(glbl.GetGlobalInputTermState()) {
+ ABORT_FINALIZE(RS_RET_FORCE_TERM);
+ }
+
STATSCOUNTER_INC(pThis->ctrEnqueued, pThis->mutCtrEnqueued);
/* first check if we need to discard this message (which will cause CHKiRet() to exit)
*/
@@ -2273,15 +2277,48 @@ doEnqSingleObj(qqueue_t *pThis, flowControl_t flowCtlType, void *pUsr)
* It's a side effect, but a good one ;) -- rgerhards, 2008-03-14
*/
if(flowCtlType == eFLOWCTL_FULL_DELAY) {
+ DBGOPRINT((obj_t*) pThis, "enqueueMsg: FullDelay mark reached for full delayable message "
+ "- blocking.\n");
while(pThis->iQueueSize >= pThis->iFullDlyMrk) {
- DBGOPRINT((obj_t*) pThis, "enqueueMsg: FullDelay mark reached for full delayable message - blocking.\n");
- pthread_cond_wait(&pThis->belowFullDlyWtrMrk, pThis->mut); /* TODO error check? But what do then? */
+ /* We have a problem during shutdown if we block eternally. In that
+ * case, the the input thread cannot be terminated. So we wake up
+ * from time to time to check for termination.
+ * TODO/v6(at earliest): check if we could signal the condition during
+ * shutdown. However, this requires new queue registries and thus is
+ * far to much change for a stable version (and I am still not sure it
+ * is worth the effort, given how seldom this situation occurs and how
+ * few resources the wakeups need). -- rgerhards, 2012-05-03
+ * In any case, this was the old code (if we do the TODO):
+ * pthread_cond_wait(&pThis->belowFullDlyWtrMrk, pThis->mut);
+ */
+ timeoutComp(&t, 1000);
+ err = pthread_cond_timedwait(&pThis->belowLightDlyWtrMrk, pThis->mut, &t);
+ if(err != 0 && err != ETIMEDOUT) {
+ /* Something is really wrong now. Report to debug log and abort the
+ * wait. That keeps us running, even though we may lose messages.
+ */
+ DBGOPRINT((obj_t*) pThis, "potential program bug: pthread_cond_timedwait()"
+ "/fulldelay returned %d\n", err);
+ break;
+
+ }
+ DBGPRINTF("wti worker in full delay timed out, checking termination...\n");
+ if(glbl.GetGlobalInputTermState()) {
+ ABORT_FINALIZE(RS_RET_FORCE_TERM);
+ }
}
} else if(flowCtlType == eFLOWCTL_LIGHT_DELAY) {
if(pThis->iQueueSize >= pThis->iLightDlyMrk) {
- DBGOPRINT((obj_t*) pThis, "enqueueMsg: LightDelay mark reached for light delayable message - blocking a bit.\n");
+ DBGOPRINT((obj_t*) pThis, "enqueueMsg: LightDelay mark reached for light "
+ "delayable message - blocking a bit.\n");
timeoutComp(&t, 1000); /* 1000 millisconds = 1 second TODO: make configurable */
- pthread_cond_timedwait(&pThis->belowLightDlyWtrMrk, pThis->mut, &t); /* TODO error check? But what do then? */
+ err = pthread_cond_timedwait(&pThis->belowLightDlyWtrMrk, pThis->mut, &t);
+ if(err != 0 && err != ETIMEDOUT) {
+ /* Something is really wrong now. Report to debug log */
+ DBGOPRINT((obj_t*) pThis, "potential program bug: pthread_cond_timedwait()"
+ "/lightdelay returned %d\n", err);
+
+ }
}
}
@@ -2294,6 +2331,9 @@ doEnqSingleObj(qqueue_t *pThis, flowControl_t flowCtlType, void *pUsr)
|| (pThis->qType == QUEUETYPE_DISK && pThis->sizeOnDiskMax != 0
&& pThis->tVars.disk.sizeOnDisk > pThis->sizeOnDiskMax)) {
DBGOPRINT((obj_t*) pThis, "enqueueMsg: queue FULL - waiting to drain.\n");
+ if(glbl.GetGlobalInputTermState()) {
+ ABORT_FINALIZE(RS_RET_FORCE_TERM);
+ }
timeoutComp(&t, pThis->toEnq);
STATSCOUNTER_INC(pThis->ctrFull, pThis->mutCtrFull);
// TODO : handle enqOnly => discard!
diff --git a/runtime/ruleset.c b/runtime/ruleset.c
index 5ee2a55..8e241c8 100644
--- a/runtime/ruleset.c
+++ b/runtime/ruleset.c
@@ -315,8 +315,8 @@ GetRulesetQueue(ruleset_t *pThis)
/* Find the ruleset with the given name and return a pointer to its object.
*/
-static rsRetVal
-GetRuleset(ruleset_t **ppRuleset, uchar *pszName)
+rsRetVal
+rulesetGetRuleset(ruleset_t **ppRuleset, uchar *pszName)
{
DEFiRet;
assert(ppRuleset != NULL);
@@ -338,7 +338,7 @@ SetDefaultRuleset(uchar *pszName)
DEFiRet;
assert(pszName != NULL);
- CHKiRet(GetRuleset(&pRuleset, pszName));
+ CHKiRet(rulesetGetRuleset(&pRuleset, pszName));
pDfltRuleset = pRuleset;
dbgprintf("default rule set changed to %p: '%s'\n", pRuleset, pszName);
@@ -356,7 +356,7 @@ SetCurrRuleset(uchar *pszName)
DEFiRet;
assert(pszName != NULL);
- CHKiRet(GetRuleset(&pRuleset, pszName));
+ CHKiRet(rulesetGetRuleset(&pRuleset, pszName));
pCurrRuleset = pRuleset;
dbgprintf("current rule set changed to %p: '%s'\n", pRuleset, pszName);
@@ -591,7 +591,7 @@ CODESTARTobjQueryInterface(ruleset)
pIf->SetName = setName;
pIf->DebugPrintAll = debugPrintAll;
pIf->GetCurrent = GetCurrent;
- pIf->GetRuleset = GetRuleset;
+ pIf->GetRuleset = rulesetGetRuleset;
pIf->SetDefaultRuleset = SetDefaultRuleset;
pIf->SetCurrRuleset = SetCurrRuleset;
pIf->GetRulesetQueue = GetRulesetQueue;
diff --git a/runtime/ruleset.h b/runtime/ruleset.h
index b055a71..52e633e 100644
--- a/runtime/ruleset.h
+++ b/runtime/ruleset.h
@@ -54,6 +54,7 @@ BEGINinterface(ruleset) /* name must also be changed in ENDinterface macro! */
qqueue_t* (*GetRulesetQueue)(ruleset_t*);
/* v3, 2009-11-04 */
parserList_t* (*GetParserList)(msg_t *);
+ /* v4 */
ENDinterface(ruleset)
#define rulesetCURR_IF_VERSION 4 /* increment whenever you change the interface structure! */
@@ -61,4 +62,18 @@ ENDinterface(ruleset)
/* prototypes */
PROTOTYPEObj(ruleset);
+
+/* Get name associated to ruleset. This function cannot fail (except,
+ * of course, if previously something went really wrong). Returned
+ * pointer is read-only.
+ * rgerhards, 2012-04-18
+ */
+static inline uchar*
+rulesetGetName(ruleset_t *pRuleset)
+{
+ return pRuleset->pszName;
+}
+
+
+rsRetVal rulesetGetRuleset(ruleset_t **ppRuleset, uchar *pszName);
#endif /* #ifndef INCLUDED_RULESET_H */
diff --git a/tools/syslogd.c b/tools/syslogd.c
index 0b7bbc9..93f37e4 100644
--- a/tools/syslogd.c
+++ b/tools/syslogd.c
@@ -21,7 +21,7 @@
* For further information, please see http://www.rsyslog.com
*
* rsyslog - An Enhanced syslogd Replacement.
- * Copyright 2003-2009 Rainer Gerhards and Adiscon GmbH.
+ * Copyright 2003-2012 Rainer Gerhards and Adiscon GmbH.
*
* This file is part of rsyslog.
*
@@ -154,6 +154,7 @@ DEFobjCurrIf(net) /* TODO: make go away! */
/* forward definitions */
static rsRetVal GlobalClassExit(void);
+static rsRetVal queryLocalHostname(void);
#ifndef _PATH_LOGCONF
@@ -1488,6 +1489,7 @@ runInputModules(void)
pMod = module.GetNxtType(NULL, eMOD_IN);
while(pMod != NULL) {
if(pMod->mod.im.bCanRun) {
+ DBGPRINTF("trying to start input module '%s'\n", pMod->pszName);
/* activate here */
bNeedsCancel = (pMod->isCompatibleWithFeature(sFEATURENonCancelInputTermination) == RS_RET_OK) ?
0 : 1;
@@ -1897,6 +1899,11 @@ DEFFUNC_llExecFunc(doHUPActions)
* is *NOT* the sighup handler. The signal is recorded by the handler, that record
* detected inside the mainloop and then this function is called to do the
* real work. -- rgerhards, 2008-10-22
+ * Note: there is a VERY slim chance of a data race when the hostname is reset.
+ * We prefer to take this risk rather than sync all accesses, because to the best
+ * of my analysis it can not really hurt (the actual property is reference-counted)
+ * but the sync would require some extra CPU for *each* message processed.
+ * rgerhards, 2012-04-11
*/
static inline void
doHUP(void)
@@ -1912,6 +1919,7 @@ doHUP(void)
logmsgInternal(NO_ERRCODE, LOG_SYSLOG|LOG_INFO, (uchar*)buf, 0);
}
+ queryLocalHostname(); /* re-read our name */
ruleset.IterateAllActions(doHUPActions, NULL);
}
@@ -2329,6 +2337,93 @@ GlobalClassExit(void)
}
+/* query our host and domain names - we need to do this early as we may emit
+ * rgerhards, 2012-04-11
+ */
+static rsRetVal
+queryLocalHostname(void)
+{
+ uchar *LocalHostName;
+ uchar *LocalDomain;
+ uchar *LocalFQDNName;
+ uchar *p;
+ struct hostent *hent;
+ DEFiRet;
+
+ net.getLocalHostname(&LocalFQDNName);
+ CHKmalloc(LocalHostName = (uchar*) strdup((char*)LocalFQDNName));
+ glbl.SetLocalFQDNName(LocalFQDNName); /* set the FQDN before we modify it */
+ if((p = (uchar*)strchr((char*)LocalHostName, '.'))) {
+ *p++ = '\0';
+ LocalDomain = p;
+ } else {
+ LocalDomain = (uchar*)"";
+
+ /* It's not clearly defined whether gethostname()
+ * should return the simple hostname or the fqdn. A
+ * good piece of software should be aware of both and
+ * we want to distribute good software. Joey
+ *
+ * Good software also always checks its return values...
+ * If syslogd starts up before DNS is up & /etc/hosts
+ * doesn't have LocalHostName listed, gethostbyname will
+ * return NULL.
+ */
+ /* TODO: gethostbyname() is not thread-safe, but replacing it is
+ * not urgent as we do not run on multiple threads here. rgerhards, 2007-09-25
+ */
+ hent = gethostbyname((char*)LocalHostName);
+ if(hent) {
+ int i = 0;
+
+ if(hent->h_aliases) {
+ size_t hnlen;
+
+ hnlen = strlen((char *) LocalHostName);
+
+ for (i = 0; hent->h_aliases[i]; i++) {
+ if (!strncmp(hent->h_aliases[i], (char *) LocalHostName, hnlen)
+ && hent->h_aliases[i][hnlen] == '.') {
+ /* found a matching hostname */
+ break;
+ }
+ }
+ }
+
+ free(LocalHostName);
+ if(hent->h_aliases && hent->h_aliases[i]) {
+ CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_aliases[i]));
+ } else {
+ CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_name));
+ }
+
+ if((p = (uchar*)strchr((char*)LocalHostName, '.')))
+ {
+ *p++ = '\0';
+ LocalDomain = p;
+ }
+ }
+ }
+
+ /* LocalDomain is "" or part of LocalHostName, allocate a new string */
+ CHKmalloc(LocalDomain = (uchar*)strdup(LocalDomain));
+
+ /* Convert to lower case to recognize the correct domain laterly */
+ for(p = LocalDomain ; *p ; p++)
+ *p = (char)tolower((int)*p);
+
+ /* we now have our hostname and can set it inside the global vars.
+ * TODO: think if all of this would better be a runtime function
+ * rgerhards, 2008-04-17
+ */
+ glbl.SetLocalHostName(LocalHostName);
+ glbl.SetLocalDomain(LocalDomain);
+ glbl.GenerateLocalHostNameProperty(); /* must be redone after conf processing, FQDN setting may have changed */
+finalize_it:
+ RETiRet;
+}
+
+
/* some support for command line option parsing. Any non-trivial options must be
* buffered until the complete command line has been parsed. This is necessary to
* prevent dependencies between the options. That, in turn, means we need to have
@@ -2530,9 +2625,7 @@ int realMain(int argc, char **argv)
{
DEFiRet;
- register uchar *p;
int ch;
- struct hostent *hent;
extern int optind;
extern char *optarg;
int bEOptionWasGiven = 0;
@@ -2541,9 +2634,6 @@ int realMain(int argc, char **argv)
int bChDirRoot = 1; /* change the current working directory to "/"? */
char *arg; /* for command line option processing */
uchar legacyConfLine[80];
- uchar *LocalHostName;
- uchar *LocalDomain;
- uchar *LocalFQDNName;
char cwdbuf[128]; /* buffer to obtain/display current working directory */
/* first, parse the command line options. We do not carry out any actual work, just
@@ -2651,7 +2741,7 @@ int realMain(int argc, char **argv)
/* we need to create the inputName property (only once during our lifetime) */
CHKiRet(prop.Construct(&pInternalInputName));
- CHKiRet(prop.SetString(pInternalInputName, UCHAR_CONSTANT("rsyslogd"), sizeof("rsyslgod") - 1));
+ CHKiRet(prop.SetString(pInternalInputName, UCHAR_CONSTANT("rsyslogd"), sizeof("rsyslogd") - 1));
CHKiRet(prop.ConstructFinalize(pInternalInputName));
CHKiRet(prop.Construct(&pLocalHostIP));
@@ -2661,72 +2751,7 @@ int realMain(int argc, char **argv)
/* get our host and domain names - we need to do this early as we may emit
* error log messages, which need the correct hostname. -- rgerhards, 2008-04-04
*/
- net.getLocalHostname(&LocalFQDNName);
- CHKmalloc(LocalHostName = (uchar*) strdup((char*)LocalFQDNName));
- glbl.SetLocalFQDNName(LocalFQDNName); /* set the FQDN before we modify it */
- if((p = (uchar*)strchr((char*)LocalHostName, '.'))) {
- *p++ = '\0';
- LocalDomain = p;
- } else {
- LocalDomain = (uchar*)"";
-
- /* It's not clearly defined whether gethostname()
- * should return the simple hostname or the fqdn. A
- * good piece of software should be aware of both and
- * we want to distribute good software. Joey
- *
- * Good software also always checks its return values...
- * If syslogd starts up before DNS is up & /etc/hosts
- * doesn't have LocalHostName listed, gethostbyname will
- * return NULL.
- */
- /* TODO: gethostbyname() is not thread-safe, but replacing it is
- * not urgent as we do not run on multiple threads here. rgerhards, 2007-09-25
- */
- hent = gethostbyname((char*)LocalHostName);
- if(hent) {
- int i = 0;
-
- if(hent->h_aliases) {
- size_t hnlen;
-
- hnlen = strlen((char *) LocalHostName);
-
- for (i = 0; hent->h_aliases[i]; i++) {
- if (!strncmp(hent->h_aliases[i], (char *) LocalHostName, hnlen)
- && hent->h_aliases[i][hnlen] == '.') {
- /* found a matching hostname */
- break;
- }
- }
- }
-
- free(LocalHostName);
- if(hent->h_aliases && hent->h_aliases[i]) {
- CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_aliases[i]));
- } else {
- CHKmalloc(LocalHostName = (uchar*)strdup(hent->h_name));
- }
-
- if((p = (uchar*)strchr((char*)LocalHostName, '.')))
- {
- *p++ = '\0';
- LocalDomain = p;
- }
- }
- }
-
- /* Convert to lower case to recognize the correct domain laterly */
- for(p = LocalDomain ; *p ; p++)
- *p = (char)tolower((int)*p);
-
- /* we now have our hostname and can set it inside the global vars.
- * TODO: think if all of this would better be a runtime function
- * rgerhards, 2008-04-17
- */
- glbl.SetLocalHostName(LocalHostName);
- glbl.SetLocalDomain(LocalDomain);
- glbl.GenerateLocalHostNameProperty(); /* must be redone after conf processing, FQDN setting may have changed */
+ queryLocalHostname();
/* initialize the objects */
if((iRet = modInitIminternal()) != RS_RET_OK) {