failures.c revision e0f65ae5ab5c991bc5ba64ef549e0a8e4b43d20a
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen failures.c : Failure manager
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainen Copyright (c) 2001-2002 Timo Sirainen
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen Permission is hereby granted, free of charge, to any person obtaining
4d4d585520538a752e9f0a4a1c019a2918f52e56Timo Sirainen a copy of this software and associated documentation files (the
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen "Software"), to deal in the Software without restriction, including
aef92409cf369afdd2ecd81a4f80083cd4082f46Timo Sirainen without limitation the rights to use, copy, modify, merge, publish,
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen distribute, sublicense, and/or sell copies of the Software, and to
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen permit persons to whom the Software is furnished to do so, subject to
e0f4fbf127b192667c62af7875c4f2ca294b6c7aTimo Sirainen the following conditions:
e0f4fbf127b192667c62af7875c4f2ca294b6c7aTimo Sirainen The above copyright notice and this permission notice shall be
e0f4fbf127b192667c62af7875c4f2ca294b6c7aTimo Sirainen included in all copies or substantial portions of the Software.
e0f4fbf127b192667c62af7875c4f2ca294b6c7aTimo Sirainen THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
e0f4fbf127b192667c62af7875c4f2ca294b6c7aTimo Sirainen OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
e0f4fbf127b192667c62af7875c4f2ca294b6c7aTimo Sirainen MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
e0f4fbf127b192667c62af7875c4f2ca294b6c7aTimo Sirainen IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
e0f4fbf127b192667c62af7875c4f2ca294b6c7aTimo Sirainen CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
105addcb709523868418cc3e3baad7ad3453a91eTimo Sirainen SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
b44faf865da16ac4d18eecd85a55b3fab6b9e63aTimo Sirainenstatic void default_panic_handler(const char *format, va_list args)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void default_fatal_handler(const char *format, va_list args)
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainenstatic void default_error_handler(const char *format, va_list args);
1175f27441385a7011629f295f42708f9a3a4ffcTimo Sirainenstatic void default_warning_handler(const char *format, va_list args);
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainen/* Initialize working defaults */
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenstatic FailureFunc panic_handler __attr_noreturn__ = default_panic_handler;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenstatic FailureFunc fatal_handler __attr_noreturn__ = default_fatal_handler;
7797aa2479e99aeb71057b7a2584b2cb72e4d3f8Timo Sirainenstatic FailureFunc error_handler = default_error_handler;
16c89b1260c9d07c01c83a9219424d3727069b2eTimo Sirainenstatic FailureFunc warning_handler = default_warning_handler;
0c909e3461607eadcd66f4eac69b7f34e37fccf1Timo Sirainenstatic char *log_prefix = NULL, *log_stamp_format = NULL;
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainenstatic void write_prefix(void)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen if (strftime(str, sizeof(str), log_stamp_format, tm) > 0)
e169102fb38ce788b76c2a344bee7d77079dea05Timo Sirainenstatic void default_panic_handler(const char *format, va_list args)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen vfprintf(log_fd, printf_string_fix_format(format), args);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void default_fatal_handler(const char *format, va_list args)
ad48319996942463675b53877092ab7e13a7a75aTimo Sirainen vfprintf(log_fd, printf_string_fix_format(format), args);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainenstatic void default_error_handler(const char *format, va_list args)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen vfprintf(log_fd, printf_string_fix_format(format), args);
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainenstatic void default_warning_handler(const char *format, va_list args)
faed8babca9914257f34fb2e603d74016d563b2dTimo Sirainen vfprintf(log_fd, printf_string_fix_format(format), args);
e76f5e07be5bec4e5ca99c3e093ff7f11edbe1b7Timo Sirainenvoid i_set_panic_handler(FailureFunc func __attr_noreturn__)
c5794838af9995f50bfecb06a3cd4f9a0ac77858Timo Sirainenvoid i_set_fatal_handler(FailureFunc func __attr_noreturn__)
0dffa25d211be541ee3c953b23566a1a990789dfTimo Sirainenvoid i_syslog_panic_handler(const char *fmt, va_list args)
0d70a702dec63d22535684fec6a7247c5f153208Timo Sirainenvoid i_syslog_fatal_handler(const char *fmt, va_list args)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenvoid i_syslog_error_handler(const char *fmt, va_list args)
2a6af811ea3de3cf9e2f15e446674dd21b0705f3Timo Sirainenvoid i_syslog_warning_handler(const char *fmt, va_list args)
2d49f150b4bce6f2f59a84e268e4777901c3e42cTimo Sirainenvoid i_set_failure_file(const char *path, const char *prefix)