diff --git a/include/lighttpd/angel_log.h b/include/lighttpd/angel_log.h index ac4198b..cd4971f 100644 --- a/include/lighttpd/angel_log.h +++ b/include/lighttpd/angel_log.h @@ -7,14 +7,6 @@ /* #include */ -#define LI_REMOVE_PATH_FROM_FILE 1 -#if LI_REMOVE_PATH_FROM_FILE -LI_API const char *li_remove_path(const char *path); -#define LI_REMOVE_PATH(file) li_remove_path(file) -#else -#define LI_REMOVE_PATH(file) file -#endif - #define SEGFAULT(srv, fmt, ...) \ do { \ li_log_write_(srv, LI_LOG_LEVEL_ABORT, LI_LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \ diff --git a/include/lighttpd/log.h b/include/lighttpd/log.h index bb7206b..b5f3212 100644 --- a/include/lighttpd/log.h +++ b/include/lighttpd/log.h @@ -7,37 +7,29 @@ /* #include */ -#define REMOVE_PATH_FROM_FILE 1 -#if REMOVE_PATH_FROM_FILE -LI_API const char *li_remove_path(const char *path); -#define REMOVE_PATH(file) li_remove_path(file) -#else -#define REMOVE_PATH(file) file -#endif - #define _SEGFAULT(srv, vr, fmt, ...) \ do { \ - li_log_write_(srv, NULL, LI_LOG_LEVEL_ABORT, LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \ + li_log_write_(srv, NULL, LI_LOG_LEVEL_ABORT, LOG_FLAG_TIMESTAMP, "(crashing) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__); \ /* VALGRIND_PRINTF_BACKTRACE(fmt, __VA_ARGS__); */\ abort();\ } while(0) #define _ERROR(srv, vr, fmt, ...) \ - li_log_write_(srv, vr, LI_LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "(error) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_log_write_(srv, vr, LI_LOG_LEVEL_ERROR, LOG_FLAG_TIMESTAMP, "(error) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define _WARNING(srv, vr, fmt, ...) \ - li_log_write_(srv, vr, LI_LOG_LEVEL_WARNING, LOG_FLAG_TIMESTAMP, "(warning) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_log_write_(srv, vr, LI_LOG_LEVEL_WARNING, LOG_FLAG_TIMESTAMP, "(warning) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define _INFO(srv, vr, fmt, ...) \ - li_log_write_(srv, vr, LI_LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "(info) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_log_write_(srv, vr, LI_LOG_LEVEL_INFO, LOG_FLAG_TIMESTAMP, "(info) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define _DEBUG(srv, vr, fmt, ...) \ - li_log_write_(srv, vr, LI_LOG_LEVEL_DEBUG, LOG_FLAG_TIMESTAMP, "(debug) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_log_write_(srv, vr, LI_LOG_LEVEL_DEBUG, LOG_FLAG_TIMESTAMP, "(debug) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define _BACKEND(srv, vr, fmt, ...) \ - li_log_write_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, "(backend) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_log_write_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, "(backend) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define _BACKEND_LINES(srv, vr, txt, fmt, ...) \ - li_log_split_lines_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, txt, "(backend) %s.%d: "fmt, REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) + li_log_split_lines_(srv, vr, LI_LOG_LEVEL_BACKEND, LOG_FLAG_TIMESTAMP, txt, "(backend) %s.%d: "fmt, LI_REMOVE_PATH(__FILE__), __LINE__, __VA_ARGS__) #define VR_SEGFAULT(vr, fmt, ...) _SEGFAULT(vr->wrk->srv, vr, fmt, __VA_ARGS__) diff --git a/include/lighttpd/utils.h b/include/lighttpd/utils.h index 2a3ae9b..ca982c4 100644 --- a/include/lighttpd/utils.h +++ b/include/lighttpd/utils.h @@ -67,4 +67,21 @@ LI_API void li_string_append_int(GString *dest, gint64 val); LI_API gsize li_dirent_buf_size(DIR * dirp); +/* error log helper functions */ +#define LI_REMOVE_PATH_FROM_FILE 1 +#if LI_REMOVE_PATH_FROM_FILE +LI_API const char *li_remove_path(const char *path); +#define LI_REMOVE_PATH(file) li_remove_path(file) +#else +#define LI_REMOVE_PATH(file) file +#endif + +#define LI_SYS_ERROR li_sys_error_quark() +LI_API GQuark li_sys_error_quark(); + +#define LI_SET_SYS_ERROR(error, msg) \ + _li_set_sys_error(error, msg, REMOVE_PATH(__FILE__), __LINE__); + +LI_API gboolean _li_set_sys_error(GError **error, const gchar *msg, const gchar *file, int lineno); + #endif diff --git a/src/angel/angel_log.c b/src/angel/angel_log.c index 6bc4c67..cf35a6b 100644 --- a/src/angel/angel_log.c +++ b/src/angel/angel_log.c @@ -1,16 +1,6 @@ #include -#if LI_REMOVE_PATH_FROM_FILE -const char *li_remove_path(const char *path) { - char *p = strrchr(path, DIR_SEPERATOR); - if (NULL != p && *(p) != '\0') { - return (p + 1); - } - return path; -} -#endif - void log_init(liServer *srv) { srv->log.type = LI_LOG_TYPE_STDERR; diff --git a/src/common/utils.c b/src/common/utils.c index 7578862..38d8014 100644 --- a/src/common/utils.c +++ b/src/common/utils.c @@ -724,3 +724,23 @@ gsize li_dirent_buf_size(DIR * dirp) { return (name_end > sizeof(struct dirent) ? name_end : sizeof(struct dirent)); } + +#if LI_REMOVE_PATH_FROM_FILE +const char *li_remove_path(const char *path) { + char *p = strrchr(path, DIR_SEPERATOR); + if (NULL != p && *(p) != '\0') { + return (p + 1); + } + return path; +} +#endif + +GQuark li_sys_error_quark() { + return g_quark_from_static_string("li-sys-error-quark"); +} + +gboolean _li_set_sys_error(GError **error, const gchar *msg, const gchar *file, int lineno) { + int code = errno; + g_set_error(error, LI_SYS_ERROR, code, "(%s:%d): %s: %s", file, lineno, msg, g_strerror(code)); + return FALSE; +} diff --git a/src/main/log.c b/src/main/log.c index deab8e1..9b0b0a0 100644 --- a/src/main/log.c +++ b/src/main/log.c @@ -11,16 +11,6 @@ #include #include -#if REMOVE_PATH_FROM_FILE -const char *li_remove_path(const char *path) { - char *p = strrchr(path, DIR_SEPERATOR); - if (NULL != p && *(p) != '\0') { - return (p + 1); - } - return path; -} -#endif - void li_log_write(liServer *srv, liLog *log, GString *msg) { liLogEntry *log_entry;