Oops. Code things so it actually works this time around...
-Erik
diff --git a/sysklogd/syslogd.c b/sysklogd/syslogd.c
index fc59225..aac37b1 100644
--- a/sysklogd/syslogd.c
+++ b/sysklogd/syslogd.c
@@ -129,6 +129,8 @@
perror_msg_and_die("semop[SMwdn]");
}
+#define MAXLINE 1024 /* maximum line length */
+
void ipcsyslog_cleanup(void){
printf("Exiting Syslogd!\n");
@@ -398,14 +400,10 @@
/* 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 @@
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 @@
/* Now log it */
logMessage (pri, line);
}
- RELEASE_CONFIG_BUFFER (tmpbuf);
return n_read;
}
@@ -555,21 +550,19 @@
--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 */