summaryrefslogtreecommitdiffstats
path: root/tcpsyslog.c
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-12-28 15:59:24 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-12-28 15:59:24 +0000
commitf67509d5707978f2acd0e335af58266afc04e372 (patch)
tree01b65c0647fadb25df0974da82d2a9d780662558 /tcpsyslog.c
parent1990c08536f3880053508ab6b60aab8cee9760ec (diff)
downloadrsyslog-f67509d5707978f2acd0e335af58266afc04e372.tar.gz
rsyslog-f67509d5707978f2acd0e335af58266afc04e372.tar.xz
rsyslog-f67509d5707978f2acd0e335af58266afc04e372.zip
omgssapi created
Diffstat (limited to 'tcpsyslog.c')
-rw-r--r--tcpsyslog.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/tcpsyslog.c b/tcpsyslog.c
index 27e1db2a..01655620 100644
--- a/tcpsyslog.c
+++ b/tcpsyslog.c
@@ -1019,6 +1019,59 @@ void TCPSessGSSDeinit(void) {
* CODE THAT SHALL GO INTO ITS OWN MODULE (SENDING) *
* ----------------------------------------------------------------- */
+/* Initialize TCP sockets (for sender)
+ * This is done once per selector line, if not yet initialized.
+ */
+int TCPSendCreateSocket(struct addrinfo *addrDest)
+{
+ int fd;
+ struct addrinfo *r;
+
+ r = addrDest;
+
+ while(r != NULL) {
+ fd = socket(r->ai_family, r->ai_socktype, r->ai_protocol);
+ if (fd != -1) {
+ /* We can not allow the TCP sender to block syslogd, at least
+ * not in a single-threaded design. That would cause rsyslogd to
+ * loose input messages - which obviously also would affect
+ * other selector lines, too. So we do set it to non-blocking and
+ * handle the situation ourselfs (by discarding messages). IF we run
+ * dual-threaded, however, the situation is different: in this case,
+ * the receivers and the selector line processing are only loosely
+ * coupled via a memory buffer. Now, I think, we can afford the extra
+ * wait time. Thus, we enable blocking mode for TCP if we compile with
+ * pthreads. -- rgerhards, 2005-10-25
+ * And now, we always run on multiple threads... -- rgerhards, 2007-12-20
+ */
+ if (connect (fd, r->ai_addr, r->ai_addrlen) != 0) {
+ if(errno == EINPROGRESS) {
+ /* this is normal - will complete later select */
+ return fd;
+ } else {
+ char errStr[1024];
+ dbgprintf("create tcp connection failed, reason %s",
+ strerror_r(errno, errStr, sizeof(errStr)));
+ }
+
+ }
+ else {
+ return fd;
+ }
+ close(fd);
+ }
+ else {
+ char errStr[1024];
+ dbgprintf("couldn't create send socket, reason %s", strerror_r(errno, errStr, sizeof(errStr)));
+ }
+ r = r->ai_next;
+ }
+
+ dbgprintf("no working socket could be obtained");
+
+ return -1;
+}
+
/* Build frame based on selected framing