From 21e8d846ed040a1bf55987036578807d5826d958 Mon Sep 17 00:00:00 2001 From: Gergely Nagy Date: Sat, 24 Mar 2012 11:17:03 +0100 Subject: Implement proper error handling. Instead of calling abort() if vasprintf() fails, and ignoring possible errors from the JSON library, do handle errors reasonably sanely: check return values, and return an error state from all functions, and propagate it up to the application level, too. This means that the legacy overrides will silently fail, but set errno appropriately in case serializing to JSON fails, and do what the system libc does with syslog otherwise. The new functions can return NULL or non-zero on error, which the application can then handle as it sees fit. Signed-off-by: Gergely Nagy --- lib/umberlog.rst | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'lib/umberlog.rst') diff --git a/lib/umberlog.rst b/lib/umberlog.rst index 515a6cc..26204e2 100644 --- a/lib/umberlog.rst +++ b/lib/umberlog.rst @@ -20,8 +20,8 @@ SYNOPSIS void ul_openlog (const char *ident, int option, int facility); - void ul_syslog (int priority, const char *format, ....); - void ul_vsyslog (int priority, const char *format, va_list ap); + int ul_syslog (int priority, const char *format, ....); + int ul_vsyslog (int priority, const char *format, va_list ap); void ul_legacy_syslog (int priority, const char *format, ...); void ul_legacy_vsyslog (int priority, const char *format, va_list ap); @@ -57,6 +57,15 @@ will be added to the generated message. variants above, except the formatted payload is not sent to syslog, but returned as a newly allocated string. +RETURN VALUE +============ + +When successful, **ul_syslog()** and **ul_vsyslog()** return zero, +while **ul_format()** and **ul_vformat()** return a character string. + +On failure the former two will return non-zero, the latter two +**NULL**, and set *errno* appropriately. + CEE PAYLOAD =========== @@ -122,11 +131,11 @@ EXAMPLES :: - ul_syslog(LOG_NOTICE, "Logged in user: %s", username, - "service", "%s", service, - "auth-method", "%s", auth_method, - "sessionid", "%d", session_id, - NULL); + status = ul_syslog(LOG_NOTICE, "Logged in user: %s", username, + "service", "%s", service, + "auth-method", "%s", auth_method, + "sessionid", "%d", session_id, + NULL); SEE ALSO ======== -- cgit