summaryrefslogtreecommitdiffstats
path: root/runtime/glbl.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2011-06-15 12:20:12 +0200
committerRainer Gerhards <rgerhards@adiscon.com>2011-06-15 12:20:12 +0200
commit41d8672524b93aaf7b7835336ac9b92428b90fed (patch)
treee24d93da0c0b3d61490ddede5fdba7fb2e31f29b /runtime/glbl.c
parent28af40670e9dc1a85a24dfcbb093ddc1171e151f (diff)
downloadrsyslog-41d8672524b93aaf7b7835336ac9b92428b90fed.tar.gz
rsyslog-41d8672524b93aaf7b7835336ac9b92428b90fed.tar.xz
rsyslog-41d8672524b93aaf7b7835336ac9b92428b90fed.zip
bugfix/improvement:$WorkDirectory now gracefully handles trailing slashes
Diffstat (limited to 'runtime/glbl.c')
-rw-r--r--runtime/glbl.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/runtime/glbl.c b/runtime/glbl.c
index ec4992cf..dea5a17b 100644
--- a/runtime/glbl.c
+++ b/runtime/glbl.c
@@ -159,8 +159,29 @@ static void SetGlobalInputTermination(void)
*/
static rsRetVal setWorkDir(void __attribute__((unused)) *pVal, uchar *pNewVal)
{
- DEFiRet;
+ size_t lenDir;
+ int i;
struct stat sb;
+ DEFiRet;
+
+ /* remove trailing slashes */
+ lenDir = ustrlen(pNewVal);
+ i = lenDir - 1;
+ while(i > 0 && pNewVal[i] == '/') {
+ --i;
+ }
+
+ if(i < 0) {
+ errmsg.LogError(0, RS_RET_ERR_WRKDIR, "$WorkDirectory: empty value "
+ "- directive ignored");
+ ABORT_FINALIZE(RS_RET_ERR_WRKDIR);
+ }
+
+ if(i != (int) lenDir - 1) {
+ pNewVal[i+1] = '\0';
+ errmsg.LogError(0, RS_RET_WRN_WRKDIR, "$WorkDirectory: trailing slashes "
+ "removed, new value is '%s'", pNewVal);
+ }
if(stat((char*) pNewVal, &sb) != 0) {
errmsg.LogError(0, RS_RET_ERR_WRKDIR, "$WorkDirectory: %s can not be "