summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2005-10-24 13:40:17 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2005-10-24 13:40:17 +0000
commit673f20015f0f1351585b8c0c4bb256dc188c72e8 (patch)
tree16b55dfb2f755bffc6d9be4e20214a9ebaafdebe
parente5507768177bd04231c44d6671851f98b15a1622 (diff)
downloadrsyslog-673f20015f0f1351585b8c0c4bb256dc188c72e8.tar.gz
rsyslog-673f20015f0f1351585b8c0c4bb256dc188c72e8.tar.xz
rsyslog-673f20015f0f1351585b8c0c4bb256dc188c72e8.zip
some test implementation for mutexes. now testing on different target
platforms
-rw-r--r--syslogd.c43
1 files changed, 39 insertions, 4 deletions
diff --git a/syslogd.c b/syslogd.c
index 40b3f524..02504a7f 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -539,6 +539,9 @@ struct filed {
TCP_SEND_READY = 2
} status;
char *savedMsg;
+# ifdef USE_PTHREADS
+ pthread_mutex_t mtxTCPSend;
+# endif
} f_forw; /* forwarding address */
char f_fname[MAXFNAME];
} f_un;
@@ -1254,12 +1257,22 @@ static void TCPSessDataRcvd(int iTCPSess, char *pData, int iLen)
static void TCPSendSetStatus(struct filed *f, enum TCPSendStatus iNewState)
{
assert(f != NULL);
+ assert(f->f_type == F_FORW);
+ assert(f->f_un.f_forw.protocol == FORW_TCP);
assert( (iNewState == TCP_SEND_NOTCONNECTED)
|| (iNewState == TCP_SEND_CONNECTING)
|| (iNewState == TCP_SEND_READY));
- /*guard the section below by a mutex*/
+ /* there can potentially be a race condition, so guard by mutex */
+# ifdef USE_PTHREADS
+ pthread_mutex_lock(&f->f_un.f_forw.mtxTCPSend);
+dprintf("SetStats aquired mutex\n");
+# endif
f->f_un.f_forw.status = iNewState;
+# ifdef USE_PTHREADS
+ pthread_mutex_unlock(&f->f_un.f_forw.mtxTCPSend);
+dprintf("SetStats freed mutex\n");
+# endif
}
@@ -1270,9 +1283,17 @@ static enum TCPSendStatus TCPSendGetStatus(struct filed *f)
{
enum TCPSendStatus eState;
assert(f != NULL);
+ assert(f->f_type == F_FORW);
+ assert(f->f_un.f_forw.protocol == FORW_TCP);
- /*guard the section below by a mutex*/
+ /* there can potentially be a race condition, so guard by mutex */
+# ifdef USE_PTHREADS
+ pthread_mutex_lock(&f->f_un.f_forw.mtxTCPSend);
+# endif
eState = f->f_un.f_forw.status;
+# ifdef USE_PTHREADS
+ pthread_mutex_unlock(&f->f_un.f_forw.mtxTCPSend);
+# endif
return eState;
}
@@ -5446,12 +5467,21 @@ static void init()
case F_CONSOLE:
(void) close(f->f_file);
break;
-#ifdef WITH_DB
+# ifdef WITH_DB
case F_MYSQL:
closeMySQL(f);
break;
-#endif
+# endif
+ }
+# ifdef USE_PTHREADS
+ /* delete any mutex objects, if present */
+ if( ( (f->f_type == F_FORW_SUSP)
+ || (f->f_type == F_FORW)
+ || (f->f_type == F_FORW_UNKN) )
+ && (f->f_un.f_forw.protocol == FORW_TCP)) {
+ pthread_mutex_destroy(&f->f_un.f_forw.mtxTCPSend);
}
+# endif
/* done with this entry, we now need to delete itself */
f = f->f_next;
free(f);
@@ -6346,6 +6376,11 @@ static rsRetVal cfline(char *line, register struct filed *f)
if(*p == '@') { /* indicator for TCP! */
f->f_un.f_forw.protocol = FORW_TCP;
++p; /* eat this '@', too */
+ /* in this case, we also need a mutex... */
+# ifdef USE_PTHREADS
+ pthread_mutex_init(&f->f_un.f_forw.mtxTCPSend, 0);
+dprintf("initializing mutex!\n");
+# endif
} else {
f->f_un.f_forw.protocol = FORW_UDP;
}