diff --git a/ChangeLog b/ChangeLog index a49800d88c..359a03c9ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Tue May 26 13:09:30 BST 2009 Daniel P. Berrange + + Fix error location logging + * src/virterror.c, src/virterror_internal.h: Re-factor error + reporting APIs to ensure correct source location info is + passed through to eventual virLogMessage call. + Tue May 26 11:25:30 BST 2009 Daniel P. Berrange * tests/Makefile.am: Add ocaml intermediate files to CLEANFILES diff --git a/src/virterror.c b/src/virterror.c index b2735e1e5a..974c366890 100644 --- a/src/virterror.c +++ b/src/virterror.c @@ -590,10 +590,11 @@ virSetConnError(virConnectPtr conn) /** - * virRaiseError: + * virRaiseErrorFull: * @conn: the connection to the hypervisor if available - * @dom: the domain if available - * @net: the network if available + * @filename: filename where error was raised + * @funcname: function name where error was raised + * @linenr: line number where error was raised * @domain: the virErrorDomain indicating where it's coming from * @code: the virErrorNumber code for the error * @level: the virErrorLevel for the error @@ -609,12 +610,19 @@ virSetConnError(virConnectPtr conn) * immediately if a callback is found and store it for later handling. */ void -virRaiseError(virConnectPtr conn, - virDomainPtr dom ATTRIBUTE_UNUSED, - virNetworkPtr net ATTRIBUTE_UNUSED, - int domain, int code, virErrorLevel level, - const char *str1, const char *str2, const char *str3, - int int1, int int2, const char *msg, ...) +virRaiseErrorFull(virConnectPtr conn, + const char *filename ATTRIBUTE_UNUSED, + const char *funcname, + size_t linenr, + int domain, + int code, + virErrorLevel level, + const char *str1, + const char *str2, + const char *str3, + int int1, + int int2, + const char *fmt, ...) { virErrorPtr to; void *userData = virUserData; @@ -650,18 +658,18 @@ virRaiseError(virConnectPtr conn, /* * formats the message */ - if (msg == NULL) { + if (fmt == NULL) { str = strdup(_("No error message provided")); } else { - VIR_GET_VAR_STR(msg, str); + VIR_GET_VAR_STR(fmt, str); } /* * Hook up the error or warning to the logging facility - * TODO: pass function name and lineno + * XXXX should we include filename as 'category' instead of domain name ? */ virLogMessage(virErrorDomainName(domain), virErrorLevelPriority(level), - NULL, 0, 1, "%s", str); + funcname, linenr, 1, "%s", str); /* * Save the information about the error @@ -1067,10 +1075,12 @@ virErrorMsg(virErrorNumber error, const char *info) * Helper function to do most of the grunt work for individual driver * ReportError */ -void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode, - const char *filename ATTRIBUTE_UNUSED, - const char *funcname ATTRIBUTE_UNUSED, - size_t linenr ATTRIBUTE_UNUSED, +void virReportErrorHelper(virConnectPtr conn, + int domcode, + int errcode, + const char *filename, + const char *funcname, + size_t linenr, const char *fmt, ...) { va_list args; @@ -1086,8 +1096,10 @@ void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode, } virerr = virErrorMsg(errcode, (errorMessage[0] ? errorMessage : NULL)); - virRaiseError(conn, NULL, NULL, domcode, errcode, VIR_ERR_ERROR, - virerr, errorMessage, NULL, -1, -1, virerr, errorMessage); + virRaiseErrorFull(conn, filename, funcname, linenr, + domcode, errcode, VIR_ERR_ERROR, + virerr, errorMessage, NULL, + -1, -1, virerr, errorMessage); } @@ -1116,9 +1128,9 @@ const char *virStrerror(int theerrno, char *errBuf, size_t errBufLen) void virReportSystemErrorFull(virConnectPtr conn, int domcode, int theerrno, - const char *filename ATTRIBUTE_UNUSED, - const char *funcname ATTRIBUTE_UNUSED, - size_t linenr ATTRIBUTE_UNUSED, + const char *filename, + const char *funcname, + size_t linenr, const char *fmt, ...) { char strerror_buf[1024]; @@ -1148,19 +1160,21 @@ void virReportSystemErrorFull(virConnectPtr conn, if (!msgDetail) msgDetail = errnoDetail; - virRaiseError(conn, NULL, NULL, domcode, VIR_ERR_SYSTEM_ERROR, VIR_ERR_ERROR, - msg, msgDetail, NULL, -1, -1, msg, msgDetail); + virRaiseErrorFull(conn, filename, funcname, linenr, + domcode, VIR_ERR_SYSTEM_ERROR, VIR_ERR_ERROR, + msg, msgDetail, NULL, -1, -1, msg, msgDetail); } void virReportOOMErrorFull(virConnectPtr conn, int domcode, - const char *filename ATTRIBUTE_UNUSED, - const char *funcname ATTRIBUTE_UNUSED, - size_t linenr ATTRIBUTE_UNUSED) + const char *filename, + const char *funcname, + size_t linenr) { const char *virerr; virerr = virErrorMsg(VIR_ERR_NO_MEMORY, NULL); - virRaiseError(conn, NULL, NULL, domcode, VIR_ERR_NO_MEMORY, VIR_ERR_ERROR, - virerr, NULL, NULL, -1, -1, virerr, NULL); + virRaiseErrorFull(conn, filename, funcname, linenr, + domcode, VIR_ERR_NO_MEMORY, VIR_ERR_ERROR, + virerr, NULL, NULL, -1, -1, virerr, NULL); } diff --git a/src/virterror_internal.h b/src/virterror_internal.h index 709c8ec473..fe9a96fe04 100644 --- a/src/virterror_internal.h +++ b/src/virterror_internal.h @@ -33,17 +33,28 @@ extern void *virUserData; * * ************************************************************************/ int virErrorInitialize(void); -void virRaiseError(virConnectPtr conn, - virDomainPtr dom, - virNetworkPtr net, - int domain, - int code, - virErrorLevel level, - const char *str1, - const char *str2, - const char *str3, - int int1, int int2, const char *msg, ...) - ATTRIBUTE_FORMAT(printf, 12, 13); +void virRaiseErrorFull(virConnectPtr conn, + const char *filename, + const char *funcname, + size_t linenr, + int domain, + int code, + virErrorLevel level, + const char *str1, + const char *str2, + const char *str3, + int int1, + int int2, + const char *fmt, ...) + ATTRIBUTE_FORMAT(printf, 13, 14); + +/* Includes 'dom' and 'net' for compatbility, but they're ignored */ +#define virRaiseError(conn, dom, net, domain, code, level, \ + str1, str2, str3, int1, int2, msg, ...) \ + virRaiseErrorFull(conn, __FILE__, __FUNCTION__, __LINE__, \ + domain, code, level, str1, str2, str3, int1, int2, \ + msg, __VA_ARGS__) + const char *virErrorMsg(virErrorNumber error, const char *info); void virReportErrorHelper(virConnectPtr conn, int domcode, int errcode, const char *filename ATTRIBUTE_UNUSED,