summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRainer Gerhards <rgerhards@adiscon.com>2007-07-23 06:21:16 +0000
committerRainer Gerhards <rgerhards@adiscon.com>2007-07-23 06:21:16 +0000
commit8425445c2dd68d91bb62487032151f06d35c583a (patch)
tree92ef23fb997666d1b09ed65bb788c52dffc1c925
parent6b24fa20d4da8a57a2e34b1ca0c3159b93157e1e (diff)
downloadrsyslog-8425445c2dd68d91bb62487032151f06d35c583a.tar.gz
rsyslog-8425445c2dd68d91bb62487032151f06d35c583a.tar.xz
rsyslog-8425445c2dd68d91bb62487032151f06d35c583a.zip
simplified action calling using new interface Warning: this version has a
structure alignment issue in omusrmsg.c, I currently do not know why. I check in so that others can look at it.
-rw-r--r--omfile.c3
-rw-r--r--omfwd.c8
-rw-r--r--omfwd.h2
-rw-r--r--ommysql.c2
-rw-r--r--ommysql.h2
-rw-r--r--omusrmsg.c13
-rw-r--r--syslogd-types.h4
-rw-r--r--syslogd.c60
8 files changed, 41 insertions, 53 deletions
diff --git a/omfile.c b/omfile.c
index f2d7814a..7d41fc0a 100644
--- a/omfile.c
+++ b/omfile.c
@@ -38,7 +38,6 @@
#include <unistd.h>
#include <sys/file.h>
-//#include <sys/param.h>
#include "rsyslog.h"
#include "syslogd.h"
@@ -424,6 +423,8 @@ int doActionFile(selector_t *f)
{
assert(f != NULL);
+ dprintf(" (%s)\n", f->f_un.f_file.f_fname);
+printf("iovUsed address: %x, size %d\n",&f->f_iIovUsed, sizeof(selector_t));
/* f->f_file == -1 is an indicator that the we couldn't
* open the file at startup. For dynaFiles, this is ok,
* all others are doomed.
diff --git a/omfwd.c b/omfwd.c
index 04d5633d..037bc26f 100644
--- a/omfwd.c
+++ b/omfwd.c
@@ -63,7 +63,7 @@ static const char *sys_h_errlist[] = {
/* call the shell action
* returns 0 if it succeeds, something else otherwise
*/
-int doActionFwd(selector_t *f, time_t now)
+int doActionFwd(selector_t *f)
{
char *psz; /* temporary buffering */
register unsigned l;
@@ -78,7 +78,7 @@ int doActionFwd(selector_t *f, time_t now)
switch (f->f_type) {
case F_FORW_SUSP:
- fwd_suspend = time(NULL) - f->f_time;
+ fwd_suspend = time(NULL) - f->f_un.f_forw.ttSuspend;
if ( fwd_suspend >= INET_SUSPEND_TIME ) {
dprintf("\nForwarding suspension over, retrying FORW ");
f->f_type = F_FORW;
@@ -101,7 +101,7 @@ int doActionFwd(selector_t *f, time_t now)
case F_FORW_UNKN:
/* The remote address is not yet known and needs to be obtained */
dprintf(" %s\n", f->f_un.f_forw.f_hname);
- fwd_suspend = time(NULL) - f->f_time;
+ fwd_suspend = time(NULL) - f->f_un.f_forw.ttSuspend;
if(fwd_suspend >= INET_SUSPEND_TIME) {
dprintf("Forwarding suspension to unknown over, retrying\n");
memset(&hints, 0, sizeof(hints));
@@ -144,7 +144,7 @@ int doActionFwd(selector_t *f, time_t now)
if ( strcmp(getHOSTNAME(f->f_pMsg), LocalHostName) && NoHops )
dprintf("Not sending message to remote.\n");
else {
- f->f_time = now;
+ f->f_un.f_forw.ttSuspend = time(NULL);
psz = iovAsString(f);
l = f->f_iLenpsziov;
if (l > MAXLINE)
diff --git a/omfwd.h b/omfwd.h
index e89c7698..6735f6dd 100644
--- a/omfwd.h
+++ b/omfwd.h
@@ -26,7 +26,7 @@
/* prototypes */
-int doActionFwd(selector_t *f, time_t now);
+int doActionFwd(selector_t *f);
#endif /* #ifndef OMFWD_H_INCLUDED */
/*
diff --git a/ommysql.c b/ommysql.c
index a91f2209..34fead8b 100644
--- a/ommysql.c
+++ b/ommysql.c
@@ -259,7 +259,7 @@ void writeMySQL(register selector_t *f)
/* call the shell action
* returns 0 if it succeeds, something else otherwise
*/
-int doActionMySQL(selector_t *f, time_t now)
+int doActionMySQL(selector_t *f)
{
assert(f != NULL);
diff --git a/ommysql.h b/ommysql.h
index 685734db..af654b8c 100644
--- a/ommysql.h
+++ b/ommysql.h
@@ -36,7 +36,7 @@ void reInitMySQL(register selector_t *f);
int checkDBErrorState(register selector_t *f);
//void DBErrorHandler(register selector_t *f);
-int doActionMySQL(selector_t *f, time_t now);
+int doActionMySQL(selector_t *f);
#endif /* #ifdef WITH_DB */
#endif /* #ifndef OMMYSQL_H_INCLUDED */
diff --git a/omusrmsg.c b/omusrmsg.c
index 3ac974ac..f03a0806 100644
--- a/omusrmsg.c
+++ b/omusrmsg.c
@@ -120,6 +120,8 @@ static void wallmsg(register selector_t *f)
return;
iovCreate(f); /* init the iovec */
+printf("gen iIovUsed %d\n", f->f_iIovUsed);
+printf("iovUsed address: %x, size %d\n",&f->f_iIovUsed, sizeof(selector_t));
/* open the user login file */
setutent();
@@ -179,13 +181,20 @@ static void wallmsg(register selector_t *f)
(void) signal(SIGALRM, endtty);
(void) alarm(15);
/* open the terminal */
+//errno = 0;
ttyf = open(p, O_WRONLY|O_NOCTTY);
+printf("try tty '%s' open: %d\n", p, ttyf);
if (ttyf >= 0) {
+printf("tty open!\n");
struct stat statb;
if (fstat(ttyf, &statb) == 0 &&
- (statb.st_mode & S_IWRITE))
- (void) writev(ttyf, f->f_iov, f->f_iIovUsed);
+ (statb.st_mode & S_IWRITE)) {
+int written;
+ // (void) writev(ttyf, f->f_iov, f->f_iIovUsed);
+ written = writev(ttyf, f->f_iov, f->f_iIovUsed);
+printf("write tty %d bytes, iIovUsed %d\n", written, f->f_iIovUsed);
+ }
close(ttyf);
ttyf = -1;
}
diff --git a/syslogd-types.h b/syslogd-types.h
index f41e18b7..b565a964 100644
--- a/syslogd-types.h
+++ b/syslogd-types.h
@@ -134,6 +134,7 @@ struct syslogTime {
*/
struct filed {
struct filed *f_next; /* next in linked list */
+ int (*doAction)(struct filed *); /* method to call to perform an action */
short f_type; /* entry type, see below */
short f_file; /* file descriptor */
time_t f_time; /* time this was last written */
@@ -192,12 +193,13 @@ struct filed {
} status;
char *savedMsg;
int savedMsgLen; /* length of savedMsg in octets */
+ time_t ttSuspend; /* time selector was suspended */
# ifdef USE_PTHREADS
pthread_mutex_t mtxTCPSend;
# endif
} f_forw; /* forwarding address */
struct {
- char f_fname[MAXFNAME];/* file or template name (dispaly only) */
+ char f_fname[MAXFNAME];/* file or template name (display only) */
struct template *pTpl; /* pointer to template object */
char bDynamicName; /* 0 - static name, 1 - dynamic name (with properties) */
int fCreateMode; /* file creation mode for open() */
diff --git a/syslogd.c b/syslogd.c
index 8c1459f4..75d46465 100644
--- a/syslogd.c
+++ b/syslogd.c
@@ -2311,6 +2311,7 @@ static void processMsg(msg_t *pMsg)
*/
f = &consfile;
f->f_file = open(ctty, O_WRONLY|O_NOCTTY);
+ f->doAction = doActionFile;
if (f->f_file >= 0) {
untty();
@@ -2327,6 +2328,7 @@ static void processMsg(msg_t *pMsg)
memset(&emergfile, 0, sizeof(emergfile));
f = &emergfile;
emergfile.f_type = F_TTY;
+ emergfile.doAction = doActionFile;
strcpy(emergfile.f_un.f_file.f_fname, ttyname(0));
cflineSetTemplateAndIOV(&emergfile, " TradFmt");
f->f_file = open(ttyname(0), O_WRONLY|O_NOCTTY);
@@ -3213,9 +3215,11 @@ void iovCreate(selector_t *f)
f->f_iIovUsed = iIOVused;
-#if 0 /* debug aid */
+#if 1 /* debug aid */
{
int i;
+ printf("iovUsed address: %x, size %d\n",&f->f_iIovUsed, sizeof(selector_t));
+ printf("dumping iov:\n");
v = f->f_iov;
for(i = 0 ; i < iIOVused ; ++i, ++v) {
printf("iovCreate(%d), string '%s', mustbeFreed %d\n", i,
@@ -3281,46 +3285,10 @@ void fprintlog(register selector_t *f)
dprintf("Called fprintlog, logging to %s", TypeNames[f->f_type]);
- switch (f->f_type) {
- case F_UNUSED:
- f->f_time = now;
- dprintf("\n");
- break;
-
- case F_FORW_SUSP:
- case F_FORW_UNKN:
- case F_FORW:
- doActionFwd(f, now);
- break;
-
- case F_CONSOLE:
- case F_TTY:
- case F_FILE:
- case F_PIPE:
- printf(" (%s)\n", f->f_un.f_file.f_fname);
- f->f_time = now; /* we need this for message repeation processing */
- doActionFile(f);
- break;
-
- case F_USERS:
- case F_WALL:
- f->f_time = now;
- doActionUsrMsg(f);
- break;
-
-#ifdef WITH_DB
- case F_MYSQL:
- f->f_time = now;
- doActionMySQL(f, now);
- break;
-#endif
-
- case F_SHELL: /* shell support by bkalkbrenner 2005-09-20 */
- f->f_time = now;
- doActionShell(f);
- break;
-
- } /* switch */
+ f->f_time = now; /* we need this for message repeation processing TODO: why must it be global now? */
+ if(f->f_type != F_UNUSED) {
+ f->doAction(f); /* call configured action */
+ }
if (f->f_type != F_FORW_UNKN)
f->f_prevcount = 0;
@@ -4610,9 +4578,11 @@ static void cflineParseFileName(selector_t *f, uchar* p)
if(*p == '|') {
f->f_type = F_PIPE;
+ f->doAction = doActionFile;
++p;
} else {
f->f_type = F_FILE;
+ f->doAction = doActionFile;
}
pName = f->f_un.f_file.f_fname;
@@ -4664,6 +4634,7 @@ static void cflineParseOutchannel(selector_t *f, uchar* p)
* extend it...
*/
f->f_type = F_FILE;
+ f->doAction = doActionFile;
++p; /* skip '$' */
i = 0;
@@ -5307,10 +5278,11 @@ static rsRetVal cfline(char *line, register selector_t *f)
hints.ai_flags = AI_NUMERICSERV;
hints.ai_family = family;
hints.ai_socktype = f->f_un.f_forw.protocol == FORW_UDP ? SOCK_DGRAM : SOCK_STREAM;
+ f->doAction = doActionFwd;
if( (error = getaddrinfo(f->f_un.f_forw.f_hname, getFwdSyslogPt(f), &hints, &res)) != 0) {
f->f_type = F_FORW_UNKN;
f->f_prevcount = INET_RETRY_MAX;
- f->f_time = time(NULL);
+ f->f_un.f_forw.ttSuspend = time(NULL);
} else {
f->f_type = F_FORW;
f->f_un.f_forw.f_addr = res;
@@ -5436,6 +5408,7 @@ static rsRetVal cfline(char *line, register selector_t *f)
case '*':
dprintf ("write-all");
f->f_type = F_WALL;
+ f->doAction = doActionUsrMsg;
if(*(p+1) == ';') {
/* we have a template specifier! */
p += 2; /* eat "*;" */
@@ -5478,6 +5451,7 @@ static rsRetVal cfline(char *line, register selector_t *f)
"database functionality - ignored");
#else /* WITH_DB defined! */
f->f_type = F_MYSQL;
+ f->doAction = doActionMySQL;
p++;
/* Now we read the MySQL connection properties
@@ -5550,12 +5524,14 @@ static rsRetVal cfline(char *line, register selector_t *f)
cflineParseFileName(f, p);
if (f->f_type == F_FILE) {
f->f_type = F_SHELL;
+ f->doAction = doActionShell;
}
break;
default:
dprintf ("users: %s\n", p); /* ASP */
f->f_type = F_USERS;
+ f->doAction = doActionUsrMsg;
for (i = 0; i < MAXUNAMES && *p && *p != ';'; i++) {
for (q = p; *q && *q != ',' && *q != ';'; )
q++;