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() */
12 int daemon_proc; /* daemon procedure or not */
14 static void err_doit(int, int, const char *, va_list);
16 /**********************************************/
17 /* set flag of syslog usage */
18 /* i:(input) TRUE(1)=use syslog (daemon proc) */
19 /* FALSE(0)=use stdout (shell proc) */
20 /**********************************************/
21 void errToSyslog(int i)
26 /*************************************************/
27 /* Non-fatal error related to a system call. */
28 /* Print a message and return. */
29 /*************************************************/
31 err_ret(const char *fmt, ...)
36 err_doit(1, LOG_INFO, fmt, ap);
41 /*************************************************/
42 /* Fatal error related to a system call.
43 * Print a message and terminate. */
44 /*************************************************/
46 err_sys(const char *fmt, ...)
51 err_doit(1, LOG_ERR, fmt, ap);
56 /*************************************************/
57 /* Fatal error related to a system call.
58 * Print a message, dump core, and terminate. */
59 /*************************************************/
61 err_dump(const char *fmt, ...)
66 err_doit(1, LOG_ERR, fmt, ap);
68 abort(); /* dump core and terminate */
69 exit(1); /* shouldn't get here */
72 /*************************************************/
73 /* Nonfatal error unrelated to a system call.
74 * Print a message and return. */
75 /*************************************************/
77 err_msg(const char *fmt, ...)
82 err_doit(0, LOG_INFO, fmt, ap);
87 /*************************************************/
88 /* Fatal error unrelated to a system call.
89 * Print a message and terminate. */
90 /*************************************************/
92 err_quit(const char *fmt, ...)
97 err_doit(0, LOG_ERR, fmt, ap);
103 /*************************************************/
104 /* Print a message and return to caller.
105 * Caller specifies "errnoflag" and "level". */
106 /*************************************************/
108 err_doit(int errnoflag, int level, const char *fmt, va_list ap)
113 errno_save = errno; /* value caller might want printed */
114 #ifdef HAVE_VSNPRINTF
115 vsnprintf(buf, sizeof(buf), fmt, ap); /* this is safe */
117 vsprintf(buf, fmt, ap); /* this is not safe */
121 snprintf(buf+n, sizeof(buf)-n, ": %s", strerror(errno_save));
125 syslog(level, "%s", buf);
127 fflush(stdout); /* in case stdout and stderr are the same */
135 /*************************
136 terminate this program
137 used for debug purpose
138 *************************/
139 void terminateProg(int ret){