From 50636ba267bb1930bce7c3baecdab8a245d52b05 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sun, 28 Feb 2010 17:18:04 +0100 Subject: moved pipe code to its own module ... based on old omfile. Michael Biebl reported that xconsole seems to have some issues with the new pipe code, so it was best to use the old code for pipes. The optimizations were done to speed up file access, so it doesn't really matter pipes do not receive them. --- tools/ompipe.c | 243 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 243 insertions(+) create mode 100644 tools/ompipe.c (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c new file mode 100644 index 00000000..89fc05ef --- /dev/null +++ b/tools/ompipe.c @@ -0,0 +1,243 @@ +/* ompipe.c + * This is the implementation of the build-in pipe output module. + * Note that this module stems back to the "old" (4.4.2 and below) + * omfile. There were some issues with the new omfile code and pipes + * (namely in regard to xconsole), so we took out the pipe code and moved + * that to a separate module. That a) immediately solves the issue for a + * less common use case and probably makes it much easier to enhance + * file and pipe support (now independently) in the future (we always + * needed to think about pipes in omfile so far, what we now no longer + * need to, hopefully resulting in reduction of complexity). + * + * NOTE: read comments in module-template.h to understand how this pipe + * works! + * + * Copyright 2007-2010 Rainer Gerhards and Adiscon GmbH. + * + * This file is part of rsyslog. + * + * Rsyslog is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Rsyslog is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Rsyslog. If not, see . + * + * A copy of the GPL can be found in the file "COPYING" in this distribution. + */ +#include "config.h" +#include "rsyslog.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "syslogd.h" +#include "syslogd-types.h" +#include "srUtils.h" +#include "template.h" +#include "ompipe.h" +#include "cfsysline.h" +#include "module-template.h" +#include "errmsg.h" + +MODULE_TYPE_OUTPUT + +/* internal structures + */ +DEF_OMOD_STATIC_DATA +DEFobjCurrIf(errmsg) + + +/* globals for default values */ +static uchar *pszTplName = NULL; /* name of the default template to use */ +/* end globals for default values */ + + +typedef struct _instanceData { + uchar f_fname[MAXFNAME];/* pipe or template name (display only) */ + short fd; /* pipe descriptor for (current) pipe */ +} instanceData; + + +BEGINisCompatibleWithFeature +CODESTARTisCompatibleWithFeature + if(eFeat == sFEATURERepeatedMsgReduction) + iRet = RS_RET_OK; +ENDisCompatibleWithFeature + + +BEGINdbgPrintInstInfo +CODESTARTdbgPrintInstInfo + dbgprintf("pipe %s", pData->f_fname); + if (pData->fd == -1) + dbgprintf(" (unused)"); +ENDdbgPrintInstInfo + + +/* This is now shared code for all types of files. It simply prepares + * pipe access, which, among others, means the the pipe wil be opened + * and any directories in between will be created (based on config, of + * course). -- rgerhards, 2008-10-22 + * changed to iRet interface - 2009-03-19 + */ +static rsRetVal +preparePipe(instanceData *pData) +{ + DEFiRet; + pData->fd = open((char*) pData->f_fname, O_RDWR|O_NONBLOCK|O_CLOEXEC); + RETiRet; +} + + +/* rgerhards 2004-11-11: write to a pipe output. This + * will be called for all outputs using pipe semantics, + * for example also for pipes. + */ +static rsRetVal writePipe(uchar **ppString, instanceData *pData) +{ + int iLenWritten; + DEFiRet; + + ASSERT(pData != NULL); + + if(pData->fd == -1) { + rsRetVal iRetLocal; + iRetLocal = preparePipe(pData); + if((iRetLocal != RS_RET_OK) || (pData->fd == -1)) + ABORT_FINALIZE(RS_RET_SUSPENDED); /* whatever the failure was, we need to retry */ + } + + /* create the message based on format specified */ + iLenWritten = write(pData->fd, ppString[0], strlen((char*)ppString[0])); + if(iLenWritten < 0) { + int e = errno; + char errStr[1024]; + rs_strerror_r(errno, errStr, sizeof(errStr)); + DBGPRINTF("pipe (%d) write error %d: %s\n", pData->fd, e, errStr); + + /* If a named pipe is full, we suspend this action for a while */ + if(e == EAGAIN) + ABORT_FINALIZE(RS_RET_SUSPENDED); + + close(pData->fd); + pData->fd = -1; /* tell that fd is no longer open! */ + iRet = RS_RET_SUSPENDED; + errno = e; + errmsg.LogError(0, NO_ERRCODE, "%s", pData->f_fname); + } + +finalize_it: + RETiRet; +} + + +BEGINcreateInstance +CODESTARTcreateInstance + pData->fd = -1; +ENDcreateInstance + + +BEGINfreeInstance +CODESTARTfreeInstance + if(pData->fd != -1) + close(pData->fd); +ENDfreeInstance + + +BEGINtryResume +CODESTARTtryResume +ENDtryResume + +BEGINdoAction +CODESTARTdoAction + DBGPRINTF(" (%s)\n", pData->f_fname); + iRet = writePipe(ppString, pData); +ENDdoAction + + +BEGINparseSelectorAct +CODESTARTparseSelectorAct + /* yes, the if below is redundant, but I need it now. Will go away as + * the code further changes. -- rgerhards, 2007-07-25 + */ + if(*p == '|') { + if((iRet = createInstance(&pData)) != RS_RET_OK) { + ENDfunc + return iRet; /* this can not use RET_iRet! */ + } + } else { + /* this is not clean, but we need it for the time being + * TODO: remove when cleaning up modularization + */ + ENDfunc + return RS_RET_CONFLINE_UNPROCESSED; + } + + CODE_STD_STRING_REQUESTparseSelectorAct(1) + ++p; + /* rgerhards 2004-11-17: from now, we need to have different + * processing, because after the first comma, the template name + * to use is specified. So we need to scan for the first coma first + * and then look at the rest of the line. + */ + CHKiRet(cflineParseFileName(p, (uchar*) pData->f_fname, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, + (pszTplName == NULL) ? (uchar*)"RSYSLOG_FileFormat" : pszTplName)); + + /* at this stage, we ignore the return value of preparePipe, this is taken + * care of in later steps. -- rgerhards, 2009-03-19 + */ + preparePipe(pData); + + if(pData->fd < 0 ) { + pData->fd = -1; + DBGPRINTF("Error opening log pipe: %s\n", pData->f_fname); + errmsg.LogError(0, RS_RET_NO_FILE_ACCESS, "Could no open output pipe '%s'", pData->f_fname); + } +CODE_STD_FINALIZERparseSelectorAct +ENDparseSelectorAct + + +BEGINdoHUP +CODESTARTdoHUP + if(pData->fd != -1) { + close(pData->fd); + pData->fd = -1; + } +ENDdoHUP + + +BEGINmodExit +CODESTARTmodExit + if(pszTplName != NULL) + free(pszTplName); +ENDmodExit + + +BEGINqueryEtryPt +CODESTARTqueryEtryPt +CODEqueryEtryPt_STD_OMOD_QUERIES +CODEqueryEtryPt_doHUP +ENDqueryEtryPt + + +BEGINmodInit(Pipe) +CODESTARTmodInit + *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ +CODEmodInit_QueryRegCFSLineHdlr + CHKiRet(objUse(errmsg, CORE_COMPONENT)); +ENDmodInit +/* vi:set ai: + */ -- cgit v1.2.3 From 791d8ea863cbd53eccf989e92ffd8b2ac00dd179 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sun, 28 Feb 2010 17:28:52 +0100 Subject: some code cleanup --- tools/ompipe.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 89fc05ef..3355bcb4 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -37,11 +37,8 @@ #include #include #include -#include #include #include -#include -#include #include #include "syslogd.h" @@ -51,6 +48,7 @@ #include "ompipe.h" #include "cfsysline.h" #include "module-template.h" +#include "conf.h" #include "errmsg.h" MODULE_TYPE_OUTPUT @@ -93,7 +91,7 @@ ENDdbgPrintInstInfo * course). -- rgerhards, 2008-10-22 * changed to iRet interface - 2009-03-19 */ -static rsRetVal +static inline rsRetVal preparePipe(instanceData *pData) { DEFiRet; -- cgit v1.2.3 From 2c39f76037328459c5cff14762e0839b1e77d570 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 1 Mar 2010 07:33:09 +0100 Subject: make $ActonFileDefaultTemplate available to ompipe This was not honored by the new ompipe module, because it is a local file directive (it was applied to pipes as a side-effect of using the same module for pipes and files...). I now made this a global, so that semantics are the same as previously. Not really nice, but probably the best thing to do in the current situation (everything else would involve much more overhead --- leave that for the new config system). --- tools/ompipe.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 3355bcb4..5fb9b27e 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -46,6 +46,7 @@ #include "srUtils.h" #include "template.h" #include "ompipe.h" +#include "omfile.h" /* for dirty trick: access to $ActionFileDefaultTemplate value */ #include "cfsysline.h" #include "module-template.h" #include "conf.h" @@ -60,7 +61,6 @@ DEFobjCurrIf(errmsg) /* globals for default values */ -static uchar *pszTplName = NULL; /* name of the default template to use */ /* end globals for default values */ @@ -192,7 +192,7 @@ CODESTARTparseSelectorAct * and then look at the rest of the line. */ CHKiRet(cflineParseFileName(p, (uchar*) pData->f_fname, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, - (pszTplName == NULL) ? (uchar*)"RSYSLOG_FileFormat" : pszTplName)); + (pszFileDfltTplName == NULL) ? (uchar*)"RSYSLOG_FileFormat" : pszFileDfltTplName)); /* at this stage, we ignore the return value of preparePipe, this is taken * care of in later steps. -- rgerhards, 2009-03-19 @@ -219,8 +219,6 @@ ENDdoHUP BEGINmodExit CODESTARTmodExit - if(pszTplName != NULL) - free(pszTplName); ENDmodExit -- cgit v1.2.3 From 2a494ffc41cd33124bbfea01ad41750b8967efed Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 2 Mar 2010 10:18:33 +0100 Subject: added include needed for Solaris --- tools/ompipe.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 5fb9b27e..7cf61822 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include "syslogd.h" -- cgit v1.2.3 From 4e511087c413629120315fe5dd26f966ac1ef6fb Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 19 Apr 2010 15:21:25 +0200 Subject: some cleanup --- tools/ompipe.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 7cf61822..40e9e79b 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3 From 393c67ba5bc20613436552a26a6f0a20d4dda9fe Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 19 Apr 2010 15:38:11 +0200 Subject: minor cleanup --- tools/ompipe.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 7cf61822..2d621e0e 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3 From d18b238f16a7ff4dbb998314b6d76ffb8b2acf59 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 27 Jul 2010 09:44:35 +0200 Subject: milestone commit: output plugin interface changes (may NOT run) The output interface has been changed, but we do not yet utilize the new interface. Also, it looks like a regression was introduced. But before hunting it down, I'd like to make a commit (what also easys the regresion hunt). --- tools/ompipe.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index cf22bc84..e8ace07a 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -72,6 +72,16 @@ typedef struct _instanceData { short fd; /* pipe descriptor for (current) pipe */ } instanceData; +typedef struct configSettings_s { + EMPTY_STRUCT +} configSettings_t; + +SCOPING_SUPPORT; /* must be set AFTER configSettings_t is defined */ + +BEGINinitConfVars /* (re)set config variables to default values */ +CODESTARTinitConfVars +ENDinitConfVars + BEGINisCompatibleWithFeature CODESTARTisCompatibleWithFeature -- cgit v1.2.3 From d460c1cd5d3c13ddc70f1d21ae4befa35b1ac627 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 27 Jul 2010 11:38:25 +0200 Subject: fixed regression from last commit config variables were not properly initialized --- tools/ompipe.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index e8ace07a..c2435438 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -244,6 +244,7 @@ ENDqueryEtryPt BEGINmodInit(Pipe) CODESTARTmodInit +SCOPINGmodInit *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr CHKiRet(objUse(errmsg, CORE_COMPONENT)); -- cgit v1.2.3 From 0a24b3afc093e16038da170458e2ecb68b363bdd Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 19 Oct 2010 12:39:48 +0200 Subject: fixing some compile problems on FreeBSD --- tools/ompipe.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 5fb9b27e..541b6552 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -39,6 +39,7 @@ #include #include #include +#include #include #include "syslogd.h" -- cgit v1.2.3 From d1eb6e0edc51a78f3209448e800b25eda50340f2 Mon Sep 17 00:00:00 2001 From: Bojan Smojver Date: Wed, 23 Feb 2011 11:25:43 +0100 Subject: added work-around for bug in gtls, which causes fd leak when using TLS The capability has been added for module to specify that they do not like being unloaded. related bug tracker: http://bugzilla.adiscon.com/show_bug.cgi?id=222 Signed-off-by: Rainer Gerhards --- tools/ompipe.c | 1 + 1 file changed, 1 insertion(+) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index c51a5c48..58725fb9 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -57,6 +57,7 @@ #include "errmsg.h" MODULE_TYPE_OUTPUT +MODULE_TYPE_NOKEEP /* internal structures */ -- cgit v1.2.3 From e1c34e174139ad030ca1108ff9782b294909013c Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 19 Apr 2011 07:53:23 +0200 Subject: renamed conf.c to legacyconf.c to make room for new config system --- tools/ompipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 01695369..db4de73b 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -53,7 +53,7 @@ #include "omfile.h" /* for dirty trick: access to $ActionFileDefaultTemplate value */ #include "cfsysline.h" #include "module-template.h" -#include "conf.h" +#include "legacyconf.h" #include "errmsg.h" MODULE_TYPE_OUTPUT -- cgit v1.2.3 From bbe1f2688c4bd5cb1b66bb48af1ce5428d69c3b9 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 19 Apr 2011 08:24:25 +0200 Subject: renaming conf.* wasn't a good idea -- undoing too many dependencies, things get cluttered (and merging probably gets problematic). Now new config will be "conf2". --- tools/ompipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index db4de73b..01695369 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -53,7 +53,7 @@ #include "omfile.h" /* for dirty trick: access to $ActionFileDefaultTemplate value */ #include "cfsysline.h" #include "module-template.h" -#include "legacyconf.h" +#include "conf.h" #include "errmsg.h" MODULE_TYPE_OUTPUT -- cgit v1.2.3 From 415b95cf453403f726f654cbc03ef3984446a870 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Tue, 26 Apr 2011 18:38:42 +0200 Subject: bugfix: pipes not opened in full priv mode when privs are to be dropped --- tools/ompipe.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 58725fb9..cbedb559 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -72,6 +72,7 @@ DEFobjCurrIf(errmsg) typedef struct _instanceData { uchar f_fname[MAXFNAME];/* pipe or template name (display only) */ short fd; /* pipe descriptor for (current) pipe */ + sbool bHadError; /* did we already have/report an error on this pipe? */ } instanceData; @@ -101,6 +102,17 @@ preparePipe(instanceData *pData) { DEFiRet; pData->fd = open((char*) pData->f_fname, O_RDWR|O_NONBLOCK|O_CLOEXEC); + if(pData->fd < 0 ) { + pData->fd = -1; + if(!pData->bHadError) { + char errStr[1024]; + rs_strerror_r(errno, errStr, sizeof(errStr)); + errmsg.LogError(0, RS_RET_NO_FILE_ACCESS, "Could no open output pipe '%s': %s", + pData->f_fname, errStr); + pData->bHadError = 1; + } + DBGPRINTF("Error opening log pipe: %s\n", pData->f_fname); + } RETiRet; } @@ -150,6 +162,7 @@ finalize_it: BEGINcreateInstance CODESTARTcreateInstance pData->fd = -1; + pData->bHadError = 0; ENDcreateInstance @@ -204,11 +217,6 @@ CODESTARTparseSelectorAct */ preparePipe(pData); - if(pData->fd < 0 ) { - pData->fd = -1; - DBGPRINTF("Error opening log pipe: %s\n", pData->f_fname); - errmsg.LogError(0, RS_RET_NO_FILE_ACCESS, "Could no open output pipe '%s'", pData->f_fname); - } CODE_STD_FINALIZERparseSelectorAct ENDparseSelectorAct -- cgit v1.2.3 From c6fc7f5ba321047aaa20a79ac47fcc2d529a3415 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Wed, 27 Apr 2011 18:07:14 +0200 Subject: merge fix: made mistake when merging in v5-devel changes, now fixing --- tools/ompipe.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index d6b1f389..5d9397e1 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -221,11 +221,6 @@ CODESTARTparseSelectorAct */ CHKiRet(cflineParseFileName(p, (uchar*) pData->f_fname, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (pszFileDfltTplName == NULL) ? (uchar*)"RSYSLOG_FileFormat" : pszFileDfltTplName)); - - /* at this stage, we ignore the return value of preparePipe, this is taken - * care of in later steps. -- rgerhards, 2009-03-19 - */ - preparePipe(pData); CODE_STD_FINALIZERparseSelectorAct ENDparseSelectorAct -- cgit v1.2.3 From 9ce9fbb28f7a7a1a0380cc272a90be077cd9c1bc Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 21 Jul 2011 11:14:52 +0200 Subject: milestone: new output plugin interface call added --- tools/ompipe.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 5d9397e1..d5faffc8 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -58,6 +58,7 @@ MODULE_TYPE_OUTPUT MODULE_TYPE_NOKEEP +MODULE_CNFNAME("ompipe") /* internal structures */ @@ -244,6 +245,7 @@ BEGINqueryEtryPt CODESTARTqueryEtryPt CODEqueryEtryPt_STD_OMOD_QUERIES CODEqueryEtryPt_doHUP +CODEqueryEtryPt_STD_CONF2_CNFNAME_QUERIES ENDqueryEtryPt -- cgit v1.2.3 From b7e69a240037277e77685af5ea5623cdd89ec2d2 Mon Sep 17 00:00:00 2001 From: Andrew Stothard Date: Thu, 15 Sep 2011 15:17:09 +0200 Subject: typo fix --- tools/ompipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 541b6552..998a8f4a 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -203,7 +203,7 @@ CODESTARTparseSelectorAct if(pData->fd < 0 ) { pData->fd = -1; DBGPRINTF("Error opening log pipe: %s\n", pData->f_fname); - errmsg.LogError(0, RS_RET_NO_FILE_ACCESS, "Could no open output pipe '%s'", pData->f_fname); + errmsg.LogError(0, RS_RET_NO_FILE_ACCESS, "Could not open output pipe '%s'", pData->f_fname); } CODE_STD_FINALIZERparseSelectorAct ENDparseSelectorAct -- cgit v1.2.3 From e335a65788ccb9cd381dbd28982079a914f4ae4e Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Sat, 14 Jan 2012 18:01:12 +0100 Subject: more license analysis & change --- tools/ompipe.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 1409287e..77a1ab60 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -12,24 +12,23 @@ * NOTE: read comments in module-template.h to understand how this pipe * works! * - * Copyright 2007-2010 Rainer Gerhards and Adiscon GmbH. + * Copyright 2007-2012 Rainer Gerhards and Adiscon GmbH. * * This file is part of rsyslog. * - * Rsyslog is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Rsyslog is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Rsyslog. If not, see . - * - * A copy of the GPL can be found in the file "COPYING" in this distribution. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * -or- + * see COPYING.ASL20 in the source distribution + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #include "config.h" #include "rsyslog.h" -- cgit v1.2.3 From 535d6cf0b8fe2423eee3fd670bc1e944b231e827 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 19 Jan 2012 14:48:40 +0100 Subject: v6.1/2 scoping support removed from plugins --- tools/ompipe.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 7400bb18..1eb0dbce 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -78,8 +78,7 @@ typedef struct _instanceData { typedef struct configSettings_s { EMPTY_STRUCT } configSettings_t; - -SCOPING_SUPPORT; /* must be set AFTER configSettings_t is defined */ +static configSettings_t cs; BEGINinitConfVars /* (re)set config variables to default values */ CODESTARTinitConfVars @@ -250,7 +249,7 @@ ENDqueryEtryPt BEGINmodInit(Pipe) CODESTARTmodInit -SCOPINGmodInit +INITLegCnfVars *ipIFVersProvided = CURR_MOD_IF_VERSION; /* we only support the current interface specification */ CODEmodInit_QueryRegCFSLineHdlr CHKiRet(objUse(errmsg, CORE_COMPONENT)); -- cgit v1.2.3 From b68af9a016c229259ccb259c33e6598a3a77ea35 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 19 Jan 2012 15:41:49 +0100 Subject: cosmetic: remove compiler warnings --- tools/ompipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 1eb0dbce..3d887e14 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -78,7 +78,7 @@ typedef struct _instanceData { typedef struct configSettings_s { EMPTY_STRUCT } configSettings_t; -static configSettings_t cs; +static configSettings_t __attribute__((unused)) cs; BEGINinitConfVars /* (re)set config variables to default values */ CODESTARTinitConfVars -- cgit v1.2.3 From 532d6994dffd733e8850d3c743a7b791f8d388b1 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 27 Jan 2012 12:05:40 +0100 Subject: ompipe: support for v6 config system added --- tools/ompipe.c | 71 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 63 insertions(+), 8 deletions(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 3d887e14..dfaa3cb8 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -70,9 +70,10 @@ DEFobjCurrIf(errmsg) typedef struct _instanceData { - uchar f_fname[MAXFNAME];/* pipe or template name (display only) */ - short fd; /* pipe descriptor for (current) pipe */ - sbool bHadError; /* did we already have/report an error on this pipe? */ + uchar *f_fname; /* pipe or template name (display only) */ + uchar *tplName; /* format template to use */ + short fd; /* pipe descriptor for (current) pipe */ + sbool bHadError; /* did we already have/report an error on this pipe? */ } instanceData; typedef struct configSettings_s { @@ -80,6 +81,18 @@ typedef struct configSettings_s { } configSettings_t; static configSettings_t __attribute__((unused)) cs; +/* tables for interfacing with the v6 config system */ +/* action (instance) parameters */ +static struct cnfparamdescr actpdescr[] = { + { "pipe", eCmdHdlrString, CNFPARAM_REQUIRED }, + { "template", eCmdHdlrGetWord, 0 } +}; +static struct cnfparamblk actpblk = + { CNFPARAMBLK_VERSION, + sizeof(actpdescr)/sizeof(struct cnfparamdescr), + actpdescr + }; + BEGINinitConfVars /* (re)set config variables to default values */ CODESTARTinitConfVars ENDinitConfVars @@ -170,6 +183,7 @@ finalize_it: BEGINcreateInstance CODESTARTcreateInstance + pData->f_fname = NULL; pData->fd = -1; pData->bHadError = 0; ENDcreateInstance @@ -177,6 +191,7 @@ ENDcreateInstance BEGINfreeInstance CODESTARTfreeInstance + free(pData->f_fname); if(pData->fd != -1) close(pData->fd); ENDfreeInstance @@ -193,6 +208,49 @@ CODESTARTdoAction ENDdoAction +static inline void +setInstParamDefaults(instanceData *pData) +{ + pData->tplName = NULL; +} + +BEGINnewActInst + struct cnfparamvals *pvals; + int i; +CODESTARTnewActInst + if((pvals = nvlstGetParams(lst, &actpblk, NULL)) == NULL) { + ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS); + } + + CHKiRet(createInstance(&pData)); + setInstParamDefaults(pData); + + CODE_STD_STRING_REQUESTparseSelectorAct(1) + for(i = 0 ; i < actpblk.nParams ; ++i) { + if(!pvals[i].bUsed) + continue; + if(!strcmp(actpblk.descr[i].name, "pipe")) { + pData->f_fname = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); + } else if(!strcmp(actpblk.descr[i].name, "template")) { + pData->tplName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); + } else { + dbgprintf("ompipe: program error, non-handled " + "param '%s'\n", actpblk.descr[i].name); + } + } + + if(pData->tplName == NULL) { + CHKiRet(OMSRsetEntry(*ppOMSR, 0, (uchar*) "RSYSLOG_FileFormat", + OMSR_NO_RQD_TPL_OPTS)); + } else { + CHKiRet(OMSRsetEntry(*ppOMSR, 0, + (uchar*) strdup((char*) pData->tplName), + OMSR_NO_RQD_TPL_OPTS)); + } +CODE_STD_FINALIZERnewActInst + cnfparamvalsDestruct(pvals, &actpblk); +ENDnewActInst + BEGINparseSelectorAct CODESTARTparseSelectorAct /* yes, the if below is redundant, but I need it now. Will go away as @@ -212,12 +270,8 @@ CODESTARTparseSelectorAct } CODE_STD_STRING_REQUESTparseSelectorAct(1) + CHKmalloc(pData->f_fname = malloc(512)); ++p; - /* rgerhards 2004-11-17: from now, we need to have different - * processing, because after the first comma, the template name - * to use is specified. So we need to scan for the first coma first - * and then look at the rest of the line. - */ CHKiRet(cflineParseFileName(p, (uchar*) pData->f_fname, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (pszFileDfltTplName == NULL) ? (uchar*)"RSYSLOG_FileFormat" : pszFileDfltTplName)); @@ -244,6 +298,7 @@ CODESTARTqueryEtryPt CODEqueryEtryPt_STD_OMOD_QUERIES CODEqueryEtryPt_doHUP CODEqueryEtryPt_STD_CONF2_CNFNAME_QUERIES +CODEqueryEtryPt_STD_CONF2_OMOD_QUERIES ENDqueryEtryPt -- cgit v1.2.3 From 6ff5f6d239ec7489e9f55cdfb665ce1e84e3865b Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Fri, 27 Jan 2012 12:06:14 +0100 Subject: ompipe: cosmetic, rename var --- tools/ompipe.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index dfaa3cb8..30cb9bfc 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -70,7 +70,7 @@ DEFobjCurrIf(errmsg) typedef struct _instanceData { - uchar *f_fname; /* pipe or template name (display only) */ + uchar *pipe; /* pipe or template name (display only) */ uchar *tplName; /* format template to use */ short fd; /* pipe descriptor for (current) pipe */ sbool bHadError; /* did we already have/report an error on this pipe? */ @@ -107,7 +107,7 @@ ENDisCompatibleWithFeature BEGINdbgPrintInstInfo CODESTARTdbgPrintInstInfo - dbgprintf("pipe %s", pData->f_fname); + dbgprintf("pipe %s", pData->pipe); if (pData->fd == -1) dbgprintf(" (unused)"); ENDdbgPrintInstInfo @@ -123,17 +123,17 @@ static inline rsRetVal preparePipe(instanceData *pData) { DEFiRet; - pData->fd = open((char*) pData->f_fname, O_RDWR|O_NONBLOCK|O_CLOEXEC); + pData->fd = open((char*) pData->pipe, O_RDWR|O_NONBLOCK|O_CLOEXEC); if(pData->fd < 0 ) { pData->fd = -1; if(!pData->bHadError) { char errStr[1024]; rs_strerror_r(errno, errStr, sizeof(errStr)); errmsg.LogError(0, RS_RET_NO_FILE_ACCESS, "Could no open output pipe '%s': %s", - pData->f_fname, errStr); + pData->pipe, errStr); pData->bHadError = 1; } - DBGPRINTF("Error opening log pipe: %s\n", pData->f_fname); + DBGPRINTF("Error opening log pipe: %s\n", pData->pipe); } RETiRet; } @@ -173,7 +173,7 @@ static rsRetVal writePipe(uchar **ppString, instanceData *pData) pData->fd = -1; /* tell that fd is no longer open! */ iRet = RS_RET_SUSPENDED; errno = e; - errmsg.LogError(0, NO_ERRCODE, "%s", pData->f_fname); + errmsg.LogError(0, NO_ERRCODE, "%s", pData->pipe); } finalize_it: @@ -183,7 +183,7 @@ finalize_it: BEGINcreateInstance CODESTARTcreateInstance - pData->f_fname = NULL; + pData->pipe = NULL; pData->fd = -1; pData->bHadError = 0; ENDcreateInstance @@ -191,7 +191,7 @@ ENDcreateInstance BEGINfreeInstance CODESTARTfreeInstance - free(pData->f_fname); + free(pData->pipe); if(pData->fd != -1) close(pData->fd); ENDfreeInstance @@ -203,7 +203,7 @@ ENDtryResume BEGINdoAction CODESTARTdoAction - DBGPRINTF(" (%s)\n", pData->f_fname); + DBGPRINTF(" (%s)\n", pData->pipe); iRet = writePipe(ppString, pData); ENDdoAction @@ -230,7 +230,7 @@ CODESTARTnewActInst if(!pvals[i].bUsed) continue; if(!strcmp(actpblk.descr[i].name, "pipe")) { - pData->f_fname = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); + pData->pipe = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); } else if(!strcmp(actpblk.descr[i].name, "template")) { pData->tplName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); } else { @@ -270,9 +270,9 @@ CODESTARTparseSelectorAct } CODE_STD_STRING_REQUESTparseSelectorAct(1) - CHKmalloc(pData->f_fname = malloc(512)); + CHKmalloc(pData->pipe = malloc(512)); ++p; - CHKiRet(cflineParseFileName(p, (uchar*) pData->f_fname, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, + CHKiRet(cflineParseFileName(p, (uchar*) pData->pipe, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, (pszFileDfltTplName == NULL) ? (uchar*)"RSYSLOG_FileFormat" : pszFileDfltTplName)); CODE_STD_FINALIZERparseSelectorAct -- cgit v1.2.3 From e9ad3cafd1b745a060e04372162722870ee6cf08 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 25 Jun 2012 17:21:17 +0200 Subject: ompipe: support for module() global config parameters added --- tools/ompipe.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 97 insertions(+), 5 deletions(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index 30cb9bfc..b774b60f 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -65,10 +65,6 @@ DEF_OMOD_STATIC_DATA DEFobjCurrIf(errmsg) -/* globals for default values */ -/* end globals for default values */ - - typedef struct _instanceData { uchar *pipe; /* pipe or template name (display only) */ uchar *tplName; /* format template to use */ @@ -82,6 +78,16 @@ typedef struct configSettings_s { static configSettings_t __attribute__((unused)) cs; /* tables for interfacing with the v6 config system */ +/* module-global parameters */ +static struct cnfparamdescr modpdescr[] = { + { "template", eCmdHdlrGetWord, 0 }, +}; +static struct cnfparamblk modpblk = + { CNFPARAMBLK_VERSION, + sizeof(modpdescr)/sizeof(struct cnfparamdescr), + modpdescr + }; + /* action (instance) parameters */ static struct cnfparamdescr actpdescr[] = { { "pipe", eCmdHdlrString, CNFPARAM_REQUIRED }, @@ -93,6 +99,25 @@ static struct cnfparamblk actpblk = actpdescr }; +struct modConfData_s { + rsconf_t *pConf; /* our overall config object */ + uchar *tplName; /* default template */ +}; + +static modConfData_t *loadModConf = NULL;/* modConf ptr to use for the current load process */ +static modConfData_t *runModConf = NULL;/* modConf ptr to use for the current exec process */ + +/* this function gets the default template */ +static inline uchar* +getDfltTpl(void) +{ + if(loadModConf != NULL && loadModConf->tplName != NULL) + return loadModConf->tplName; + else + return (uchar*)"RSYSLOG_FileFormat"; +} + + BEGINinitConfVars /* (re)set config variables to default values */ CODESTARTinitConfVars ENDinitConfVars @@ -181,6 +206,71 @@ finalize_it: } +BEGINbeginCnfLoad +CODESTARTbeginCnfLoad + loadModConf = pModConf; + pModConf->pConf = pConf; + pModConf->tplName = NULL; +ENDbeginCnfLoad + +BEGINsetModCnf + struct cnfparamvals *pvals = NULL; + int i; +CODESTARTsetModCnf + pvals = nvlstGetParams(lst, &modpblk, NULL); + if(pvals == NULL) { + errmsg.LogError(0, RS_RET_MISSING_CNFPARAMS, "error processing module " + "config parameters [module(...)]"); + ABORT_FINALIZE(RS_RET_MISSING_CNFPARAMS); + } + + if(Debug) { + dbgprintf("module (global) param blk for omfile:\n"); + cnfparamsPrint(&modpblk, pvals); + } + + for(i = 0 ; i < modpblk.nParams ; ++i) { + if(!pvals[i].bUsed) + continue; + if(!strcmp(modpblk.descr[i].name, "template")) { + loadModConf->tplName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); + if(pszFileDfltTplName != NULL) { + errmsg.LogError(0, RS_RET_DUP_PARAM, "omfile: warning: default template " + "was already set via legacy directive - may lead to inconsistent " + "results."); + } + } else { + dbgprintf("omfile: program error, non-handled " + "param '%s' in beginCnfLoad\n", modpblk.descr[i].name); + } + } +finalize_it: + if(pvals != NULL) + cnfparamvalsDestruct(pvals, &modpblk); +ENDsetModCnf + +BEGINendCnfLoad +CODESTARTendCnfLoad + loadModConf = NULL; /* done loading */ + /* free legacy config vars */ + free(pszFileDfltTplName); + pszFileDfltTplName = NULL; +ENDendCnfLoad + +BEGINcheckCnf +CODESTARTcheckCnf +ENDcheckCnf + +BEGINactivateCnf +CODESTARTactivateCnf + runModConf = pModConf; +ENDactivateCnf + +BEGINfreeCnf +CODESTARTfreeCnf + free(pModConf->tplName); +ENDfreeCnf + BEGINcreateInstance CODESTARTcreateInstance pData->pipe = NULL; @@ -273,7 +363,7 @@ CODESTARTparseSelectorAct CHKmalloc(pData->pipe = malloc(512)); ++p; CHKiRet(cflineParseFileName(p, (uchar*) pData->pipe, *ppOMSR, 0, OMSR_NO_RQD_TPL_OPTS, - (pszFileDfltTplName == NULL) ? (uchar*)"RSYSLOG_FileFormat" : pszFileDfltTplName)); + getDfltTpl())); CODE_STD_FINALIZERparseSelectorAct ENDparseSelectorAct @@ -297,7 +387,9 @@ BEGINqueryEtryPt CODESTARTqueryEtryPt CODEqueryEtryPt_STD_OMOD_QUERIES CODEqueryEtryPt_doHUP +CODEqueryEtryPt_STD_CONF2_QUERIES CODEqueryEtryPt_STD_CONF2_CNFNAME_QUERIES +CODEqueryEtryPt_STD_CONF2_setModCnf_QUERIES CODEqueryEtryPt_STD_CONF2_OMOD_QUERIES ENDqueryEtryPt -- cgit v1.2.3 From 5de5166e44da181d042129585a2919550236a5a0 Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Mon, 25 Jun 2012 17:42:41 +0200 Subject: ompipe: fix copy&paste name errors --- tools/ompipe.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index b774b60f..d293114f 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -225,7 +225,7 @@ CODESTARTsetModCnf } if(Debug) { - dbgprintf("module (global) param blk for omfile:\n"); + dbgprintf("module (global) param blk for ompipe:\n"); cnfparamsPrint(&modpblk, pvals); } @@ -235,12 +235,12 @@ CODESTARTsetModCnf if(!strcmp(modpblk.descr[i].name, "template")) { loadModConf->tplName = (uchar*)es_str2cstr(pvals[i].val.d.estr, NULL); if(pszFileDfltTplName != NULL) { - errmsg.LogError(0, RS_RET_DUP_PARAM, "omfile: warning: default template " + errmsg.LogError(0, RS_RET_DUP_PARAM, "ompipe: warning: default template " "was already set via legacy directive - may lead to inconsistent " "results."); } } else { - dbgprintf("omfile: program error, non-handled " + dbgprintf("ompipe: program error, non-handled " "param '%s' in beginCnfLoad\n", modpblk.descr[i].name); } } -- cgit v1.2.3 From e5ef73eb25c8dda2e19c593ad2fc0a960aa8873b Mon Sep 17 00:00:00 2001 From: Rainer Gerhards Date: Thu, 1 Nov 2012 17:05:07 +0100 Subject: bugfix: invalid rsyslog-internal macro API use This had no bad effect, because the macro did the same as the one that should have been used. --- tools/ompipe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tools/ompipe.c') diff --git a/tools/ompipe.c b/tools/ompipe.c index d293114f..420e2b11 100644 --- a/tools/ompipe.c +++ b/tools/ompipe.c @@ -315,7 +315,7 @@ CODESTARTnewActInst CHKiRet(createInstance(&pData)); setInstParamDefaults(pData); - CODE_STD_STRING_REQUESTparseSelectorAct(1) + CODE_STD_STRING_REQUESTnewActInst(1) for(i = 0 ; i < actpblk.nParams ; ++i) { if(!pvals[i].bUsed) continue; -- cgit v1.2.3