All uses of virLibNetworkError passed __FUNCTION__ as the info string; avoid the duplication by factoring it into a macro which can contain additional information (namely, the line number). The resulting error messages differ in the attributed location (now pointing to the caller rather than the helper), but the rest of the error text is unchanged. * src/libvirt.c (virLibNetworkError): Convert to macro, and drop extra parameter. All callers simplified. (virLibNetworkErrorHelper): Refactor function to take new parameters. --- If this type of cleanup is desirable, I can trim the 600+ other uses of __FUNCTION__ out of libvirt.c. src/libvirt.c | 52 +++++++++++++++++++++++++++------------------------- 1 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/libvirt.c b/src/libvirt.c index eb05337..2764793 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -503,9 +503,11 @@ virLibDomainError(virDomainPtr domain, virErrorNumber error, * * Handle an error at the connection level */ +#define virLibNetworkError(net, error) \ + virLibNetworkErrorHelper(net, error, __FILE__, __FUNCTION__, __LINE__) static void -virLibNetworkError(virNetworkPtr network, virErrorNumber error, - const char *info) +virLibNetworkErrorHelper(virNetworkPtr network, virErrorNumber error, + const char *file, const char *func, size_t line) { virConnectPtr conn = NULL; const char *errmsg; @@ -513,12 +515,12 @@ virLibNetworkError(virNetworkPtr network, virErrorNumber error, if (error == VIR_ERR_OK) return; - errmsg = virErrorMsg(error, info); + errmsg = virErrorMsg(error, func); if (error != VIR_ERR_INVALID_NETWORK) { conn = network->conn; } - virRaiseError(conn, NULL, network, VIR_FROM_NET, error, VIR_ERR_ERROR, - errmsg, info, NULL, 0, 0, errmsg, info); + virRaiseErrorFull(conn, file, func, line, VIR_FROM_NET, error, + VIR_ERR_ERROR, errmsg, func, NULL, 0, 0, errmsg, func); } /** @@ -5630,7 +5632,7 @@ virNetworkGetConnect (virNetworkPtr net) virResetLastError(); if (!VIR_IS_CONNECTED_NETWORK (net)) { - virLibNetworkError (NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError (NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return NULL; } @@ -6028,13 +6030,13 @@ virNetworkUndefine(virNetworkPtr network) { virResetLastError(); if (!VIR_IS_CONNECTED_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (-1); } conn = network->conn; if (conn->flags & VIR_CONNECT_RO) { - virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__); + virLibNetworkError(network, VIR_ERR_OPERATION_DENIED); goto error; } @@ -6071,13 +6073,13 @@ virNetworkCreate(virNetworkPtr network) virResetLastError(); if (!VIR_IS_CONNECTED_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (-1); } conn = network->conn; if (conn->flags & VIR_CONNECT_RO) { - virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__); + virLibNetworkError(network, VIR_ERR_OPERATION_DENIED); goto error; } @@ -6116,14 +6118,14 @@ virNetworkDestroy(virNetworkPtr network) virResetLastError(); if (!VIR_IS_CONNECTED_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (-1); } conn = network->conn; if (conn->flags & VIR_CONNECT_RO) { - virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__); + virLibNetworkError(network, VIR_ERR_OPERATION_DENIED); goto error; } @@ -6159,7 +6161,7 @@ virNetworkFree(virNetworkPtr network) virResetLastError(); if (!VIR_IS_CONNECTED_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (-1); } @@ -6219,7 +6221,7 @@ virNetworkGetName(virNetworkPtr network) virResetLastError(); if (!VIR_IS_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (NULL); } @@ -6243,12 +6245,12 @@ virNetworkGetUUID(virNetworkPtr network, unsigned char *uuid) virResetLastError(); if (!VIR_IS_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (-1); } if (uuid == NULL) { - virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__); + virLibNetworkError(network, VIR_ERR_INVALID_ARG); goto error; } @@ -6280,12 +6282,12 @@ virNetworkGetUUIDString(virNetworkPtr network, char *buf) virResetLastError(); if (!VIR_IS_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (-1); } if (buf == NULL) { - virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__); + virLibNetworkError(network, VIR_ERR_INVALID_ARG); goto error; } @@ -6320,12 +6322,12 @@ virNetworkGetXMLDesc(virNetworkPtr network, int flags) virResetLastError(); if (!VIR_IS_CONNECTED_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (NULL); } if (flags != 0) { - virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__); + virLibNetworkError(network, VIR_ERR_INVALID_ARG); goto error; } @@ -6365,7 +6367,7 @@ virNetworkGetBridgeName(virNetworkPtr network) virResetLastError(); if (!VIR_IS_CONNECTED_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (NULL); } @@ -6408,12 +6410,12 @@ virNetworkGetAutostart(virNetworkPtr network, virResetLastError(); if (!VIR_IS_CONNECTED_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (-1); } if (!autostart) { - virLibNetworkError(network, VIR_ERR_INVALID_ARG, __FUNCTION__); + virLibNetworkError(network, VIR_ERR_INVALID_ARG); goto error; } @@ -6454,13 +6456,13 @@ virNetworkSetAutostart(virNetworkPtr network, virResetLastError(); if (!VIR_IS_CONNECTED_NETWORK(network)) { - virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK, __FUNCTION__); + virLibNetworkError(NULL, VIR_ERR_INVALID_NETWORK); virDispatchError(NULL); return (-1); } if (network->conn->flags & VIR_CONNECT_RO) { - virLibNetworkError(network, VIR_ERR_OPERATION_DENIED, __FUNCTION__); + virLibNetworkError(network, VIR_ERR_OPERATION_DENIED); goto error; } -- 1.7.0.1 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list