From caede8f6216a27d06c755698fb0056c32e60bcdb Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 1 Aug 2008 15:00:40 +0200 Subject: added $InputUnixListenSocketHostName config directive It permits to override the hostname being used on a local unix socket. This is useful for differentiating "hosts" running in several jails. Feature was suggested by David Darville, thanks for the suggestion. --- ChangeLog | 6 ++++++ configure.ac | 2 +- doc/imuxsock.html | 27 +++++++++++++++++++++------ doc/manual.html | 2 +- plugins/imuxsock/imuxsock.c | 41 ++++++++++++++++++++++++++++++----------- 5 files changed, 59 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index f947ddbe..44b72632 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,10 @@ --------------------------------------------------------------------------- +Version 3.21.2 [DEVEL] (rgerhards), 2008-08-?? +- added $InputUnixListenSocketHostName config directive, which permits to + override the hostname being used on a local unix socket. This is useful + for differentiating "hosts" running in several jails. Feature was + suggested by David Darville, thanks for the suggestion. +--------------------------------------------------------------------------- Version 3.21.1 [DEVEL] (rgerhards), 2008-07-30 - bugfix: no error was reported if the target of a $IncludeConfig could not be accessed. diff --git a/configure.ac b/configure.ac index c28cc139..82742641 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],[3.21.1],[rsyslog@lists.adiscon.com]) +AC_INIT([rsyslog],[3.21.2-Test1],[rsyslog@lists.adiscon.com]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([ChangeLog]) AC_CONFIG_HEADERS([config.h]) diff --git a/doc/imuxsock.html b/doc/imuxsock.html index ee367dbc..3beabe94 100644 --- a/doc/imuxsock.html +++ b/doc/imuxsock.html @@ -1,7 +1,7 @@ -Unix Socket Input - + +Unix Socket Input

Unix Socket Input

@@ -25,15 +25,30 @@ $InputUnixListenSocketIgnoreMsgTimestamp and $SystemLogSocketIgnoreMsgTimestamp +former -p option +
  • $AddUnixListenSocket <name-of-socket> adds additional unix socket, default none -- former -a option
  • +
  • $InputUnixListenSocketHostName <hostname> permits to override the hostname that +shall be used inside messages taken from the next $AddUnixListenSocket socket. Note that +the hostname must be specified before the $AddUnixListenSocket configuration directive, and it +will only affect the next one and then automatically be reset. This functionality is provided so +that the local hostname can be overridden in cases where that is desired.
  • + Caveats/Known Bugs:

    This documentation is sparse and incomplete.

    Sample:

    The following sample is the minimum setup required to accept syslog messages from applications running on the local system.

    - +

    The following sample is a configuration where rsyslogd pulls logs from two +jails, and assigns different hostnames to each of the jails:

    +

    [rsyslog.conf overview] [manual index] [rsyslog site]

    @@ -44,4 +59,4 @@ Copyright Gerhards and Adiscon. Released under the GNU GPL version 3 or higher.

    - \ No newline at end of file + diff --git a/doc/manual.html b/doc/manual.html index a41c44e0..417ef35f 100644 --- a/doc/manual.html +++ b/doc/manual.html @@ -16,7 +16,7 @@ relay chains while at the same time being very easy to setup for the novice user. And as we know what enterprise users really need, there is also professional rsyslog support available directly from the source!

    -

    This documentation is for version 3.21.1 (devel branch) of rsyslog. +

    This documentation is for version 3.21.2 (devel branch) of rsyslog. Visit the rsyslog status page to obtain current version information and project status.

    If you like rsyslog, you might diff --git a/plugins/imuxsock/imuxsock.c b/plugins/imuxsock/imuxsock.c index 5781589f..9d2ab8a1 100644 --- a/plugins/imuxsock/imuxsock.c +++ b/plugins/imuxsock/imuxsock.c @@ -73,12 +73,14 @@ static int startIndexUxLocalSockets; /* process funix from that index on (used t static int funixParseHost[MAXFUNIX] = { 0, }; /* should parser parse host name? read-only after startup */ static int funixFlags[MAXFUNIX] = { ADDDATE, }; /* should parser parse host name? read-only after startup */ static uchar *funixn[MAXFUNIX] = { (uchar*) _PATH_LOG }; /* read-only after startup */ +static uchar *funixHName[MAXFUNIX] = { NULL, }; /* host-name override - if set, use this instead of actual name */ static int funix[MAXFUNIX] = { -1, }; /* read-only after startup */ static int nfunix = 1; /* number of Unix sockets open / read-only after startup */ /* config settings */ static int bOmitLocalLogging = 0; static uchar *pLogSockName = NULL; +static uchar *pLogHostName = NULL; /* host name to use with this socket */ static int bIgnoreTimestamp = 1; /* ignore timestamps present in the incoming message? */ @@ -100,6 +102,7 @@ static rsRetVal setSystemLogTimestampIgnore(void __attribute__((unused)) *pVal, * TODO: we should change the array to a list so that we * can support any number of listen socket names. * rgerhards, 2007-12-20 + * added capability to specify hostname for socket -- rgerhards, 2008-08-01 */ static rsRetVal addLstnSocketName(void __attribute__((unused)) *pVal, uchar *pNewVal) { @@ -110,6 +113,8 @@ static rsRetVal addLstnSocketName(void __attribute__((unused)) *pVal, uchar *pNe else { funixParseHost[nfunix] = 0; } + funixHName[nfunix] = pLogHostName; + pLogHostName = NULL; /* re-init for next, not freed because funixHName[] now owns it */ funixFlags[nfunix] = bIgnoreTimestamp ? ADDDATE : NOFLAG; funixn[nfunix++] = pNewVal; } @@ -134,6 +139,10 @@ static rsRetVal discardFunixn(void) free(funixn[i]); funixn[i] = NULL; } + if(funixHName[i] != NULL) { + free(funixHName[i]); + funixHName[i] = NULL; + } } return RS_RET_OK; @@ -144,7 +153,6 @@ static int create_unix_socket(const char *path) { struct sockaddr_un sunx; int fd; - char line[MAXLINE +1]; if (path[0] == '\0') return -1; @@ -155,11 +163,9 @@ static int create_unix_socket(const char *path) sunx.sun_family = AF_UNIX; (void) strncpy(sunx.sun_path, path, sizeof(sunx.sun_path)); fd = socket(AF_UNIX, SOCK_DGRAM, 0); - if (fd < 0 || bind(fd, (struct sockaddr *) &sunx, - SUN_LEN(&sunx)) < 0 || + if (fd < 0 || bind(fd, (struct sockaddr *) &sunx, SUN_LEN(&sunx)) < 0 || chmod(path, 0666) < 0) { - snprintf(line, sizeof(line), "cannot create %s", path); - errmsg.LogError(errno, NO_ERRCODE, "%s", line); + errmsg.LogError(errno, NO_ERRCODE, "connot create '%s'", path); dbgprintf("cannot create %s (%d).\n", path, errno); close(fd); return -1; @@ -171,18 +177,23 @@ static int create_unix_socket(const char *path) /* This function receives data from a socket indicated to be ready * to receive and submits the message received for processing. * rgerhards, 2007-12-20 + * Interface changed so that this function is passed the array index + * of the socket which is to be processed. This eases access to the + * growing number of properties. -- rgerhards, 2008-08-01 */ -static rsRetVal readSocket(int fd, int bParseHost, int flags) +static rsRetVal readSocket(int fd, int iSock) { DEFiRet; int iRcvd; uchar line[MAXLINE +1]; + assert(iSock >= 0); iRcvd = recv(fd, line, MAXLINE - 1, 0); dbgprintf("Message from UNIX socket: #%d\n", fd); if (iRcvd > 0) { - parseAndSubmitMessage(glbl.GetLocalHostName(), (uchar*)"127.0.0.1", line, - iRcvd, bParseHost, flags, eFLOWCTL_LIGHT_DELAY); + parseAndSubmitMessage(funixHName[iSock] == NULL ? glbl.GetLocalHostName() : funixHName[iSock], + (uchar*)"127.0.0.1", line, + iRcvd, funixParseHost[iSock], funixFlags[iSock], eFLOWCTL_LIGHT_DELAY); } else if (iRcvd < 0 && errno != EINTR) { char errStr[1024]; rs_strerror_r(errno, errStr, sizeof(errStr)); @@ -194,8 +205,7 @@ static rsRetVal readSocket(int fd, int bParseHost, int flags) } -/* This function is called to gather input. - */ +/* This function is called to gather input. */ BEGINrunInput int maxfds; int nfds; @@ -237,7 +247,7 @@ CODESTARTrunInput for (i = 0; i < nfunix && nfds > 0; i++) { if ((fd = funix[i]) != -1 && FD_ISSET(fd, &readfds)) { - readSocket(fd, funixParseHost[i], funixFlags[i]); + readSocket(fd, i); --nfds; /* indicate we have processed one */ } } @@ -282,6 +292,9 @@ CODESTARTafterRun /* free no longer needed string */ if(pLogSockName != NULL) free(pLogSockName); + if(pLogHostName != NULL) { + free(pLogHostName); + } discardFunixn(); nfunix = 1; @@ -307,6 +320,10 @@ static rsRetVal resetConfigVariables(uchar __attribute__((unused)) *pp, void __a free(pLogSockName); pLogSockName = NULL; } + if(pLogHostName != NULL) { + free(pLogHostName); + pLogHostName = NULL; + } discardFunixn(); nfunix = 1; @@ -337,6 +354,8 @@ CODEmodInit_QueryRegCFSLineHdlr NULL, &bIgnoreTimestamp, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"systemlogsocketname", 0, eCmdHdlrGetWord, NULL, &pLogSockName, STD_LOADABLE_MODULE_ID)); + CHKiRet(omsdRegCFSLineHdlr((uchar *)"inputunixlistensockethostname", 0, eCmdHdlrGetWord, + NULL, &pLogHostName, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"addunixlistensocket", 0, eCmdHdlrGetWord, addLstnSocketName, NULL, STD_LOADABLE_MODULE_ID)); CHKiRet(omsdRegCFSLineHdlr((uchar *)"resetconfigvariables", 1, eCmdHdlrCustomHandler, -- cgit