summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2005-07-20 14:40:41 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2005-07-20 14:40:41 +0000
commit1545ee4272a7667bb51ce58d20605f037cb751db (patch)
treee5c49f42bbdaea79fc8a234301f6d18e987cd080
parentabce3af3e1e6aa0896a986b674aa379f31719f6c (diff)
downloadrsyslog-1545ee4272a7667bb51ce58d20605f037cb751db.tar.gz
rsyslog-1545ee4272a7667bb51ce58d20605f037cb751db.tar.xz
rsyslog-1545ee4272a7667bb51ce58d20605f037cb751db.zip
useful tcp sender finished (at least it looks so, testing might reveal a
different view ;))
-rw-r--r--NEWS5
-rw-r--r--syslogd.c29
2 files changed, 32 insertions, 2 deletions
diff --git a/NEWS b/NEWS
index 49e2f97c..cc721dc8 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,10 @@
---------------------------------------------------------------------------
Version 0.9.4 (RGer), around 2005-07-20
+- finally added the TCP sender. It now supports non-blocking mode, no
+ longer disabling message reception during connect. As it is now, it
+ is usable in production. The code could be more sophisticated, but
+ I've kept it short in anticipation of the move to liblogging, which
+ will lead to the removal of the code just written ;)
- the "exiting on signal..." message still had the "syslogd" name in
it. Changed this to "rsyslogd", as we do not have a large user base
yet, this should pose no problem.
diff --git a/syslogd.c b/syslogd.c
index 3e521aae..0ba09577 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -437,6 +437,7 @@ struct filed {
TCP_SEND_CONNECTING = 1,
TCP_SEND_READY = 2
} status;
+ char *savedMsg;
} f_forw; /* forwarding address */
char f_fname[MAXFNAME];
} f_un;
@@ -974,7 +975,22 @@ int TCPSend(struct filed *f, char *msg)
}
dprintf("##sending '%s'\n", msg);
- if(f->f_un.f_forw.status != TCP_SEND_READY)
+ if(f->f_un.f_forw.status == TCP_SEND_CONNECTING) {
+ /* In this case, we save the buffer. If we have a
+ * system with few messages, that hopefully prevents
+ * message loss at all. However, we make no further attempts,
+ * just the first message is saved. So we only try this
+ * if there is not yet a saved message present.
+ * rgerhards 2005-07-20
+ */
+ if(f->f_un.f_forw.savedMsg == NULL) {
+ f->f_un.f_forw.savedMsg = malloc((len + 1) * sizeof(char));
+ if(f->f_un.f_forw.savedMsg == NULL)
+ return 0; /* nothing we can do... */
+ memcpy(f->f_un.f_forw.savedMsg, msg, len + 1);
+ return 0;
+ }
+ } else if(f->f_un.f_forw.status != TCP_SEND_READY)
/* This here is debatable. For the time being, we
* accept the loss of a single message (e.g. during
* connection setup in favour of not messing with
@@ -2402,7 +2418,7 @@ int main(argc, argv)
* scheduled to be replaced after the liblogging integration.
* rgerhards 2005-07-20
*/
- FD_ZERO(&writefds);
+ FD_ZERO(&writefds);
for (f = Files; f; f = f->f_next) {
if( (f->f_type == F_FORW)
&& (f->f_un.f_forw.protocol == FORW_TCP)
@@ -2489,6 +2505,15 @@ int main(argc, argv)
&& (FD_ISSET(f->f_file, &writefds))) {
dprintf("tcp send socket %d ready for writing.\n", f->f_file);
f->f_un.f_forw.status = TCP_SEND_READY;
+ /* Send stored message (if any) */
+ if(f->f_un.f_forw.savedMsg != NULL)
+ if(TCPSend(f, f->f_un.f_forw.savedMsg) != 0) {
+ /* error! */
+ f->f_type = F_FORW_SUSP;
+ errno = 0;
+ logerror("error forwarding via tcp, suspending...");
+ }
+ f->f_un.f_forw.savedMsg = NULL;
}
}
}