/*
- * Copyright (c) 1983, 1988 Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1983, 1988, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
*
* %sccs.include.redist.c%
*/
#ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1983, 1988 Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1983, 1988, 1993, 1994\n\
+ The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)syslogd.c 5.52 (Berkeley) %G%";
+static char sccsid[] = "@(#)syslogd.c 8.3 (Berkeley) %G%";
#endif /* not lint */
/*
int MarkInterval = 20 * 60; /* interval between marks in seconds */
int MarkSeq = 0; /* mark sequence number */
-void cfline __P((char *, struct filed *));
-char *cvthname __P((struct sockaddr_in *));
-int decode __P((const char *, CODE *));
-void die __P((int));
-void domark __P((int));
-void fprintlog __P((struct filed *, int, char *));
-void init __P((int));
-void logerror __P((char *));
-void logmsg __P((int, char *, char *, int));
-void printline __P((char *, char *));
-void printsys __P((char *));
-void reapchild __P((int));
-char *ttymsg __P((struct iovec *, int, char *, int));
-void usage __P((void));
-void wallmsg __P((struct filed *, struct iovec *));
+void cfline __P((char *, struct filed *));
+char *cvthname __P((struct sockaddr_in *));
+int decode __P((const char *, CODE *));
+void die __P((int));
+void domark __P((int));
+void fprintlog __P((struct filed *, int, char *));
+void init __P((int));
+void logerror __P((char *));
+void logmsg __P((int, char *, char *, int));
+void printline __P((char *, char *));
+void printsys __P((char *));
+void reapchild __P((int));
+char *ttymsg __P((struct iovec *, int, char *, int));
+void usage __P((void));
+void wallmsg __P((struct filed *, struct iovec *));
int
main(argc, argv)
int argc;
char *argv[];
{
- register int i;
- register char *p;
- int funix, inetm, fklog, klogm, len;
+ int ch, funix, i, inetm, fklog, klogm, len;
struct sockaddr_un sunx, fromunix;
struct sockaddr_in sin, frominet;
FILE *fp;
- int ch;
- char line[MSG_BSIZE + 1];
+ char *p, line[MSG_BSIZE + 1];
while ((ch = getopt(argc, argv, "df:m:p:")) != EOF)
- switch((char)ch) {
+ switch(ch) {
case 'd': /* debug */
Debug++;
break;
default:
usage();
}
- if (argc -= optind)
+ if ((argc -= optind) != 0)
usage();
if (!Debug)
consfile.f_type = F_CONSOLE;
(void)strcpy(consfile.f_un.f_fname, ctty);
- (void)gethostname(LocalHostName, sizeof LocalHostName);
- if (p = index(LocalHostName, '.')) {
+ (void)gethostname(LocalHostName, sizeof(LocalHostName));
+ if ((p = strchr(LocalHostName, '.')) != NULL) {
*p++ = '\0';
LocalDomain = p;
} else
#ifndef SUN_LEN
#define SUN_LEN(unp) (strlen((unp)->sun_path) + 2)
#endif
- bzero((char *)&sunx, sizeof(sunx));
+ memset(&sunx, 0, sizeof(sunx));
sunx.sun_family = AF_UNIX;
- (void)strncpy(sunx.sun_path, LogName, sizeof sunx.sun_path);
+ (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, SUN_LEN(&sunx)) < 0 ||
logerror("syslog/udp: unknown service");
die(0);
}
- bzero((char *)&sin, sizeof(sin));
+ memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_port = LogPort = sp->s_port;
if (bind(finet, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
for (;;) {
int nfds, readfds = FDMASK(funix) | inetm | klogm;
- errno = 0;
dprintf("readfds = %#x\n", readfds);
nfds = select(20, (fd_set *)&readfds, (fd_set *)NULL,
(fd_set *)NULL, (struct timeval *)NULL);
}
}
if (readfds & FDMASK(funix)) {
- len = sizeof fromunix;
+ len = sizeof(fromunix);
i = recvfrom(funix, line, MAXLINE, 0,
(struct sockaddr *)&fromunix, &len);
if (i > 0) {
logerror("recvfrom unix");
}
if (readfds & inetm) {
- len = sizeof frominet;
+ len = sizeof(frominet);
i = recvfrom(finet, line, MAXLINE, 0,
(struct sockaddr *)&frominet, &len);
if (i > 0) {
void
usage()
{
+
(void)fprintf(stderr,
"usage: syslogd [-f conffile] [-m markinterval] [-p logpath]\n");
exit(1);
char *hname;
char *msg;
{
- register char *p, *q;
- register int c;
- char line[MAXLINE + 1];
- int pri;
+ int c, pri;
+ char *p, *q, line[MAXLINE + 1];
/* test for special codes */
pri = DEFUPRI;
printsys(msg)
char *msg;
{
- register char *p, *q;
- register int c;
- char line[MAXLINE + 1];
- int pri, flags;
- char *lp;
+ int c, pri, flags;
+ char *lp, *p, *q, line[MAXLINE + 1];
(void)strcpy(line, "vmunix: ");
lp = line + strlen(line);
char *msg, *from;
int flags;
{
- register struct filed *f;
- int fac, prilev;
- int omask, msglen;
+ struct filed *f;
+ int fac, msglen, omask, prilev;
char *timestamp;
dprintf("logmsg: pri %o, flags %x, from %s, msg %s\n",
void
fprintlog(f, flags, msg)
- register struct filed *f;
+ struct filed *f;
int flags;
char *msg;
{
struct iovec iov[6];
- register struct iovec *v;
- register int l;
+ struct iovec *v;
+ int l;
char line[MAXLINE + 1], repbuf[80], greetings[200];
v = iov;
l = MAXLINE;
if (sendto(finet, line, l, 0,
(struct sockaddr *)&f->f_un.f_forw.f_addr,
- sizeof f->f_un.f_forw.f_addr) != l) {
+ sizeof(f->f_un.f_forw.f_addr)) != l) {
int e = errno;
(void)close(f->f_file);
f->f_type = F_UNUSED;
*/
void
wallmsg(f, iov)
- register struct filed *f;
+ struct filed *f;
struct iovec *iov;
{
static int reenter; /* avoid calling ourselves */
- register FILE *uf;
- register int i;
+ FILE *uf;
struct utmp ut;
+ int i;
char *p;
+ char line[sizeof(ut.ut_line) + 1];
if (reenter++)
return;
return;
}
/* NOSTRICT */
- while (fread((char *)&ut, sizeof ut, 1, uf) == 1) {
+ while (fread((char *)&ut, sizeof(ut), 1, uf) == 1) {
if (ut.ut_name[0] == '\0')
continue;
+ strncpy(line, ut.ut_line, sizeof(ut.ut_line));
+ line[sizeof(ut.ut_line)] = '\0';
if (f->f_type == F_WALL) {
- if (p = ttymsg(iov, 6, ut.ut_line, 60*5)) {
+ if ((p = ttymsg(iov, 6, line, 60*5)) != NULL) {
errno = 0; /* already in msg */
logerror(p);
}
break;
if (!strncmp(f->f_un.f_uname[i], ut.ut_name,
UT_NAMESIZE)) {
- if (p = ttymsg(iov, 6, ut.ut_line, 60*5)) {
+ if ((p = ttymsg(iov, 6, line, 60*5)) != NULL) {
errno = 0; /* already in msg */
logerror(p);
}
struct sockaddr_in *f;
{
struct hostent *hp;
- register char *p;
+ char *p;
dprintf("cvthname(%s)\n", inet_ntoa(f->sin_addr));
inet_ntoa(f->sin_addr));
return (inet_ntoa(f->sin_addr));
}
- if ((p = index(hp->h_name, '.')) && strcmp(p + 1, LocalDomain) == 0)
+ if ((p = strchr(hp->h_name, '.')) && strcmp(p + 1, LocalDomain) == 0)
*p = '\0';
return (hp->h_name);
}
domark(signo)
int signo;
{
- register struct filed *f;
+ struct filed *f;
now = time((time_t *)NULL);
MarkSeq += TIMERINTVL;
die(signo)
int signo;
{
- register struct filed *f;
+ struct filed *f;
char buf[100];
for (f = Files; f != NULL; f = f->f_next) {
init(signo)
int signo;
{
- register int i;
- register FILE *cf;
- register struct filed *f, *next, **nextp;
- register char *p;
- char cline[BUFSIZ];
+ int i;
+ FILE *cf;
+ struct filed *f, *next, **nextp;
+ char *p;
+ char cline[LINE_MAX];
dprintf("init\n");
* Foreach line in the conf table, open that file.
*/
f = NULL;
- while (fgets(cline, sizeof cline, cf) != NULL) {
+ while (fgets(cline, sizeof(cline), cf) != NULL) {
/*
* check for end-of-section, comments, strip off trailing
* spaces and newline character.
*/
- for (p = cline; isspace(*p); ++p);
+ for (p = cline; isspace(*p); ++p)
+ continue;
if (*p == NULL || *p == '#')
continue;
- for (p = index(cline, '\0'); isspace(*--p););
+ for (p = strchr(cline, '\0'); isspace(*--p);)
+ continue;
*++p = '\0';
f = (struct filed *)calloc(1, sizeof(*f));
*nextp = f;
void
cfline(line, f)
char *line;
- register struct filed *f;
+ struct filed *f;
{
- register char *p;
- register char *q;
- register int i;
- char *bp;
- int pri;
struct hostent *hp;
+ int i, pri;
+ char *bp, *p, *q;
char buf[MAXLINE], ebuf[100];
dprintf("cfline(%s)\n", line);
errno = 0; /* keep strerror() stuff out of logerror messages */
/* clear out file entry */
- bzero((char *)f, sizeof *f);
+ memset(f, 0, sizeof(*f));
for (i = 0; i <= LOG_NFACILITIES; i++)
f->f_pmask[i] = INTERNAL_NOPRI;
continue;
/* collect priority name */
- for (bp = buf; *q && !index("\t,;", *q); )
+ for (bp = buf; *q && !strchr("\t,;", *q); )
*bp++ = *q++;
*bp = '\0';
/* skip cruft */
- while (index(", ;", *q))
+ while (strchr(", ;", *q))
q++;
/* decode priority name */
}
/* scan facilities */
- while (*p && !index("\t.;", *p)) {
- for (bp = buf; *p && !index("\t,;.", *p); )
+ while (*p && !strchr("\t.;", *p)) {
+ for (bp = buf; *p && !strchr("\t,;.", *p); )
*bp++ = *p++;
*bp = '\0';
if (*buf == '*')
(void)strcpy(f->f_un.f_forw.f_hname, ++p);
hp = gethostbyname(p);
if (hp == NULL) {
- extern int h_errno, h_nerr;
- extern char *h_errlist[];
+ extern int h_errno;
- logerror((u_int)h_errno < h_nerr ?
- h_errlist[h_errno] : "Unknown error");
+ logerror(hstrerror(h_errno));
break;
}
- bzero((char *)&f->f_un.f_forw.f_addr,
- sizeof f->f_un.f_forw.f_addr);
+ memset(&f->f_un.f_forw.f_addr, 0,
+ sizeof(f->f_un.f_forw.f_addr));
f->f_un.f_forw.f_addr.sin_family = AF_INET;
f->f_un.f_forw.f_addr.sin_port = LogPort;
- bcopy(hp->h_addr, (char *)&f->f_un.f_forw.f_addr.sin_addr, hp->h_length);
+ memmove(&f->f_un.f_forw.f_addr.sin_addr, hp->h_addr, hp->h_length);
f->f_type = F_FORW;
break;
const char *name;
CODE *codetab;
{
- register CODE *c;
- register char *p;
- char buf[40];
+ CODE *c;
+ char *p, buf[40];
if (isdigit(*name))
return (atoi(name));