util: consolidate duplicated error messages in virnetlink.c

There are special stub versions of all public functions in this file
that are compiled when either libnl isn't available or the platform
isn't linux. Each of these functions had two almost identical message,
differing only in the function name included in the message. Since log
messages already contain the function name, we can just define a const
char* with the common part of the string, and use that same string for
all the log messages.

Also, rather than doing #if defined ... #else ... #endif *inside the
error log macro invocation*, this patch does #if defined ... just
once, using it to decide which single string to define. This turns the
error log in each function from 6 lines, to 1 line.
This commit is contained in:
Laine Stump 2012-03-06 12:21:21 -05:00
parent d403b84cf3
commit 879bcee08c

View File

@ -525,17 +525,18 @@ cleanup:
#else
# if defined(__linux)
static const char *unsupported = N_("libnl was not available at build time");
# else
static const char *unsupported = N_("not supported on non-linux platforms");
# endif
int virNetlinkCommand(struct nl_msg *nl_msg ATTRIBUTE_UNUSED,
unsigned char **respbuf ATTRIBUTE_UNUSED,
unsigned int *respbuflen ATTRIBUTE_UNUSED,
int nl_pid ATTRIBUTE_UNUSED)
{
netlinkError(VIR_ERR_INTERNAL_ERROR, "%s",
# if defined(__linux__) && !defined(HAVE_LIBNL)
_("virNetlinkCommand is not supported since libnl was not available"));
# else
_("virNetlinkCommand is not supported on non-linux platforms"));
# endif
netlinkError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
}
@ -545,11 +546,7 @@ int virNetlinkCommand(struct nl_msg *nl_msg ATTRIBUTE_UNUSED,
*/
int virNetlinkEventServiceStop(void)
{
# if defined(__linux__) && !defined(HAVE_LIBNL)
netlinkError(VIR_ERR_INTERNAL_ERROR,
"%s",
_("virNetlinkEventServiceStop is not supported since libnl was not available"));
# endif
netlinkError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return 0;
}
@ -559,11 +556,7 @@ int virNetlinkEventServiceStop(void)
*/
int virNetlinkEventServiceStart(void)
{
# if defined(__linux__) && !defined(HAVE_LIBNL)
netlinkError(VIR_ERR_INTERNAL_ERROR,
"%s",
_("virNetlinkEventServiceStart is not supported since libnl was not available"));
# endif
netlinkError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return 0;
}
@ -573,11 +566,7 @@ int virNetlinkEventServiceStart(void)
*/
bool virNetlinkEventServiceIsRunning(void)
{
# if defined(__linux__) && !defined(HAVE_LIBNL)
netlinkError(VIR_ERR_INTERNAL_ERROR,
"%s",
_("virNetlinkEventServiceIsRunning is not supported since libnl was not available"));
# endif
netlinkError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return 0;
}
@ -590,13 +579,7 @@ int virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB ATTRIBUTE_UN
void *opaque ATTRIBUTE_UNUSED,
const unsigned char *macaddr ATTRIBUTE_UNUSED)
{
netlinkError(VIR_ERR_INTERNAL_ERROR,
"%s",
# if defined(__linux__) && !defined(HAVE_LIBNL)
_("virNetlinkEventServiceAddClient is not supported since libnl was not available"));
# else
_("virNetlinkEventServiceAddClient is not supported on non-linux platforms"));
# endif
netlinkError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
}
@ -606,13 +589,7 @@ int virNetlinkEventAddClient(virNetlinkEventHandleCallback handleCB ATTRIBUTE_UN
int virNetlinkEventRemoveClient(int watch ATTRIBUTE_UNUSED,
const unsigned char *macaddr ATTRIBUTE_UNUSED)
{
netlinkError(VIR_ERR_INTERNAL_ERROR,
"%s",
# if defined(__linux__) && !defined(HAVE_LIBNL)
_("virNetlinkEventRemoveClient is not supported since libnl was not available"));
# else
_("virNetlinkEventRemoveClient is not supported on non-linux platforms"));
# endif
netlinkError(VIR_ERR_INTERNAL_ERROR, "%s", _(unsupported));
return -1;
}