From 74b007f7cc1da527ee38be5c60e51d9882c6838a Mon Sep 17 00:00:00 2001 From: Eric Andersen Date: Mon, 5 Aug 2002 11:56:25 +0000 Subject: [PATCH] Oops. Code things so it actually works this time around... -Erik --- sysklogd/syslogd.c | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c index fc5922562..aac37b11e 100644 --- a/sysklogd/syslogd.c +++ b/sysklogd/syslogd.c @@ -129,6 +129,8 @@ static inline void sem_down(int semid) perror_msg_and_die("semop[SMwdn]"); } +#define MAXLINE 1024 /* maximum line length */ + void ipcsyslog_cleanup(void){ printf("Exiting Syslogd!\n"); @@ -398,14 +400,10 @@ static void domark(int sig) /* This must be a #define, since when DODEBUG and BUFFERS_GO_IN_BSS are * enabled, we otherwise get a "storage size isn't constant error. */ #define BUFSIZE 1023 -static int serveConnection (int conn) +static int serveConnection (char* tmpbuf, int n_read) { - RESERVE_CONFIG_BUFFER(tmpbuf, BUFSIZE + 1); - int n_read; char *p = tmpbuf; - n_read = read (conn, tmpbuf, BUFSIZE ); - while (p < tmpbuf + n_read) { int pri = (LOG_USER | LOG_NOTICE); @@ -415,8 +413,6 @@ static int serveConnection (int conn) char *q = line; - tmpbuf[ n_read - 1 ] = '\0'; - while (p && (c = *p) && q < &line[ sizeof (line) - 1 ]) { if ((c == '<') && !gotpri && isdigit(p[1])) { /* Parse the magic priority number. */ @@ -443,7 +439,6 @@ static int serveConnection (int conn) /* Now log it */ logMessage (pri, line); } - RELEASE_CONFIG_BUFFER (tmpbuf); return n_read; } @@ -555,21 +550,19 @@ static void doSyslogd (void) --n_ready; if (fd == sock_fd) { - int conn; + int i; + RESERVE_CONFIG_BUFFER(tmpbuf, BUFSIZE + 1); - //printf("New Connection request.\n"); - if ((conn = accept (sock_fd, (struct sockaddr *) &sunx, &addrLength)) < 0) { - perror_msg_and_die ("accept error"); + memset(tmpbuf, '\0', BUFSIZE+1); + if ( (i = recv(fd, tmpbuf, MAXLINE - 2, 0)) > 0) { + if ( serveConnection(tmpbuf, i) <= 0 ) { + close (fd); + FD_CLR(fd, &fds); + } + } else { + perror_msg_and_die ("UNIX socket error"); } - - FD_SET(conn, &fds); - //printf("conn: %i, set_size: %i\n",conn,FD_SETSIZE); - } else { - //printf("Serving connection: %i\n",fd); - if ( serveConnection(fd) <= 0 ) { - close (fd); - FD_CLR(fd, &fds); - } + RELEASE_CONFIG_BUFFER (tmpbuf); } /* fd == sock_fd */ }/* FD_ISSET() */ }/* for */