[590] in Zephyr_Bugs
Re: zephyr syslogd
daemon@ATHENA.MIT.EDU (ghudson@MIT.EDU)
Sun Jun 4 16:27:09 1995
From: ghudson@MIT.EDU
Date: Sun, 4 Jun 1995 16:26:56 -0400
To: David Langhorst <dirt@umich.edu>
Cc: bug-zephyr@MIT.EDU
In-Reply-To: "[589] in Zephyr_Bugs"
> allo. syslogd from the zephyr package (most recent snapshot) has the
> tendancy (actually it always does) to destroy dev/log under Solaris
> 2.3. has anyone that you know of had/fixed this problem? if not, i
> guess i'll fix it and send it on up...
I don't think the syslogd from the most recent zephyrd snapshot will
work on any platforms but SunOS. Certainly, it won't work under
Solaris, with the completely different STREAMS-based logging
interface.
Here are two sets of patches which you may find useful. The first
brings you in sync with the syslogd in the current zephyr source tree
(which gets syslogd working on NetBSD and probably most other
BSD-based platforms). The second set, written by John Hawkinson, adds
Solaris STREAMS-basd logging capability to the current zephyr source
tree.
The next Zephyr release should have the Solaris support in it.
*** 1.20 1995/02/15 14:52:03
--- syslogd.c 1995/05/18 17:48:17
***************
*** 89,94 ****
--- 89,97 ----
#ifdef POSIX
#include <termios.h>
#endif
+ #ifdef __NetBSD__ /* HAVE_PATHS_H */
+ #include <paths.h>
+ #endif
#include <zephyr/zephyr.h>
***************
*** 104,118 ****
#define sighandler_type int
#endif
#define CTTY "/dev/console"
char *LogName = "/dev/log";
! #ifdef COMPAT42
! char *ConfFile = "/etc/nsyslog.conf";
! char *PidFile = "/etc/nsyslog.pid";
! #else /* !COMPAT42 */
! char *ConfFile = "/etc/syslog.conf";
! char *PidFile = "/etc/syslog.pid";
! #endif /* COMPAT42 */
char ctty[] = CTTY;
#define FDMASK(fd) (1 << (fd))
--- 107,128 ----
#define sighandler_type int
#endif
+ #ifdef _PATH_VARRUN
+ #define PIDDIR _PATH_VARRUN
+ #else
+ #define PIDDIR "/etc/"
+ #endif
+
+ #ifdef COMPAT42
+ #define COMPAT_PREFIX "n"
+ #else
+ #define COMPAT_PREFIX ""
+ #endif
+
#define CTTY "/dev/console"
char *LogName = "/dev/log";
! char *ConfFile = "/etc/" COMPAT_PREFIX "syslog.conf";
! char *PidFile = PIDDIR COMPAT_PREFIX "syslog.pid";
char ctty[] = CTTY;
#define FDMASK(fd) (1 << (fd))
***************
*** 243,251 ****
"lpr", LOG_LPR,
"news", LOG_NEWS,
"uucp", LOG_UUCP,
! "reserved", -1,
! "reserved", -1,
! "reserved", -1,
"reserved", -1,
"reserved", -1,
"reserved", -1,
--- 253,261 ----
"lpr", LOG_LPR,
"news", LOG_NEWS,
"uucp", LOG_UUCP,
! "cron", LOG_CRON,
! "authpriv", LOG_AUTHPRIV,
! "ftp", LOG_FTP,
"reserved", -1,
"reserved", -1,
"reserved", -1,
***************
*** 403,411 ****
sunx.sun_family = AF_UNIX;
(void) strncpy(sunx.sun_path, LogName, sizeof sunx.sun_path);
funix = socket(AF_UNIX, SOCK_DGRAM, 0);
! if (funix < 0 || bind(funix, (struct sockaddr *) &sunx,
! sizeof(sunx.sun_len)+sizeof(sunx.sun_family)
! +strlen(sunx.sun_path)) < 0 ||
chmod(LogName, 0666) < 0) {
(void) sprintf(line, "cannot create %s", LogName);
logerror(line);
--- 413,420 ----
sunx.sun_family = AF_UNIX;
(void) strncpy(sunx.sun_path, LogName, sizeof sunx.sun_path);
funix = socket(AF_UNIX, SOCK_DGRAM, 0);
! if (funix < 0 ||
! bind(funix, (struct sockaddr *) &sunx, sizeof(sunx)) < 0) ||
chmod(LogName, 0666) < 0) {
(void) sprintf(line, "cannot create %s", LogName);
logerror(line);
Subject: Solaris patches for zephyring syslogd
Date: Wed, 10 May 95 21:05:39 -0400
To: bug-zephyr@MIT.EDU
From: John Hawkinson <jhawk@MIT.EDU>
Attached are my patches for the zephyring syslogd
under Solaris, along with text intended for the
Change/RCS log.
--jhawk
=============================================================================
These patches add support for the Solaris-style STREAMS-based /dev/log
interface to the Zephyr syslogd.
The relevent changes are #ifdef'd on STREAMS_LOG_DRIVER, which in
turn is defined if SOLARIS is defined.
Use of streams requires that poll() be used rather than select(),
so there are some crappy #ifdef's littered throughout there.
It seems nonobvious how to divide them up in a more manageable
fashion, so it's left as is.
This code assumes that NLOGARGS will be three, and #error's if
that's not the case. This is due to a bogosity in the log(7)
specification (where the /dev/log interface is documented) which
specifies that it returns NLOGARGS words which much be *printf()'d,
which is not possible to do in a portable fashion without either:
1) a portable interface to the stdarg back end
2) preprocessor and sed magic
Since I chose to avoid the latter, and the former does not
exist, this restriction is in place.
Some other notes:
* /dev/klog is not supported in this model (doesn't exist).
* There are two other types of logging, I_ERRLOG and I_TRCLOG. It's
not clear to me exactly what they're good for, but they provide
far more information than is normally availabel through syslogs
(largely stats and information from kernel modules, I believe).
* unlink()-ing /dev/log (as syslogd normally does) is a bad idea
under Solaris, so don't do it :-). If you do this by accident, you
can remake it by running /usr/sbin/devlinks.
=============================================================================
*** 1.1 1995/05/06 07:05:57
--- /afs/sipb/project/foo-server/common/src/syslogd/syslogd.c 1995/05/10 20:48:48
***************
*** 21,26 ****
--- 21,27 ----
All rights reserved.\n";
static char sccsid[] = "@(#)syslogd.c 5.24 (Berkeley) 6/18/88";
+ static char rcsid[] = "$Id: syslogd.c,v 1.5 1995/05/10 20:48:48 jhawk Exp $";
#endif /* not lint */
/*
***************
*** 55,69 ****
--- 56,73 ----
#ifdef SOLARIS
#define MSG_BSIZE BUFSIZ
+ #define STREAMS_LOG_DRIVER
#endif
#include <stdio.h>
#include <sys/types.h>
#include <time.h>
+
#ifdef _IBMR2
#include <sys/select.h>
#include <spc.h> /* For support of the SRC system */
#endif
+
#include <utmp.h>
#include <ctype.h>
#include <string.h>
***************
*** 77,91 ****
--- 81,108 ----
#include <sys/wait.h>
#include <sys/socket.h>
#include <sys/file.h>
+
#ifndef COMPAT42
#include <sys/msgbuf.h>
#endif
+
+
#include <sys/uio.h>
#include <sys/un.h>
#include <sys/time.h>
#include <sys/resource.h>
#include <sys/signal.h>
#include <netdb.h>
+
+ #ifdef STREAMS_LOG_DRIVER
+ #include <sys/stream.h>
+ #include <sys/strlog.h>
+ #include <sys/log.h>
+
+ #include <poll.h>
+ #include <stropts.h>
+ #endif
+
#ifdef POSIX
#include <termios.h>
#endif
***************
*** 408,413 ****
--- 425,432 ----
(void) signal(SIGALRM, domark);
#endif
(void) alarm(TIMERINTVL);
+
+ #ifndef STREAMS_LOG_DRIVER
(void) unlink(LogName);
sunx.sun_family = AF_UNIX;
***************
*** 421,426 ****
--- 440,466 ----
dprintf("cannot create %s (%d)\n", LogName, errno);
die(0);
}
+ #else /* STREAMS_LOG_DRIVER */
+ if ((funix=open(LogName, O_RDONLY)) < 0) {
+ sprintf(line, "cannot open %s", LogName);
+ logerror(line);
+ dprintf("cannot open %s (%d)\n", LogName, errno);
+ die(0);
+ }
+ {
+ struct strioctl ioc;
+ ioc.ic_cmd = I_CONSLOG;
+ ioc.ic_timout = 0; /* 15 seconds default */
+ ioc.ic_len = 0; ioc.ic_dp = NULL;
+ if (ioctl(funix, I_STR, &ioc) < 0) {
+ sprintf(line, "cannot setup STREAMS logging on %s", LogName);
+ logerror(line);
+ dprintf("cannot setup STREAMS logging on %s (%d)", LogName,
+ errno);
+ die(0);
+ }
+ }
+ #endif /* STREAMS_LOG_DRIVER */
finet = socket(AF_INET, SOCK_DGRAM, 0);
if (finet >= 0) {
struct servent *sp;
***************
*** 447,457 ****
}
#endif /* COMPAT42 */
}
! #ifdef COMPAT42
InetInuse = 1;
inetm = 0;
klogm = 0;
! #else
if ((fklog = open("/dev/klog", O_RDONLY)) >= 0)
klogm = FDMASK(fklog);
else {
--- 487,499 ----
}
#endif /* COMPAT42 */
}
! #if defined(COMPAT42)
InetInuse = 1;
inetm = 0;
klogm = 0;
! #elif defined(STREAMS_LOG_DRIVER)
! klogm = 0;
! #else /* !COMPAT42, !STREAMS_LOG_DRIVER */
if ((fklog = open("/dev/klog", O_RDONLY)) >= 0)
klogm = FDMASK(fklog);
else {
***************
*** 485,493 ****
(void) signal(SIGHUP, init);
#endif
for (;;) {
! int nfds, readfds = FDMASK(funix) | inetm | klogm;
#ifdef _AIX
if (using_src)
readfds |= FDMASK(src_fd);
--- 527,556 ----
(void) signal(SIGHUP, init);
#endif
+ #ifndef STREAMS_LOG_DRIVER
+ dprintf("fdmasks: funix=%d, inetm=%d, klogm=%d\n",
+ FDMASK(funix), inetm, klogm);
+ #endif
+
for (;;) {
! int nfds;
! #ifdef STREAMS_LOG_DRIVER
! struct pollfd readfds[2] = {
! { funix, POLLIN | POLLPRI, 0 },
! { finet, POLLIN | POLLPRI, 0 } };
! # define POLLFD_unix 0
! # define POLLFD_inet 1
!
! errno = 0; dprintf("readfds = {(%d,%#x),(%d,%#x)}\n",
! readfds[POLLFD_unix].fd,
! readfds[POLLFD_unix].revents,
! readfds[POLLFD_inet].fd,
! readfds[POLLFD_inet].revents);
+ nfds = poll(readfds, 2, INFTIM);
+
+ #else /* STREAMS_LOG_DRIVER */
+ int readfds = FDMASK(funix) | inetm | klogm;
#ifdef _AIX
if (using_src)
readfds |= FDMASK(src_fd);
***************
*** 496,508 ****
dprintf("readfds = %#x\n", readfds);
nfds = select(20, (fd_set *) &readfds, (fd_set *) NULL,
(fd_set *) NULL, (struct timeval *) NULL);
if (nfds == 0)
continue;
if (nfds < 0) {
if (errno != EINTR)
! logerror("select");
continue;
}
dprintf("got a message (%d, %#x)\n", nfds, readfds);
if (readfds & klogm) {
i = read(fklog, line, sizeof(line) - 1);
--- 559,619 ----
dprintf("readfds = %#x\n", readfds);
nfds = select(20, (fd_set *) &readfds, (fd_set *) NULL,
(fd_set *) NULL, (struct timeval *) NULL);
+ dprintf("got a message (%d, %#x)\n", nfds, readfds);
+ #endif /* STREAMS_LOG_DRIVER */
if (nfds == 0)
continue;
if (nfds < 0) {
if (errno != EINTR)
! #ifdef STREAMS_LOG_DRIVER
! logerror("poll");
! #else
! logerror("select");
! #endif
continue;
}
+ #ifdef STREAMS_LOG_DRIVER
+ dprintf("got a message {(%d, %#x), (%d, %#x)}\n",
+ readfds[POLLFD_unix].fd, readfds[0].revents,
+ readfds[POLLFD_inet].fd, readfds[1].revents);
+ if (readfds[POLLFD_unix].revents & (POLLIN|POLLPRI)) {
+ struct log_ctl logctl;
+ char datbuf[BUFSIZ];
+ struct strbuf dat = { (sizeof(int)*2+sizeof(datbuf)),
+ 0, datbuf };
+ struct strbuf ctl = {
+ (sizeof(int)*2+sizeof(logctl)), 0, (char*)&logctl };
+ int flags = 0;
+
+ i = getmsg(funix, &ctl, &dat, &flags);
+ if ((i==0)) {
+ #if (NLOGARGS != 3)
+ #error This section of code assumes that NLOGARGS is 3. If that's not the case, this needs to be editted by hand. Sorry, but sed magic was too much for me.
+ #else
+ {
+ char null[] = "", *p;
+ char *logargs[NLOGARGS] = { null, null, null };
+
+ logargs[0]=dat.buf;
+ p=memchr(logargs[0], 0, sizeof(dat.buf)); /* XXX */
+ if (p != NULL)
+ logargs[1]=p++;
+ p=memchr(logargs[1], 0, sizeof(dat.buf)); /* XXX */
+ if (p != NULL)
+ logargs[2]=p++;
+ sprintf(line, logargs[0], logargs[1], logargs[2]);
+ }
+ #endif /* NLOGARGS != 3 */
+ line[strlen(line)-1]=0;
+ logmsg(logctl.pri, line, LocalHostName, 0);
+ } else if (i < 0 && errno != EINTR) {
+ logerror("getmsg() unix");
+ } else if (i > 0) {
+ sprintf(line, "getmsg() > 1 (%X)", i);
+ logerror(line);
+ }
+ }
+ #else /* STREAMS_LOG_DRIVER */
dprintf("got a message (%d, %#x)\n", nfds, readfds);
if (readfds & klogm) {
i = read(fklog, line, sizeof(line) - 1);
***************
*** 524,531 ****
printline(LocalHostName, line);
} else if (i < 0 && errno != EINTR)
logerror("recvfrom unix");
! }
if (readfds & inetm) {
len = sizeof frominet;
i = recvfrom(finet, line, MAXLINE, 0, &frominet, &len);
if (i > 0) {
--- 635,647 ----
printline(LocalHostName, line);
} else if (i < 0 && errno != EINTR)
logerror("recvfrom unix");
! }
! #endif /* STREAMS_LOG_DRIVER */
! #ifdef STREAMS_LOG_DRIVER
! if (readfds[POLLFD_inet].revents & (POLLIN|POLLPRI)) {
! #else
if (readfds & inetm) {
+ #endif
len = sizeof frominet;
i = recvfrom(finet, line, MAXLINE, 0, &frominet, &len);
if (i > 0) {
***************
*** 545,555 ****
&len);
dprintf("finished recvfrom, %d\n",i);
}
! /* if (i > 0) {
handle_src(srcreq);
} else if (i < 0 && errno != EINTR)
logerror("recvfrom src");
! } */
#endif /* _AIX */
}
}
--- 661,673 ----
&len);
dprintf("finished recvfrom, %d\n",i);
}
! #ifdef 0
! if (i > 0) {
handle_src(srcreq);
} else if (i < 0 && errno != EINTR)
logerror("recvfrom src");
! }
! #endif /* 0 */
#endif /* _AIX */
}
}
***************
*** 1182,1188 ****
--- 1300,1308 ----
errno = 0;
logerror(buf);
}
+ #ifndef STREAMS_LOG_DRIVER
(void) unlink(LogName);
+ #endif
exit(0);
}