Annotation of embedaddon/sudo/include/fatal.h, revision 1.1.1.2
1.1 misho 1: /*
2: * Copyright (c) 2004, 2010-2013 Todd C. Miller <Todd.Miller@courtesan.com>
3: *
4: * Permission to use, copy, modify, and distribute this software for any
5: * purpose with or without fee is hereby granted, provided that the above
6: * copyright notice and this permission notice appear in all copies.
7: *
8: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15: */
16:
17: #ifndef _SUDO_FATAL_H_
18: #define _SUDO_FATAL_H_
19:
20: #include <stdarg.h>
21: #include <setjmp.h>
22:
23: /*
24: * We wrap fatal/fatalx and warning/warningx so that the same output can
25: * go to the debug file, if there is one.
26: */
1.1.1.2 ! misho 27: #if (defined(SUDO_ERROR_WRAP) && SUDO_ERROR_WRAP == 0) || defined(NO_VARIADIC_MACROS)
! 28: # define fatal fatal_nodebug
! 29: # define fatalx fatalx_nodebug
! 30: # define warning warning_nodebug
! 31: # define warningx warningx_nodebug
1.1 misho 32: # define vfatal(fmt, ap) fatal_nodebug((fmt), (ap))
33: # define vfatalx(fmt, ap) fatalx_nodebug((fmt), (ap))
34: # define vwarning(fmt, ap) warning_nodebug((fmt), (ap))
35: # define vwarningx(fmt, ap) warningx_nodebug((fmt), (ap))
36: #else /* SUDO_ERROR_WRAP */
37: # if defined(__GNUC__) && __GNUC__ == 2
38: # define fatal(fmt...) do { \
39: sudo_debug_printf2(__func__, __FILE__, __LINE__, \
40: SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
41: fmt); \
42: fatal_nodebug(fmt); \
43: } while (0)
44: # define fatalx(fmt...) do { \
45: sudo_debug_printf2(__func__, __FILE__, __LINE__, \
46: SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, fmt); \
47: fatalx_nodebug(fmt); \
48: } while (0)
49: # define warning(fmt...) do { \
50: sudo_debug_printf2(__func__, __FILE__, __LINE__, \
51: SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
52: fmt); \
53: warning_nodebug(fmt); \
54: } while (0)
55: # define warningx(fmt...) do { \
56: sudo_debug_printf2(__func__, __FILE__, __LINE__, \
57: SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, fmt); \
58: warningx_nodebug(fmt); \
59: } while (0)
60: # else
61: # define fatal(...) do { \
62: sudo_debug_printf2(__func__, __FILE__, __LINE__, \
63: SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
64: __VA_ARGS__); \
65: fatal_nodebug(__VA_ARGS__); \
66: } while (0)
67: # define fatalx(...) do { \
68: sudo_debug_printf2(__func__, __FILE__, __LINE__, \
69: SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, __VA_ARGS__); \
70: fatalx_nodebug(__VA_ARGS__); \
71: } while (0)
72: # define warning(...) do { \
73: sudo_debug_printf2(__func__, __FILE__, __LINE__, \
74: SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
75: __VA_ARGS__); \
76: warning_nodebug(__VA_ARGS__); \
77: } while (0)
78: # define warningx(...) do { \
79: sudo_debug_printf2(__func__, __FILE__, __LINE__, \
80: SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|sudo_debug_subsys, __VA_ARGS__); \
81: warningx_nodebug(__VA_ARGS__); \
82: } while (0)
83: # endif /* __GNUC__ == 2 */
1.1.1.2 ! misho 84: # define vfatal(fmt, ap) do { \
! 85: va_list ap2; \
! 86: va_copy(ap2, (ap)); \
1.1 misho 87: sudo_debug_vprintf2(__func__, __FILE__, __LINE__, \
88: SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
1.1.1.2 ! misho 89: (fmt), ap2); \
1.1 misho 90: vfatal_nodebug((fmt), (ap)); \
91: } while (0)
92: # define vfatalx(fmt, ap) do { \
1.1.1.2 ! misho 93: va_list ap2; \
! 94: va_copy(ap2, (ap)); \
1.1 misho 95: sudo_debug_vprintf2(__func__, __FILE__, __LINE__, \
1.1.1.2 ! misho 96: SUDO_DEBUG_ERROR|SUDO_DEBUG_LINENO|sudo_debug_subsys, (fmt), ap2); \
1.1 misho 97: vfatalx_nodebug((fmt), (ap)); \
98: } while (0)
99: # define vwarning(fmt, ap) do { \
1.1.1.2 ! misho 100: va_list ap2; \
! 101: va_copy(ap2, (ap)); \
1.1 misho 102: sudo_debug_vprintf2(__func__, __FILE__, __LINE__, \
103: SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|SUDO_DEBUG_ERRNO|sudo_debug_subsys, \
1.1.1.2 ! misho 104: (fmt), ap2); \
1.1 misho 105: vwarning_nodebug((fmt), (ap)); \
106: } while (0)
107: # define vwarningx(fmt, ap) do { \
1.1.1.2 ! misho 108: va_list ap2; \
! 109: va_copy(ap2, (ap)); \
1.1 misho 110: sudo_debug_vprintf2(__func__, __FILE__, __LINE__, \
1.1.1.2 ! misho 111: SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO|sudo_debug_subsys, (fmt), ap2); \
1.1 misho 112: vwarningx_nodebug((fmt), (ap)); \
113: } while (0)
114: #endif /* SUDO_ERROR_WRAP */
115:
116: #define fatal_setjmp() (fatal_enable_setjmp(), sigsetjmp(fatal_jmp, 1))
117: #define fatal_longjmp(val) siglongjmp(fatal_jmp, val)
118:
119: extern int (*sudo_printf)(int msg_type, const char *fmt, ...);
120: extern sigjmp_buf fatal_jmp;
121:
1.1.1.2 ! misho 122: int fatal_callback_register(void (*func)(void));
! 123: char *warning_gettext(const char *msgid) __format_arg(1);
1.1 misho 124: void fatal_disable_setjmp(void);
125: void fatal_enable_setjmp(void);
1.1.1.2 ! misho 126: void fatal_nodebug(const char *, ...) __printf0like(1, 2) __attribute__((__noreturn__));
! 127: void fatalx_nodebug(const char *, ...) __printflike(1, 2) __attribute__((__noreturn__));
! 128: void vfatal_nodebug(const char *, va_list ap) __printf0like(1, 0) __attribute__((__noreturn__));
! 129: void vfatalx_nodebug(const char *, va_list ap) __printflike(1, 0) __attribute__((__noreturn__));
! 130: void warning_nodebug(const char *, ...) __printf0like(1, 2);
! 131: void warningx_nodebug(const char *, ...) __printflike(1, 2);
! 132: void vwarning_nodebug(const char *, va_list ap) __printf0like(1, 0);
! 133: void vwarningx_nodebug(const char *, va_list ap) __printflike(1, 0);
1.1 misho 134:
135: #endif /* _SUDO_FATAL_H_ */
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>