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 "opengatemmng.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 /* Fatal error unrelated to a system call.
84 * Print a message and terminate. */
85 /*************************************************/
87 err_quit(const char *fmt, ...)
92 err_doit(0, LOG_ERR, fmt, ap);
98 /*************************************************/
99 /* Print a message and return to caller.
100 * Caller specifies "errnoflag" and "level". */
101 /*************************************************/
103 err_doit(int errnoflag, int level, const char *fmt, va_list ap)
108 errno_save = errno; /* value caller might want printed */
109 #ifdef HAVE_VSNPRINTF
110 vsnprintf(buf, sizeof(buf), fmt, ap); /* this is safe */
112 vsprintf(buf, fmt, ap); /* this is not safe */
116 snprintf(buf+n, sizeof(buf)-n, ": %s", strerror(errno_save));
122 fflush(stdout); /* in case stdout and stderr are the same */
130 /*************************
131 terminate this program
132 used for debug purpose
133 *************************/
134 void terminateProg(int ret){