]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: consolidate duplicated error messages in virnetlink.c
authorLaine Stump <laine@laine.org>
Tue, 6 Mar 2012 17:21:21 +0000 (12:21 -0500)
committerLaine Stump <laine@laine.org>
Thu, 8 Mar 2012 21:58:09 +0000 (16:58 -0500)
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.

src/util/virnetlink.c

index 59f3e39e6fe8f68289bafca3a1cbbf197a9efd05..feb0fc70d838635e7e48545654600d1cacd873aa 100644 (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;
 }