summaryrefslogtreecommitdiffstats
path: root/plugins/imuxsock/imuxsock.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-08-01 15:00:40 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2008-08-01 15:00:40 +0200
commitcaede8f6216a27d06c755698fb0056c32e60bcdb (patch)
tree789fab567e360ff306345fa08845376df31f2454 /plugins/imuxsock/imuxsock.c
parent55d05e060e35035db53c4e1fa5a2facb2a5ff051 (diff)
downloadrsyslog-caede8f6216a27d06c755698fb0056c32e60bcdb.tar.gz
rsyslog-caede8f6216a27d06c755698fb0056c32e60bcdb.tar.xz
rsyslog-caede8f6216a27d06c755698fb0056c32e60bcdb.zip
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.
Diffstat (limited to 'plugins/imuxsock/imuxsock.c')
-rw-r--r--plugins/imuxsock/imuxsock.c41
1 files changed, 30 insertions, 11 deletions
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,