[BACK]Return to diag.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libwrap

File: [cvs.NetBSD.org] / src / lib / libwrap / diag.c (download)

Revision 1.8.50.2, Mon Apr 23 23:40:41 2012 UTC (8 years, 5 months ago) by riz
Branch: netbsd-6
CVS Tags: netbsd-6-1-RELEASE, netbsd-6-1-RC4, netbsd-6-1-RC3, netbsd-6-1-RC2, netbsd-6-1-RC1, netbsd-6-1-5-RELEASE, netbsd-6-1-4-RELEASE, netbsd-6-1-3-RELEASE, netbsd-6-1-2-RELEASE, netbsd-6-1-1-RELEASE, netbsd-6-1, netbsd-6-0-RELEASE, netbsd-6-0-RC2, netbsd-6-0-RC1, netbsd-6-0-6-RELEASE, netbsd-6-0-5-RELEASE, netbsd-6-0-4-RELEASE, netbsd-6-0-3-RELEASE, netbsd-6-0-2-RELEASE, netbsd-6-0-1-RELEASE, netbsd-6-0, matt-nb6-plus-nbase, matt-nb6-plus-base, matt-nb6-plus
Changes since 1.8.50.1: +16 -16 lines

Back out changes committed as part of ticket #195 which were apparently
not intended as part of the pullup request.  Should fix netbsd-6 build.

/*	$NetBSD: diag.c,v 1.8.50.2 2012/04/23 23:40:41 riz Exp $	*/

 /*
  * Routines to report various classes of problems. Each report is decorated
  * with the current context (file name and line number), if available.
  * 
  * tcpd_warn() reports a problem and proceeds.
  * 
  * tcpd_jump() reports a problem and jumps.
  * 
  * Author: Wietse Venema, Eindhoven University of Technology, The Netherlands.
  */

#include <sys/cdefs.h>
#ifndef lint
#if 0
static char sccsid[] = "@(#) diag.c 1.1 94/12/28 17:42:20";
#else
__RCSID("$NetBSD: diag.c,v 1.8.50.2 2012/04/23 23:40:41 riz Exp $");
#endif
#endif

/* System libraries */

#include <syslog.h>
#include <stdio.h>
#include <setjmp.h>
#include <string.h>
#include <errno.h>

/* Local stuff */

#include "tcpd.h"
#include "mystdarg.h"

struct tcpd_context tcpd_context;
jmp_buf tcpd_buf;

static void tcpd_diag __P((int, char *, char *, va_list))
	__attribute__((__format__(__printf__, 3, 0)));

/* tcpd_diag - centralize error reporter */

static void tcpd_diag(severity, tag, format, ap)
int     severity;
char   *tag;
char   *format;
va_list ap;
{
    char    fmt[BUFSIZ];
    char    buf[BUFSIZ];
    int     i, o, oerrno;

    /* save errno in case we need it */
    oerrno = errno;

    /* contruct the tag for the log entry */
    if (tcpd_context.file)
	(void)snprintf(buf, sizeof buf, "%s: %s, line %d: ",
		tag, tcpd_context.file, tcpd_context.line);
    else
	(void)snprintf(buf, sizeof buf, "%s: ", tag);

    /* change % to %% in tag before appending the format */
    for (i = 0, o = 0; buf[i] != '\0'; ) {
	if (buf[i] == '%') {
	    fmt[o] = '%';
	    if (o < sizeof(fmt) - 1)
		o++;
	}
	fmt[o] = buf[i++];
	if (o < sizeof(fmt) - 1)
	    o++;
    }

    /* append format and force null termination */
    fmt[o] = '\0';
    (void)strlcat(fmt, format, sizeof(fmt) - o);

    errno = oerrno;
    vsyslog(severity, fmt, ap);
}

/* tcpd_warn - report problem of some sort and proceed */

void    VARARGS(tcpd_warn, char *, format)
{
    va_list ap;

    VASTART(ap, char *, format);
    tcpd_diag(LOG_ERR, "warning", format, ap);
    VAEND(ap);
}

/* tcpd_jump - report serious problem and jump */

void    VARARGS(tcpd_jump, char *, format)
{
    va_list ap;

    VASTART(ap, char *, format);
    tcpd_diag(LOG_ERR, "error", format, ap);
    VAEND(ap);
    longjmp(tcpd_buf, AC_ERROR);
}