summaryrefslogtreecommitdiffstats
path: root/cfsysline.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2008-01-09 08:25:25 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2008-01-09 08:25:25 +0000
commitfbd4ecdce40d1164c7cbdd55c672a83755e95482 (patch)
treed2e75ea5c1db839157e0e216685640a2e15451f7 /cfsysline.c
parent0964658cc8a276bbdfce335d08898ee4097e87dc (diff)
downloadrsyslog-fbd4ecdce40d1164c7cbdd55c672a83755e95482.tar.gz
rsyslog-fbd4ecdce40d1164c7cbdd55c672a83755e95482.tar.xz
rsyslog-fbd4ecdce40d1164c7cbdd55c672a83755e95482.zip
- implemented new GetSize() handler for config files
- implemented $MainMsgQueueMaxFileSize configuration directive
Diffstat (limited to 'cfsysline.c')
-rw-r--r--cfsysline.c92
1 files changed, 86 insertions, 6 deletions
diff --git a/cfsysline.c b/cfsysline.c
index ff44af68..337d362a 100644
--- a/cfsysline.c
+++ b/cfsysline.c
@@ -96,17 +96,20 @@ finalize_it:
}
-/* Parse a number from the configuration line.
- * rgerhards, 2007-07-31
+/* Parse a number from the configuration line. This functions just parses
+ * the number and does NOT call any handlers or set any values. It is just
+ * for INTERNAL USE by other parse functions!
+ * rgerhards, 2008-01-08
*/
-static rsRetVal doGetInt(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
+static rsRetVal parseIntVal(uchar **pp, size_t *pVal)
{
uchar *p;
DEFiRet;
- int i;
+ size_t i;
assert(pp != NULL);
assert(*pp != NULL);
+ assert(pVal != NULL);
skipWhiteSpace(pp); /* skip over any whitespace */
p = *pp;
@@ -121,12 +124,35 @@ static rsRetVal doGetInt(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *p
for(i = 0 ; *p && isdigit((int) *p) ; ++p)
i = i * 10 + *p - '0';
+ *pVal = i;
+ *pp = p;
+
+finalize_it:
+ return iRet;
+}
+
+
+/* Parse a number from the configuration line.
+ * rgerhards, 2007-07-31
+ */
+static rsRetVal doGetInt(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
+{
+ uchar *p;
+ DEFiRet;
+ size_t i;
+
+ assert(pp != NULL);
+ assert(*pp != NULL);
+
+ CHKiRet(parseIntVal(pp, &i));
+ p = *pp;
+
if(pSetHdlr == NULL) {
/* we should set value directly to var */
- *((int*)pVal) = i;
+ *((int*)pVal) = (int) i;
} else {
/* we set value via a set function */
- CHKiRet(pSetHdlr(pVal, i));
+ CHKiRet(pSetHdlr(pVal, (int) i));
}
*pp = p;
@@ -136,6 +162,57 @@ finalize_it:
}
+/* Parse a size from the configuration line. This is basically an integer
+ * syntax, but modifiers may be added after the integer (e.g. 1k to mean
+ * 1024). The size must immediately follow the number. Note that the
+ * param value must be size_t!
+ * rgerhards, 2008-01-09
+ */
+static rsRetVal doGetSize(uchar **pp, rsRetVal (*pSetHdlr)(void*, uid_t), void *pVal)
+{
+ DEFiRet;
+ size_t i;
+
+ assert(pp != NULL);
+ assert(*pp != NULL);
+
+ CHKiRet(parseIntVal(pp, &i));
+
+ /* we now check if the next character is one of our known modifiers.
+ * If so, we accept it as such. If not, we leave it alone. tera and
+ * above does not make any sense as that is above a 32-bit int value.
+ */
+ switch(**pp) {
+ /* traditional binary-based definitions */
+ case 'k': i *= 1024; ++(*pp); break;
+ case 'm': i *= 1024 * 1024; ++(*pp); break;
+ case 'g': i *= 1024 * 1024 * 1024; ++(*pp); break;
+ case 't': i *= (size_t) 1024 * 1024 * 1024 * 1024; ++(*pp); break; /* tera */
+ case 'p': i *= (size_t) 1024 * 1024 * 1024 * 1024 * 1024; ++(*pp); break; /* peta */
+ case 'e': i *= (size_t) 1024 * 1024 * 1024 * 1024 * 1024 * 1024; ++(*pp); break; /* exa */
+ /* and now the "new" 1000-based definitions */
+ case 'K': i *= 1000; ++(*pp); break;
+ case 'M': i *= 10000; ++(*pp); break;
+ case 'G': i *= 100000; ++(*pp); break;
+ case 'T': i *= 1000000; ++(*pp); break; /* tera */
+ case 'P': i *= 10000000; ++(*pp); break; /* peta */
+ case 'E': i *= 100000000; ++(*pp); break; /* exa */
+ }
+
+ /* done */
+ if(pSetHdlr == NULL) {
+ /* we should set value directly to var */
+ *((size_t*)pVal) = i;
+ } else {
+ /* we set value via a set function */
+ CHKiRet(pSetHdlr(pVal, i));
+ }
+
+finalize_it:
+ return iRet;
+}
+
+
/* Parse and interpet a $FileCreateMode and $umask line. This function
* pulls the creation mode and, if successful, stores it
* into the global variable so that the rest of rsyslogd
@@ -510,6 +587,9 @@ static rsRetVal cslchCallHdlr(cslCmdHdlr_t *pThis, uchar **ppConfLine)
case eCmdHdlrInt:
pHdlr = doGetInt;
break;
+ case eCmdHdlrSize:
+ pHdlr = doGetSize;
+ break;
case eCmdHdlrGetChar:
pHdlr = doGetChar;
break;