=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/rdist/message.c,v retrieving revision 1.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- src/usr.bin/rdist/message.c 2003/04/19 17:22:29 1.13 +++ src/usr.bin/rdist/message.c 2003/05/14 01:34:35 1.14 @@ -1,4 +1,4 @@ -/* $OpenBSD: message.c,v 1.13 2003/04/19 17:22:29 millert Exp $ */ +/* $OpenBSD: message.c,v 1.14 2003/05/14 01:34:35 millert Exp $ */ /* * Copyright (c) 1983 Regents of the University of California. @@ -33,18 +33,21 @@ * SUCH DAMAGE. */ +#include "defs.h" + #ifndef lint #if 0 -static char RCSid[] = -"$From: message.c,v 6.24 1996/07/19 17:00:35 michaelc Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$From: message.c,v 1.5 1999/11/01 00:21:39 christos Exp $"; #else -static char RCSid[] = -"$OpenBSD: message.c,v 1.13 2003/04/19 17:22:29 millert Exp $"; +static char RCSid[] __attribute__((__unused__)) = +"$OpenBSD: message.c,v 1.14 2003/05/14 01:34:35 millert Exp $"; #endif -static char sccsid[] = "@(#)common.c"; +static char sccsid[] __attribute__((__unused__)) = +"@(#)common.c"; -static char copyright[] = +static char copyright[] __attribute__((__unused__)) = "@(#) Copyright (c) 1983 Regents of the University of California.\n\ All rights reserved.\n"; #endif /* !lint */ @@ -53,7 +56,6 @@ * Message handling functions for both rdist and rdistd. */ -#include "defs.h" #define MSGBUFSIZ 32*1024 @@ -76,8 +78,10 @@ { 0 }, }; -static void msgsendstdout(), msgsendfile(), msgsendsyslog(), - msgsendnotify(); +static void msgsendstdout(MSGFACILITY *, int, int, char *); +static void msgsendsyslog(MSGFACILITY *, int, int, char *); +static void msgsendfile(MSGFACILITY *, int, int, char *); +static void msgsendnotify(MSGFACILITY *, int, int, char *); /* * Message Facilities @@ -90,10 +94,19 @@ { 0 }, }; +static MSGFACILITY *getmsgfac(char *); +static MSGTYPE *getmsgtype(char *); +static char *setmsgtypes(MSGFACILITY *, char *); +static void _message(int, char *); +static void _debugmsg(int, char *); +static void _error(char *); +static void _fatalerr(char *); + /* * Print message logging usage message */ -extern void msgprusage() +void +msgprusage(void) { int i, x; @@ -116,22 +129,23 @@ /* * Print enabled message logging info */ -extern void msgprconfig() +void +msgprconfig(void) { int i, x; static char buf[MSGBUFSIZ]; debugmsg(DM_MISC, "Current message logging config:"); for (i = 0; msgfacility[i].mf_name; ++i) { - (void) snprintf(buf, sizeof(buf), - " %s=", msgfacility[i].mf_name); + (void) snprintf(buf, sizeof(buf), " %.*s=", + (int)(sizeof(buf) - 7), msgfacility[i].mf_name); for (x = 0; msgtypes[x].mt_name; ++x) if (IS_ON(msgfacility[i].mf_msgtypes, msgtypes[x].mt_type)) { if (x > 0) - (void) strlcat(buf, ",", sizeof buf); + (void) strlcat(buf, ",", sizeof(buf)); (void) strlcat(buf, msgtypes[x].mt_name, - sizeof buf); + sizeof(buf)); } debugmsg(DM_MISC, "%s", buf); } @@ -141,8 +155,8 @@ /* * Get the Message Facility entry "name" */ -static MSGFACILITY *getmsgfac(name) - char *name; +static MSGFACILITY * +getmsgfac(char *name) { int i; @@ -156,8 +170,8 @@ /* * Get the Message Type entry named "name" */ -static MSGTYPE *getmsgtype(name) - char *name; +static MSGTYPE * +getmsgtype(char *name) { int i; @@ -172,9 +186,8 @@ * Set Message Type information for Message Facility "msgfac" as * indicated by string "str". */ -static char *setmsgtypes(msgfac, str) - MSGFACILITY *msgfac; - char *str; +static char * +setmsgtypes(MSGFACILITY *msgfac, char *str) { static char ebuf[BUFSIZ]; char *cp; @@ -187,8 +200,8 @@ if (isserver && (msgfac->mf_msgfac != MF_SYSLOG && msgfac->mf_msgfac != MF_FILE)) { (void) snprintf(ebuf, sizeof(ebuf), - "The \"%s\" message facility cannot be used by the server.", - msgfac->mf_name); + "The \"%.*s\" message facility cannot be used by the server.", + 100, msgfac->mf_name); return(ebuf); } @@ -239,11 +252,11 @@ msgfac->mf_msgtypes = 0; /* Start from scratch */ while (strptr) { word = strptr; - if ((cp = strchr(strptr, ','))) + if ((cp = strchr(strptr, ',')) != NULL) *cp++ = CNULL; strptr = cp; - if ((mtp = getmsgtype(word))) { + if ((mtp = getmsgtype(word)) != NULL) { msgfac->mf_msgtypes |= mtp->mt_type; /* * XXX This is really a kludge until we add real @@ -254,8 +267,8 @@ debug = DM_ALL; } else { (void) snprintf(ebuf, sizeof(ebuf), - "Message type \"%s\" is invalid.", - word); + "Message type \"%.*s\" is invalid.", + 100, word); return(ebuf); } } @@ -266,9 +279,8 @@ /* * Parse a message logging option string */ -extern char *msgparseopts(msgstr, doset) - char *msgstr; - int doset; +char * +msgparseopts(char *msgstr, int doset) { static char ebuf[BUFSIZ], msgbuf[MSGBUFSIZ]; char *cp, *optstr; @@ -279,7 +291,7 @@ return("NULL message string"); /* strtok() is harmful */ - (void) strlcpy(msgbuf, msgstr, sizeof msgbuf); + (void) strlcpy(msgbuf, msgstr, sizeof(msgbuf)); /* * Each = list is separated by ":". @@ -299,15 +311,15 @@ if ((msgfac = getmsgfac(word)) == NULL) { (void) snprintf(ebuf, sizeof(ebuf), - "%s is not a valid message facility", - word); + "%.*s is not a valid message facility", + 100, word); return(ebuf); } if (doset) { char *mcp; - if ((mcp = setmsgtypes(msgfac, cp))) + if ((mcp = setmsgtypes(msgfac, cp)) != NULL) return(mcp); } } @@ -324,12 +336,8 @@ * Send a message to facility "stdout". * For rdistd, this is really the rdist client. */ -static void msgsendstdout(msgfac, mtype, flags, msgbuf) - /*ARGSUSED*/ - MSGFACILITY *msgfac; - int mtype; - int flags; - char *msgbuf; +static void +msgsendstdout(MSGFACILITY *msgfac, int mtype, int flags, char *msgbuf) { char cmd; @@ -382,12 +390,8 @@ /* * Send a message to facility "syslog" */ -static void msgsendsyslog(msgfac, mtype, flags, msgbuf) - /*ARGSUSED*/ - MSGFACILITY *msgfac; - int mtype; - int flags; - char *msgbuf; +static void +msgsendsyslog(MSGFACILITY *msgfac, int mtype, int flags, char *msgbuf) { int syslvl = 0; @@ -427,12 +431,8 @@ /* * Send a message to a "file" facility. */ -static void msgsendfile(msgfac, mtype, flags, msgbuf) - /*ARGSUSED*/ - MSGFACILITY *msgfac; - int mtype; - int flags; - char *msgbuf; +static void +msgsendfile(MSGFACILITY *msgfac, int mtype, int flags, char *msgbuf) { if (msgfac->mf_fptr == NULL) return; @@ -447,12 +447,8 @@ /* * Same method as msgsendfile() */ -static void msgsendnotify(msgfac, mtype, flags, msgbuf) - /*ARGSUSED*/ - MSGFACILITY *msgfac; - int mtype; - int flags; - char *msgbuf; +static void +msgsendnotify(MSGFACILITY *msgfac, int mtype, int flags, char *msgbuf) { char *tempfile; @@ -465,26 +461,22 @@ if (!msgfac->mf_fptr) { char *cp; int fd; - char *getenv(); size_t len; /* * Create and open a new temporary file */ - if ((cp = getenv("TMPDIR")) == NULL) + if ((cp = getenv("TMPDIR")) == NULL || *cp == '\0') cp = _PATH_TMP; len = strlen(cp) + 1 + sizeof(_RDIST_TMP); tempfile = (char *) xmalloc(len); (void) snprintf(tempfile, len, "%s/%s", cp, _RDIST_TMP); msgfac->mf_filename = tempfile; - if ((fd = mkstemp(msgfac->mf_filename)) == -1 || - (msgfac->mf_fptr = fdopen(fd, "w")) == NULL) { - if (fd != -1) - close(fd); - fatalerr("Cannot open notify file for writing: %s: %s.", - msgfac->mf_filename, SYSERR); - } + if ((fd = mkstemp(msgfac->mf_filename)) < 0 || + (msgfac->mf_fptr = fdopen(fd, "w")) == NULL) + fatalerr("Cannot open notify file for writing: %s: %s.", + msgfac->mf_filename, SYSERR); debugmsg(DM_MISC, "Created notify temp file '%s'", msgfac->mf_filename); } @@ -499,7 +491,8 @@ /* * Insure currenthost is set to something reasonable. */ -extern void checkhostname() +void +checkhostname(void) { static char mbuf[MAXHOSTNAMELEN]; char *cp; @@ -517,9 +510,8 @@ /* * Print a message contained in "msgbuf" if a level "lvl" is set. */ -static void _message(flags, msgbuf) - int flags; - char *msgbuf; +static void +_message(int flags, char *msgbuf) { int i, x; char *cp; @@ -529,17 +521,17 @@ /* * Ensure no stray newlines are present */ - if ((cp = strchr(msgbuf, '\n'))) + if ((cp = strchr(msgbuf, '\n')) != NULL) *cp = CNULL; checkhostname(); if (strncmp(currenthost, msgbuf, strlen(currenthost)) == 0) - (void) strlcpy(mbuf, msgbuf, sizeof mbuf); + (void) strlcpy(mbuf, msgbuf, sizeof(mbuf)); else - (void) snprintf(mbuf, sizeof mbuf, - "%s: %s", currenthost, msgbuf); + (void) snprintf(mbuf, sizeof(mbuf), + "%s: %s", currenthost, msgbuf); } else - (void) strlcpy(mbuf, "", sizeof mbuf); + mbuf[0] = '\0'; /* * Special case for messages that only get @@ -587,7 +579,8 @@ /* * Varargs front-end to _message() */ -extern void message(va_alist) +void +message(va_alist) va_dcl { static char buf[MSGBUFSIZ]; @@ -600,7 +593,7 @@ fmt = (char *) va_arg(args, char *); va_end(args); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); _message(lvl, buf); } @@ -610,43 +603,25 @@ /* * Stdarg front-end to _message() */ -extern void message(int lvl, char *fmt, ...) +void +message(int lvl, char *fmt, ...) { static char buf[MSGBUFSIZ]; va_list args; va_start(args, fmt); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _message(lvl, buf); } #endif /* ARG_STDARG */ - -#if !defined(ARG_TYPE) /* - * Simple front-end to _message() - */ -/*VARARGS2*/ -extern void message(lvl, fmt, a1, a2, a3, a4, a5) - int lvl; - char *fmt; -{ - static char buf[MSGBUFSIZ]; - - (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5); - - _message(lvl, buf); -} -#endif /* !ARG_TYPE */ - -/* * Display a debugging message */ -static void _debugmsg(lvl, buf) - int lvl; - char *buf; +static void +_debugmsg(int lvl, char *buf) { if (IS_ON(debug, lvl)) _message(MT_DEBUG, buf); @@ -656,7 +631,8 @@ /* * Varargs front-end to _debugmsg() */ -extern void debugmsg(va_alist) +void +debugmsg(va_alist) va_dcl { static char buf[MSGBUFSIZ]; @@ -669,7 +645,7 @@ fmt = (char *) va_arg(args, char *); va_end(args); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); _debugmsg(lvl, buf); } @@ -679,41 +655,25 @@ /* * Stdarg front-end to _debugmsg() */ -extern void debugmsg(int lvl, char *fmt, ...) +void +debugmsg(int lvl, char *fmt, ...) { static char buf[MSGBUFSIZ]; va_list args; va_start(args, fmt); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _debugmsg(lvl, buf); } #endif /* ARG_STDARG */ -#if !defined(ARG_TYPE) /* - * Simple front-end to _debugmsg() - */ -/*VARARGS2*/ -extern void debugmsg(lvl, fmt, a1, a2, a3, a4, a5) - int lvl; - char *fmt; -{ - static char buf[MSGBUFSIZ]; - - (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5); - - _debugmsg(lvl, buf); -} -#endif /* ARG_TYPE */ - -/* * Print an error message */ -static void _error(msg) - char *msg; +static void +_error(char *msg) { static char buf[MSGBUFSIZ]; @@ -722,9 +682,11 @@ if (msg) { if (isserver) - (void) snprintf(buf, sizeof buf, "REMOTE ERROR: %s", msg); + (void) snprintf(buf, sizeof(buf), + "REMOTE ERROR: %s", msg); else - (void) snprintf(buf, sizeof buf, "LOCAL ERROR: %s", msg); + (void) snprintf(buf, sizeof(buf), + "LOCAL ERROR: %s", msg); } _message(MT_NERROR, (buf[0]) ? buf : NULL); @@ -734,7 +696,8 @@ /* * Varargs frontend to _error() */ -extern void error(va_alist) +void +error(va_alist) va_dcl { static char buf[MSGBUFSIZ]; @@ -745,7 +708,7 @@ va_start(args); fmt = (char *) va_arg(args, char *); if (fmt) - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _error((buf[0]) ? buf : NULL); @@ -756,7 +719,8 @@ /* * Stdarg frontend to _error() */ -extern void error(char *fmt, ...) +void +error(char *fmt, ...) { static char buf[MSGBUFSIZ]; va_list args; @@ -764,45 +728,27 @@ buf[0] = CNULL; va_start(args, fmt); if (fmt) - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _error((buf[0]) ? buf : NULL); } #endif /* ARG_STDARG */ -#if !defined(ARG_TYPE) /* - * Simple frontend to _error() - */ -/*VARARGS1*/ -extern void error(fmt, a1, a2, a3, a4, a5, a6) - char *fmt; -{ - static char buf[MSGBUFSIZ]; - - buf[0] = CNULL; - if (fmt) - (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5, a6); - - _error((buf[0]) ? buf : NULL); -} -#endif /* ARG_TYPE */ - -/* * Display a fatal message */ -static void _fatalerr(msg) - char *msg; +static void +_fatalerr(char *msg) { static char buf[MSGBUFSIZ]; ++nerrs; if (isserver) - (void) snprintf(buf, sizeof buf, "REMOTE ERROR: %s", msg); + (void) snprintf(buf, sizeof(buf), "REMOTE ERROR: %s", msg); else - (void) snprintf(buf, sizeof buf, "LOCAL ERROR: %s", msg); + (void) snprintf(buf, sizeof(buf), "LOCAL ERROR: %s", msg); _message(MT_FERROR, buf); @@ -813,7 +759,8 @@ /* * Varargs front-end to _fatalerr() */ -extern void fatalerr(va_alist) +void +fatalerr(va_alist) va_dcl { static char buf[MSGBUFSIZ]; @@ -822,7 +769,7 @@ va_start(args); fmt = (char *) va_arg(args, char *); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _fatalerr(buf); @@ -833,42 +780,28 @@ /* * Stdarg front-end to _fatalerr() */ -extern void fatalerr(char *fmt, ...) +void +fatalerr(char *fmt, ...) { static char buf[MSGBUFSIZ]; va_list args; va_start(args, fmt); - (void) vsnprintf(buf, sizeof buf, fmt, args); + (void) vsnprintf(buf, sizeof(buf), fmt, args); va_end(args); _fatalerr(buf); } #endif /* ARG_STDARG */ -#if !defined(ARG_TYPE) /* - * Simple front-end to _fatalerr() - */ -/*VARARGS1*/ -extern void fatalerr(fmt, a1, a2, a3, a4, a5) - char *fmt; -{ - static char buf[MSGBUFSIZ]; - - (void) snprintf(buf, sizeof buf, fmt, a1, a2, a3, a4, a5); - - _fatalerr(buf); -} -#endif /* !ARG_TYPE */ - -/* * Get the name of the file used for notify. * A side effect is that the file pointer to the file * is closed. We assume this function is only called when * we are ready to read the file. */ -extern char *getnotifyfile() +char * +getnotifyfile(void) { int i;