summaryrefslogtreecommitdiffstats
path: root/tools/omfile.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/omfile.c')
-rw-r--r--tools/omfile.c44
1 files changed, 38 insertions, 6 deletions
diff --git a/tools/omfile.c b/tools/omfile.c
index d9dce4f9..91f9d64a 100644
--- a/tools/omfile.c
+++ b/tools/omfile.c
@@ -48,10 +48,13 @@
#include <libgen.h>
#include <unistd.h>
#include <sys/file.h>
-
#ifdef OS_SOLARIS
# include <fcntl.h>
#endif
+#ifdef HAVE_ATOMIC_BUILTINS
+# include <pthread.h>
+#endif
+
#include "conf.h"
#include "syslogd-types.h"
@@ -89,12 +92,33 @@ static uint64 clockFileAccess = 0;
static unsigned clockFileAccess = 0;
#endif
/* and the "tick" function */
+#ifdef HAVE_ATOMIC_BUILTINS
static inline uint64
getClockFileAccess(void)
{
return ATOMIC_INC_AND_FETCH(clockFileAccess);
}
-
+#else
+/* if we do not have atomics, we need to guard this via a mutex.
+ * the reason is that otherwise cache lookups may fail. That function
+ * requires the highest current value, and we can not provide that
+ * without using atomic instructions and mutexes.
+ * rgerhards, 2010-03-05
+ */
+static pthread_mutex_t mutClock;
+static uint64
+getClockFileAccess(void)
+{
+ uint64 retVal;
+
+ BEGINfunc
+ d_pthread_mutex_lock(&mutClock);
+ retVal = ++clockFileAccess;
+ d_pthread_mutex_unlock(&mutClock);
+ ENDfunc
+ return retVal;
+}
+#endif /* #ifdef HAVE_ATOMIC_BUILTINS */
/* The following structure is a dynafile name cache entry.
*/
@@ -125,7 +149,7 @@ static uid_t dirGID; /* GID to be used for newly created directories */
static int bCreateDirs = 1;/* auto-create directories for dynaFiles: 0 - no, 1 - yes */
static int bEnableSync = 0;/* enable syncing of files (no dash in front of pathname in conf): 0 - no, 1 - yes */
static int iZipLevel = 0; /* zip compression mode (0..9 as usual) */
-static bool bFlushOnTXEnd = FLUSHONTX_DFLT;/* flush write buffers when transaction has ended? */
+static sbool bFlushOnTXEnd = FLUSHONTX_DFLT;/* flush write buffers when transaction has ended? */
static int64 iIOBufSize = IOBUF_DFLT_SIZE; /* size of an io buffer */
static int iFlushInterval = FLUSH_INTRVL_DFLT; /* how often flush the output buffer on inactivity? */
static int bUseAsyncWriter = USE_ASYNCWRITER_DFLT; /* should we enable asynchronous writing? */
@@ -142,7 +166,7 @@ typedef struct _instanceData {
int fDirCreateMode; /* creation mode for mkdir() */
int bCreateDirs; /* auto-create directories? */
int bSyncFile; /* should the file by sync()'ed? 1- yes, 0- no */
- bool bForceChown; /* force chown() on existing files? */
+ sbool bForceChown; /* force chown() on existing files? */
uid_t fileUID; /* IDs for creation */
uid_t dirUID;
gid_t fileGID;
@@ -161,8 +185,8 @@ typedef struct _instanceData {
int iZipLevel; /* zip mode to use for this selector */
int iIOBufSize; /* size of associated io buffer */
int iFlushInterval; /* how fast flush buffer on inactivity? */
- bool bFlushOnTXEnd; /* flush write buffers when transaction has ended? */
- bool bUseAsyncWriter; /* use async stream writer? */
+ sbool bFlushOnTXEnd; /* flush write buffers when transaction has ended? */
+ sbool bUseAsyncWriter; /* use async stream writer? */
} instanceData;
@@ -854,6 +878,9 @@ CODESTARTmodExit
objRelease(errmsg, CORE_COMPONENT);
objRelease(strm, CORE_COMPONENT);
free(pszFileDfltTplName);
+# ifndef HAVE_ATOMIC_BUILTINS
+ pthread_mutex_destroy(&mutClock);
+# endif
ENDmodExit
@@ -871,6 +898,11 @@ CODESTARTmodInit
CODEmodInit_QueryRegCFSLineHdlr
CHKiRet(objUse(errmsg, CORE_COMPONENT));
CHKiRet(objUse(strm, CORE_COMPONENT));
+
+# ifndef HAVE_ATOMIC_BUILTINS
+ pthread_mutex_init(&mutClock, NULL);
+# endif
+
INITChkCoreFeature(bCoreSupportsBatching, CORE_FEATURE_BATCHING);
DBGPRINTF("omfile: %susing transactional output interface.\n", bCoreSupportsBatching ? "" : "not ");
CHKiRet(omsdRegCFSLineHdlr((uchar *)"dynafilecachesize", 0, eCmdHdlrInt, (void*) setDynaFileCacheSize, NULL, STD_LOADABLE_MODULE_ID));