Annotation of src/usr.bin/rdist/message.c, Revision 1.6
1.6 ! millert 1: /* $OpenBSD: message.c,v 1.5 1996/07/25 05:31:02 millert Exp $ */
1.4 deraadt 2:
1.1 dm 3: /*
4: * Copyright (c) 1983 Regents of the University of California.
5: * All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by the University of
18: * California, Berkeley and its contributors.
19: * 4. Neither the name of the University nor the names of its contributors
20: * may be used to endorse or promote products derived from this software
21: * without specific prior written permission.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33: * SUCH DAMAGE.
34: */
35:
36: #ifndef lint
37: static char RCSid[] =
1.6 ! millert 38: "$OpenBSD: message.c,v 1.5 1996/07/25 05:31:02 millert Exp $";
1.1 dm 39:
40: static char sccsid[] = "@(#)common.c";
41:
42: static char copyright[] =
43: "@(#) Copyright (c) 1983 Regents of the University of California.\n\
44: All rights reserved.\n";
45: #endif /* !lint */
46:
47: /*
48: * Message handling functions for both rdist and rdistd.
49: */
50:
51: #include "defs.h"
52:
53: #define MSGBUFSIZ 32*1024
54:
55: int debug = 0; /* Debugging level */
56: int nerrs = 0; /* Number of errors */
57: char *tempfile = NULL; /* Name of temporary file */
58:
59: /*
60: * Message Types
61: */
62: MSGTYPE msgtypes[] = {
63: { MT_CHANGE, "change" },
64: { MT_INFO, "info" },
65: { MT_NOTICE, "notice" },
66: { MT_NERROR, "nerror" },
67: { MT_FERROR, "ferror" },
68: { MT_WARNING, "warning" },
69: { MT_VERBOSE, "verbose" },
70: { MT_ALL, "all" },
71: { MT_DEBUG, "debug" },
72: { 0 },
73: };
74:
75: static void msgsendstdout(), msgsendfile(), msgsendsyslog(),
76: msgsendnotify();
77:
78: /*
79: * Message Facilities
80: */
81: MSGFACILITY msgfacility[] = {
82: { MF_STDOUT, "stdout", msgsendstdout },
83: { MF_FILE, "file", msgsendfile },
84: { MF_SYSLOG, "syslog", msgsendsyslog },
85: { MF_NOTIFY, "notify", msgsendnotify },
86: { 0 },
87: };
88:
89: /*
90: * Print message logging usage message
91: */
92: extern void msgprusage()
93: {
94: register int i, x;
95:
96: (void) fprintf(stderr, "\nWhere <msgopt> is of form\n");
97: (void) fprintf(stderr,
98: "\t<facility1>=<type1>,<type2>,...:<facility2>=<type1>,<type2>...\n");
99:
100: (void) fprintf(stderr, "Valid <facility> names:");
101:
102: for (i = 0; msgfacility[i].mf_name; ++i)
103: (void) fprintf(stderr, " %s", msgfacility[i].mf_name);
104:
105: (void) fprintf(stderr, "\nValid <type> names:");
106: for (x = 0; msgtypes[x].mt_name; ++x)
107: (void) fprintf(stderr, " %s", msgtypes[x].mt_name);
108:
109: (void) fprintf(stderr, "\n");
110: }
111:
112: /*
113: * Print enabled message logging info
114: */
115: extern void msgprconfig()
116: {
117: register int i, x;
118: static char buf[MSGBUFSIZ];
119:
120: debugmsg(DM_MISC, "Current message logging config:");
121: for (i = 0; msgfacility[i].mf_name; ++i) {
1.5 millert 122: (void) snprintf(buf, sizeof(buf),
123: " %s=", msgfacility[i].mf_name);
1.1 dm 124: for (x = 0; msgtypes[x].mt_name; ++x)
125: if (IS_ON(msgfacility[i].mf_msgtypes,
126: msgtypes[x].mt_type)) {
127: if (x > 0)
128: (void) strcat(buf, ",");
129: (void) strcat(buf, msgtypes[x].mt_name);
130: }
131: debugmsg(DM_MISC, "%s", buf);
132: }
133:
134: }
135:
136: /*
137: * Get the Message Facility entry "name"
138: */
139: static MSGFACILITY *getmsgfac(name)
140: char *name;
141: {
142: register int i;
143:
144: for (i = 0; msgfacility[i].mf_name; ++i)
145: if (strcasecmp(name, msgfacility[i].mf_name) == 0)
146: return(&msgfacility[i]);
147:
148: return((MSGFACILITY *) NULL);
149: }
150:
151: /*
152: * Get the Message Type entry named "name"
153: */
154: static MSGTYPE *getmsgtype(name)
155: char *name;
156: {
157: register int i;
158:
159: for (i = 0; msgtypes[i].mt_name; ++i)
160: if (strcasecmp(name, msgtypes[i].mt_name) == 0)
161: return(&msgtypes[i]);
162:
163: return((MSGTYPE *) NULL);
164: }
165:
166: /*
167: * Set Message Type information for Message Facility "msgfac" as
168: * indicated by string "str".
169: */
170: static char *setmsgtypes(msgfac, str)
171: MSGFACILITY *msgfac;
172: char *str;
173: {
174: static char ebuf[BUFSIZ];
175: register char *cp;
176: register char *strptr, *word;
177: register MSGTYPE *mtp;
178:
179: /*
180: * MF_SYSLOG is the only supported message facility for the server
181: */
182: if (isserver && (msgfac->mf_msgfac != MF_SYSLOG &&
183: msgfac->mf_msgfac != MF_FILE)) {
1.5 millert 184: (void) snprintf(ebuf, sizeof(ebuf),
1.1 dm 185: "The \"%s\" message facility cannot be used by the server.",
186: msgfac->mf_name);
187: return(ebuf);
188: }
189:
190: strptr = str;
191:
192: /*
193: * Do any necessary Message Facility preparation
194: */
195: switch(msgfac->mf_msgfac) {
196: case MF_FILE:
197: /*
198: * The MF_FILE string should look like "<file>=<types>".
199: */
200: if ((cp = strchr(strptr, '=')) == NULL)
201: return(
202: "No file name found for \"file\" message facility");
203: *cp++ = CNULL;
204:
205: if ((msgfac->mf_fptr = fopen(strptr, "w")) == NULL)
206: fatalerr("Cannot open log file for writing: %s: %s.",
207: strptr, SYSERR);
208: msgfac->mf_filename = strdup(strptr);
209:
210: strptr = cp;
211: break;
212:
213: case MF_NOTIFY:
214: break;
215:
216: case MF_STDOUT:
217: msgfac->mf_fptr = stdout;
218: break;
219:
220: case MF_SYSLOG:
221: #if defined(LOG_OPTS)
222: #if defined(LOG_FACILITY)
223: openlog(progname, LOG_OPTS, LOG_FACILITY);
224: #else
225: openlog(progname, LOG_OPTS);
226: #endif /* LOG_FACILITY */
227: #endif /* LOG_OPTS */
228: break;
229: }
230:
231: /*
232: * Parse each type word
233: */
234: msgfac->mf_msgtypes = 0; /* Start from scratch */
235: while (strptr) {
236: word = strptr;
237: if (cp = strchr(strptr, ','))
238: *cp++ = CNULL;
239: strptr = cp;
240:
241: if (mtp = getmsgtype(word)) {
242: msgfac->mf_msgtypes |= mtp->mt_type;
243: /*
244: * XXX This is really a kludge until we add real
245: * control over debugging.
246: */
247: if (!debug && isserver &&
248: strcasecmp(word, "debug") == 0)
249: debug = DM_ALL;
250: } else {
1.5 millert 251: (void) snprintf(ebuf, sizeof(ebuf),
252: "Message type \"%s\" is invalid.",
253: word);
1.1 dm 254: return(ebuf);
255: }
256: }
257:
258: return((char *) NULL);
259: }
260:
261: /*
262: * Parse a message logging option string
263: */
264: extern char *msgparseopts(msgstr, doset)
265: char *msgstr;
266: int doset;
267: {
268: static char ebuf[BUFSIZ], msgbuf[MSGBUFSIZ];
269: register char *cp, *optstr;
270: register char *word;
271: MSGFACILITY *msgfac;
272:
273: if (msgstr == NULL)
274: return("NULL message string");
275:
276: /* strtok() is harmful */
277: (void) strcpy(msgbuf, msgstr);
278:
279: /*
280: * Each <facility>=<types> list is seperated by ":".
281: */
282: for (optstr = strtok(msgbuf, ":"); optstr;
283: optstr = strtok((char *)NULL, ":")) {
284:
285: if ((cp = strchr(optstr, '=')) == NULL)
286: return("No '=' found");
287:
288: *cp++ = CNULL;
289: word = optstr;
290: if ((int)strlen(word) <= 0)
291: return("No message facility specified");
292: if ((int)strlen(cp) <= 0)
293: return("No message type specified");
294:
295: if ((msgfac = getmsgfac(word)) == NULL) {
1.5 millert 296: (void) snprintf(ebuf, sizeof(ebuf),
297: "%s is not a valid message facility",
298: word);
1.1 dm 299: return(ebuf);
300: }
301:
302: if (doset) {
303: char *mcp;
304:
305: if (mcp = setmsgtypes(msgfac, cp))
306: return(mcp);
307: }
308: }
309:
310: if (isserver && debug) {
311: debugmsg(DM_MISC, "%s", getversion());
312: msgprconfig();
313: }
314:
315: return((char *) NULL);
316: }
317:
318: /*
319: * Send a message to facility "stdout".
320: * For rdistd, this is really the rdist client.
321: */
322: static void msgsendstdout(msgfac, mtype, flags, msgbuf)
323: /*ARGSUSED*/
324: MSGFACILITY *msgfac;
325: int mtype;
326: int flags;
327: char *msgbuf;
328: {
329: char cmd;
330:
331: if (isserver) {
332: if (rem_w < 0 || IS_ON(flags, MT_NOREMOTE))
333: return;
334:
335: cmd = CNULL;
336:
337: switch(mtype) {
338: case MT_NERROR: cmd = C_ERRMSG; break;
339: case MT_FERROR: cmd = C_FERRMSG; break;
340: case MT_NOTICE: cmd = C_NOTEMSG; break;
341: case MT_REMOTE: cmd = C_LOGMSG; break;
342: }
343:
344: if (cmd != CNULL)
345: (void) sendcmd(cmd, "%s", msgbuf);
346: } else {
347: switch(mtype) {
348: case MT_FERROR:
349: case MT_NERROR:
350: if (msgbuf && *msgbuf) {
351: (void) fprintf(stderr, "%s\n", msgbuf);
352: (void) fflush(stderr);
353: }
354: break;
355:
356: case MT_DEBUG:
357: /*
358: * Only things that are strictly MT_DEBUG should
359: * be shown.
360: */
361: if (flags != MT_DEBUG)
362: return;
363: case MT_NOTICE:
364: case MT_CHANGE:
365: case MT_INFO:
366: case MT_VERBOSE:
367: case MT_WARNING:
368: if (msgbuf && *msgbuf) {
369: (void) printf("%s\n", msgbuf);
370: (void) fflush(stdout);
371: }
372: break;
373: }
374: }
375: }
376:
377: /*
378: * Send a message to facility "syslog"
379: */
380: static void msgsendsyslog(msgfac, mtype, flags, msgbuf)
381: /*ARGSUSED*/
382: MSGFACILITY *msgfac;
383: int mtype;
384: int flags;
385: char *msgbuf;
386: {
387: int syslvl = 0;
388:
389: if (!msgbuf || !*msgbuf)
390: return;
391:
392: switch(mtype) {
393: #if defined(SL_NERROR)
394: case MT_NERROR: syslvl = SL_NERROR; break;
395: #endif
396: #if defined(SL_FERROR)
397: case MT_FERROR: syslvl = SL_FERROR; break;
398: #endif
399: #if defined(SL_WARNING)
400: case MT_WARNING: syslvl = SL_WARNING; break;
401: #endif
402: #if defined(SL_CHANGE)
403: case MT_CHANGE: syslvl = SL_CHANGE; break;
404: #endif
405: #if defined(SL_INFO)
406: case MT_SYSLOG:
407: case MT_VERBOSE:
408: case MT_INFO: syslvl = SL_INFO; break;
409: #endif
410: #if defined(SL_NOTICE)
411: case MT_NOTICE: syslvl = SL_NOTICE; break;
412: #endif
413: #if defined(SL_DEBUG)
414: case MT_DEBUG: syslvl = SL_DEBUG; break;
415: #endif
416: }
417:
418: if (syslvl)
419: syslog(syslvl, "%s", msgbuf);
420: }
421:
422: /*
423: * Send a message to a "file" facility.
424: */
425: static void msgsendfile(msgfac, mtype, flags, msgbuf)
426: /*ARGSUSED*/
427: MSGFACILITY *msgfac;
428: int mtype;
429: int flags;
430: char *msgbuf;
431: {
432: if (msgfac->mf_fptr == NULL)
433: return;
434:
435: if (!msgbuf || !*msgbuf)
436: return;
437:
438: (void) fprintf(msgfac->mf_fptr, "%s\n", msgbuf);
439: (void) fflush(msgfac->mf_fptr);
440: }
441:
442: /*
443: * Same method as msgsendfile()
444: */
445: static void msgsendnotify(msgfac, mtype, flags, msgbuf)
446: /*ARGSUSED*/
447: MSGFACILITY *msgfac;
448: int mtype;
449: int flags;
450: char *msgbuf;
451: {
452: if (IS_ON(flags, MT_DEBUG))
453: return;
454:
455: if (!msgbuf || !*msgbuf)
456: return;
457:
458: if (!msgfac->mf_fptr) {
459: register char *cp;
460: char *getenv();
1.6 ! millert 461: int fd;
1.1 dm 462:
463: /*
464: * Create and open a new temporary file
465: */
466: if ((cp = getenv("TMPDIR")) == (char *) NULL)
467: cp = _PATH_TMP;
468: tempfile = (char *) xmalloc(strlen(cp) + 1 +
469: strlen(_RDIST_TMP) + 2);
470: (void) sprintf(tempfile, "%s/%s", cp, _RDIST_TMP);
471:
472: msgfac->mf_filename = tempfile;
1.3 deraadt 473: if ((fd = mkstemp(msgfac->mf_filename)) == -1 ||
1.6 ! millert 474: (msgfac->mf_fptr = fdopen(fd, "w")) == NULL) {
1.3 deraadt 475: if (fd != -1)
476: close(fd);
1.1 dm 477: fatalerr("Cannot open notify file for writing: %s: %s.",
478: msgfac->mf_filename, SYSERR);
1.3 deraadt 479: }
1.1 dm 480: debugmsg(DM_MISC, "Created notify temp file '%s'",
481: msgfac->mf_filename);
482: }
483:
484: if (msgfac->mf_fptr == NULL)
485: return;
486:
487: (void) fprintf(msgfac->mf_fptr, "%s\n", msgbuf);
488: (void) fflush(msgfac->mf_fptr);
489: }
490:
491: /*
492: * Insure currenthost is set to something reasonable.
493: */
494: extern void checkhostname()
495: {
496: static char mbuf[MAXHOSTNAMELEN];
497: char *cp;
498:
499: if (!currenthost) {
500: if (gethostname(mbuf, sizeof(mbuf)) == 0) {
501: if ((cp = strchr(mbuf, '.')) != NULL)
502: *cp = CNULL;
503: currenthost = strdup(mbuf);
504: } else
505: currenthost = "(unknown)";
506: }
507: }
508:
509: /*
510: * Print a message contained in "msgbuf" if a level "lvl" is set.
511: */
512: static void _message(flags, msgbuf)
513: int flags;
514: char *msgbuf;
515: {
516: register int i, x;
517: register char *cp;
518: static char mbuf[2048];
519:
520: if (msgbuf && *msgbuf) {
521: /*
522: * Ensure no stray newlines are present
523: */
524: if (cp = strchr(msgbuf, '\n'))
525: *cp = CNULL;
526:
527: checkhostname();
528: if (strncmp(currenthost, msgbuf, strlen(currenthost)) == 0)
529: (void) strcpy(mbuf, msgbuf);
530: else
531: (void) sprintf(mbuf, "%s: %s", currenthost, msgbuf);
532: } else
533: (void) strcpy(mbuf, "");
534:
535: /*
536: * Special case for messages that only get
537: * logged to the system log facility
538: */
539: if (IS_ON(flags, MT_SYSLOG)) {
540: msgsendsyslog((MSGFACILITY *)NULL, MT_SYSLOG, flags, mbuf);
541: return;
542: }
543:
544: /*
545: * Special cases
546: */
1.5 millert 547: if (isserver && IS_ON(flags, MT_NOTICE)) {
548: msgsendstdout((MSGFACILITY *)NULL, MT_NOTICE, flags, mbuf);
549: return;
550: } else if (isserver && IS_ON(flags, MT_REMOTE))
1.1 dm 551: msgsendstdout((MSGFACILITY *)NULL, MT_REMOTE, flags, mbuf);
552: else if (isserver && IS_ON(flags, MT_NERROR))
553: msgsendstdout((MSGFACILITY *)NULL, MT_NERROR, flags, mbuf);
554: else if (isserver && IS_ON(flags, MT_FERROR))
555: msgsendstdout((MSGFACILITY *)NULL, MT_FERROR, flags, mbuf);
556:
557: /*
558: * For each Message Facility, check each Message Type to see
559: * if the bits in "flags" are set. If so, call the appropriate
560: * Message Facility to dispatch the message.
561: */
562: for (i = 0; msgfacility[i].mf_name; ++i)
563: for (x = 0; msgtypes[x].mt_name; ++x)
564: /*
565: * XXX MT_ALL should not be used directly
566: */
567: if (msgtypes[x].mt_type != MT_ALL &&
568: IS_ON(flags, msgtypes[x].mt_type) &&
569: IS_ON(msgfacility[i].mf_msgtypes,
570: msgtypes[x].mt_type))
571: (*msgfacility[i].mf_sendfunc)(&msgfacility[i],
572: msgtypes[x].mt_type,
573: flags,
574: mbuf);
575: }
576:
577: #if defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
578: /*
579: * Varargs front-end to _message()
580: */
581: extern void message(va_alist)
582: va_dcl
583: {
584: static char buf[MSGBUFSIZ];
585: va_list args;
586: char *fmt;
587: int lvl;
588:
589: va_start(args);
590: lvl = (int) va_arg(args, int);
591: fmt = (char *) va_arg(args, char *);
592: va_end(args);
593:
594: (void) vsprintf(buf, fmt, args);
595:
596: _message(lvl, buf);
597: }
598: #endif /* ARG_VARARGS */
599:
600: #if defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
601: /*
602: * Stdarg front-end to _message()
603: */
604: extern void message(int lvl, char *fmt, ...)
605: {
606: static char buf[MSGBUFSIZ];
607: va_list args;
608:
609: va_start(args, fmt);
610: (void) vsprintf(buf, fmt, args);
611: va_end(args);
612:
613: _message(lvl, buf);
614: }
615: #endif /* ARG_STDARG */
616:
617:
618: #if !defined(ARG_TYPE)
619: /*
620: * Simple front-end to _message()
621: */
622: /*VARARGS2*/
623: extern void message(lvl, fmt, a1, a2, a3, a4, a5)
624: int lvl;
625: char *fmt;
626: {
627: static char buf[MSGBUFSIZ];
628:
629: (void) sprintf(buf, fmt, a1, a2, a3, a4, a5);
630:
631: _message(lvl, buf);
632: }
633: #endif /* !ARG_TYPE */
634:
635: /*
636: * Display a debugging message
637: */
638: static void _debugmsg(lvl, buf)
639: int lvl;
640: char *buf;
641: {
642: if (IS_ON(debug, lvl))
643: _message(MT_DEBUG, buf);
644: }
645:
646: #if defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
647: /*
648: * Varargs front-end to _debugmsg()
649: */
650: extern void debugmsg(va_alist)
651: va_dcl
652: {
653: static char buf[MSGBUFSIZ];
654: va_list args;
655: char *fmt;
656: int lvl;
657:
658: va_start(args);
659: lvl = (int) va_arg(args, int);
660: fmt = (char *) va_arg(args, char *);
661: va_end(args);
662:
663: (void) vsprintf(buf, fmt, args);
664:
665: _debugmsg(lvl, buf);
666: }
667: #endif /* ARG_VARARGS */
668:
669: #if defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
670: /*
671: * Stdarg front-end to _debugmsg()
672: */
673: extern void debugmsg(int lvl, char *fmt, ...)
674: {
675: static char buf[MSGBUFSIZ];
676: va_list args;
677:
678: va_start(args, fmt);
679: (void) vsprintf(buf, fmt, args);
680: va_end(args);
681:
682: _debugmsg(lvl, buf);
683: }
684: #endif /* ARG_STDARG */
685:
686: #if !defined(ARG_TYPE)
687: /*
688: * Simple front-end to _debugmsg()
689: */
690: /*VARARGS2*/
691: extern void debugmsg(lvl, fmt, a1, a2, a3, a4, a5)
692: int lvl;
693: char *fmt;
694: {
695: static char buf[MSGBUFSIZ];
696:
697: (void) sprintf(buf, fmt, a1, a2, a3, a4, a5);
698:
699: _debugmsg(lvl, buf);
700: }
701: #endif /* ARG_TYPE */
702:
703: /*
704: * Print an error message
705: */
706: static void _error(msg)
707: char *msg;
708: {
709: static char buf[MSGBUFSIZ];
710:
711: nerrs++;
712: buf[0] = CNULL;
713:
714: if (msg) {
715: if (isserver)
716: (void) sprintf(buf, "REMOTE ERROR: %s", msg);
717: else
718: (void) sprintf(buf, "LOCAL ERROR: %s", msg);
719: }
720:
721: _message(MT_NERROR, (buf[0]) ? buf : NULL);
722: }
723:
724: #if defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
725: /*
726: * Varargs frontend to _error()
727: */
728: extern void error(va_alist)
729: va_dcl
730: {
731: static char buf[MSGBUFSIZ];
732: va_list args;
733: char *fmt;
734:
735: buf[0] = CNULL;
736: va_start(args);
737: fmt = (char *) va_arg(args, char *);
738: if (fmt)
739: (void) vsprintf(buf, fmt, args);
740: va_end(args);
741:
742: _error((buf[0]) ? buf : NULL);
743: }
744: #endif /* ARG_VARARGS */
745:
746: #if defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
747: /*
748: * Stdarg frontend to _error()
749: */
750: extern void error(char *fmt, ...)
751: {
752: static char buf[MSGBUFSIZ];
753: va_list args;
754:
755: buf[0] = CNULL;
756: va_start(args, fmt);
757: if (fmt)
758: (void) vsprintf(buf, fmt, args);
759: va_end(args);
760:
761: _error((buf[0]) ? buf : NULL);
762: }
763: #endif /* ARG_STDARG */
764:
765: #if !defined(ARG_TYPE)
766: /*
767: * Simple frontend to _error()
768: */
769: /*VARARGS1*/
770: extern void error(fmt, a1, a2, a3, a4, a5, a6)
771: char *fmt;
772: {
773: static char buf[MSGBUFSIZ];
774:
775: buf[0] = CNULL;
776: if (fmt)
777: (void) sprintf(buf, fmt, a1, a2, a3, a4, a5, a6);
778:
779: _error((buf[0]) ? buf : NULL);
780: }
781: #endif /* ARG_TYPE */
782:
783: /*
784: * Display a fatal message
785: */
786: static void _fatalerr(msg)
787: char *msg;
788: {
789: static char buf[MSGBUFSIZ];
790:
791: ++nerrs;
792:
793: if (isserver)
794: (void) sprintf(buf, "REMOTE ERROR: %s", msg);
795: else
796: (void) sprintf(buf, "LOCAL ERROR: %s", msg);
797:
798: _message(MT_FERROR, buf);
799:
800: exit(nerrs);
801: }
802:
803: #if defined(ARG_TYPE) && ARG_TYPE == ARG_VARARGS
804: /*
805: * Varargs front-end to _fatalerr()
806: */
807: extern void fatalerr(va_alist)
808: va_dcl
809: {
810: static char buf[MSGBUFSIZ];
811: va_list args;
812: char *fmt;
813:
814: va_start(args);
815: fmt = (char *) va_arg(args, char *);
816: (void) vsprintf(buf, fmt, args);
817: va_end(args);
818:
819: _fatalerr(buf);
820: }
821: #endif /* ARG_VARARGS */
822:
823: #if defined(ARG_TYPE) && ARG_TYPE == ARG_STDARG
824: /*
825: * Stdarg front-end to _fatalerr()
826: */
827: extern void fatalerr(char *fmt, ...)
828: {
829: static char buf[MSGBUFSIZ];
830: va_list args;
831:
832: va_start(args, fmt);
833: (void) vsprintf(buf, fmt, args);
834: va_end(args);
835:
836: _fatalerr(buf);
837: }
838: #endif /* ARG_STDARG */
839:
840: #if !defined(ARG_TYPE)
841: /*
842: * Simple front-end to _fatalerr()
843: */
844: /*VARARGS1*/
845: extern void fatalerr(fmt, a1, a2, a3, a4, a5)
846: char *fmt;
847: {
848: static char buf[MSGBUFSIZ];
849:
850: (void) sprintf(buf, fmt, a1, a2, a3, a4, a5);
851:
852: _fatalerr(buf);
853: }
854: #endif /* !ARG_TYPE */
855:
856: /*
857: * Get the name of the file used for notify.
858: * A side effect is that the file pointer to the file
859: * is closed. We assume this function is only called when
860: * we are ready to read the file.
861: */
862: extern char *getnotifyfile()
863: {
864: register int i;
865:
866: for (i = 0; msgfacility[i].mf_name; i++)
867: if (msgfacility[i].mf_msgfac == MF_NOTIFY &&
868: msgfacility[i].mf_fptr) {
869: (void) fclose(msgfacility[i].mf_fptr);
870: msgfacility[i].mf_fptr = NULL;
871: return(msgfacility[i].mf_filename);
872: }
873:
874: return((char *) NULL);
875: }