1 /**********************************************************/
2 /* output error message to syslog or stdout */
3 /* from UNIX NETWORK PROGRAMMING,Vol.1,Second Edition, */
4 /* By W. Richard Stevens, Published By Prentice Hall */
5 /* ftp://ftp.kohala.com/pub/rstevens/unpv12e.tar.gz */
6 /**********************************************************/
8 #include "opengatemd.h"
9 #include <stdarg.h> /* ANSI C header file */
10 #include <syslog.h> /* for syslog() */
14 static void err_doit(int, int, const char *, va_list);
16 /*************************************************/
17 /* Nonfatal error related to a system call.
18 * Print a message and return. */
19 /*************************************************/
20 void errToSyslog(int i)
26 err_ret(const char *fmt, ...)
31 err_doit(1, LOG_INFO, fmt, ap);
36 /*************************************************/
37 /* Fatal error related to a system call.
38 * Print a message and terminate. */
39 /*************************************************/
41 err_sys(const char *fmt, ...)
46 err_doit(1, LOG_ERR, fmt, ap);
51 /*************************************************/
52 /* Fatal error related to a system call.
53 * Print a message, dump core, and terminate. */
54 /*************************************************/
56 err_dump(const char *fmt, ...)
61 err_doit(1, LOG_ERR, fmt, ap);
63 abort(); /* dump core and terminate */
64 exit(1); /* shouldn't get here */
67 /*************************************************/
68 /* Nonfatal error unrelated to a system call.
69 * Print a message and return. */
70 /*************************************************/
72 err_msg(const char *fmt, ...)
77 err_doit(0, LOG_INFO, fmt, ap);
82 /*************************************************/
83 /* Nonfatal error unrelated to a system call.
84 * Print a message and return.
85 * Write with WARNING property */
86 /*************************************************/
88 err_msg_warn(const char *fmt, ...)
93 err_doit(0, LOG_WARNING, fmt, ap);
98 /*************************************************/
99 /* Fatal error unrelated to a system call.
100 * Print a message and terminate. */
101 /*************************************************/
103 err_quit(const char *fmt, ...)
108 err_doit(0, LOG_ERR, fmt, ap);
114 /*************************************************/
115 /* Print a message and return to caller.
116 * Caller specifies "errnoflag" and "level". */
117 /*************************************************/
119 err_doit(int errnoflag, int level, const char *fmt, va_list ap)
124 errno_save = errno; /* value caller might want printed */
125 #ifdef HAVE_VSNPRINTF
126 vsnprintf(buf, sizeof(buf), fmt, ap); /* this is safe */
128 vsprintf(buf, fmt, ap); /* this is not safe */
132 snprintf(buf+n, sizeof(buf)-n, ": %s", strerror(errno_save));
136 syslog(level, "%s", buf);
138 fflush(stdout); /* in case stdout and stderr are the same */