]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: avoid accidentally using files from gnulib
authorDaniel P. Berrangé <berrange@redhat.com>
Thu, 8 Aug 2019 09:23:26 +0000 (10:23 +0100)
committerDaniel P. Berrangé <berrange@redhat.com>
Thu, 8 Aug 2019 12:32:02 +0000 (13:32 +0100)
The AM_CPPFLAGS setting includes the gnulib headers, which
means we can get some replacement functions defined. Since
virt-login-shell and the NSS module intentionally don't link
to gnulib, these replacement functions causes link failures.

This was seen cross-compiling on Debian for example:

virt-login-shell.o: In function `main':
/builds/libvirt/libvirt/build/tools/../../tools/virt-login-shell.c:81: undefined reference to `rpl_strerror'
/builds/libvirt/libvirt/build/tools/../../tools/virt-login-shell.c:66: undefined reference to `rpl_strerror'
/builds/libvirt/libvirt/build/tools/../../tools/virt-login-shell.c:75: undefined reference to `rpl_strerror'

The only way to avoid these replacement gnulib headers is
to drop the -Ignulib/lib flags. We do still want to use
gnulib for configmake.h and intprops.h, but those can be
included via their full path.

We must also stop using internal.h, since that expects
-Ignulib/lib to be on the include path in order to resolve
the verify.h header.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
cfg.mk
tools/Makefile.am
tools/nss/libvirt_nss.c
tools/nss/libvirt_nss_leases.c
tools/nss/libvirt_nss_leases.h
tools/nss/libvirt_nss_macs.c
tools/nss/libvirt_nss_macs.h
tools/virt-login-shell.c

diff --git a/cfg.mk b/cfg.mk
index 85b5a0a5a2db4620a554eabff1807ef22dc2893d..c459ad443fe4caf3f51aad41eef36bf1ba9ad669 100644 (file)
--- a/cfg.mk
+++ b/cfg.mk
@@ -1346,3 +1346,6 @@ exclude_file_name_regexp--sc_prohibit_cross_inclusion = \
 
 exclude_file_name_regexp--sc_prohibit_dirent_d_type = \
   ^(src/util/vircgroup.c)$
+
+exclude_file_name_regexp--sc_prohibit_strcmp = \
+  ^(tools/nss/libvirt_nss.*\.c)
index 09cada949b96d973b077e81a78aa1819689c572d..df3d628bab976ace0c08f5cd9510b2bab8e102d4 100644 (file)
@@ -23,6 +23,12 @@ AM_CPPFLAGS = \
        -I$(top_srcdir) \
        $(NULL)
 
+# We do not want to accidentally include stuff from gnulib
+# or the main src/ dir or public API dir. Specific files can
+# still be included via their path relative to the root if
+# needed
+STANDALONE_CPPFLAGS = -I$(top_srcdir)
+
 WARN_CFLAGS += $(STRICT_FRAME_LIMIT_CFLAGS)
 
 AM_CFLAGS = \
@@ -199,6 +205,8 @@ virt_host_validate_CFLAGS = \
 virt_login_shell_SOURCES = \
                virt-login-shell.c
 
+virt_login_shell_CPPFLAGS = $(STANDALONE_CPPFLAGS)
+
 virt_login_shell_helper_SOURCES = \
                virt-login-shell-helper.c
 
@@ -486,6 +494,7 @@ noinst_LTLIBRARIES += nss/libnss_libvirt_impl.la
 nss_libnss_libvirt_impl_la_SOURCES = \
        $(LIBVIRT_NSS_SOURCES)
 
+nss_libnss_libvirt_impl_la_CPPFLAGS = $(STANDALONE_CPPFLAGS)
 nss_libnss_libvirt_impl_la_CFLAGS = \
        -DLIBVIRT_NSS \
        $(YAJL_CFLAGS) \
@@ -516,6 +525,7 @@ nss_libnss_libvirt_guest_impl_la_SOURCES = \
        nss/libvirt_nss_macs.c \
        $(NULL)
 
+nss_libnss_libvirt_guest_impl_la_CPPFLAGS = $(STANDALONE_CPPFLAGS)
 nss_libnss_libvirt_guest_impl_la_CFLAGS = \
        -DLIBVIRT_NSS \
        -DLIBVIRT_NSS_GUEST \
index 7122065b284e38d851d54ca53d586dd97977f2d8..b75f51c560890c9dda4c463550bc07f634596106 100644 (file)
@@ -32,6 +32,8 @@
 #include <dirent.h>
 #include <arpa/inet.h>
 #include <stdlib.h>
+#include <stdbool.h>
+#include <errno.h>
 #include <string.h>
 #include <time.h>
 
 # include <nsswitch.h>
 #endif
 
-#include "configmake.h"
+/*
+ * This gnulib files is used for its macros only,
+ * so doesn't introduce a link time dep, which we
+ * must avoid
+ */
+#include "gnulib/lib/configmake.h"
 
 #include "libvirt_nss_leases.h"
 
@@ -131,7 +138,7 @@ findLease(const char *name,
         char *path;
         size_t dlen = strlen(entry->d_name);
 
-        if (dlen >= 7 && STREQ(entry->d_name + dlen - 7, ".status")) {
+        if (dlen >= 7 && !strcmp(entry->d_name + dlen - 7, ".status")) {
             char **tmpLease;
             if (asprintf(&path, "%s/%s", leaseDir, entry->d_name) < 0)
                 goto cleanup;
@@ -142,7 +149,7 @@ findLease(const char *name,
             leaseFiles = tmpLease;
             leaseFiles[nleaseFiles++] = path;
 #if defined(LIBVIRT_NSS_GUEST)
-        } else if (dlen >= 5 && STREQ(entry->d_name + dlen - 5, ".macs")) {
+        } else if (dlen >= 5 && !strcmp(entry->d_name + dlen - 5, ".macs")) {
             if (asprintf(&path, "%s/%s", leaseDir, entry->d_name) < 0)
                 goto cleanup;
 
index 48a54d58418063f57742dc64563aa6494c215dcb..86881641a9293df477855c808c206607bed12f04 100644 (file)
@@ -23,6 +23,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <fcntl.h>
 
 #include <yajl/yajl_gen.h>
@@ -60,7 +61,7 @@ typedef struct {
 
 
 static int
-appendAddr(const char *name ATTRIBUTE_UNUSED,
+appendAddr(const char *name __attribute__((unused)),
            leaseAddress **tmpAddress,
            size_t *ntmpAddress,
            const char *ipAddr,
@@ -165,7 +166,7 @@ findLeasesParserInteger(void *ctx,
         return 0;
 
     if (parser->state == FIND_LEASES_STATE_ENTRY) {
-        if (STRNEQ(parser->key, "expiry-time"))
+        if (strcmp(parser->key, "expiry-time"))
             return 0;
 
         parser->entry.expiry = val;
@@ -190,13 +191,13 @@ findLeasesParserString(void *ctx,
         return 0;
 
     if (parser->state == FIND_LEASES_STATE_ENTRY) {
-        if (STREQ(parser->key, "ip-address")) {
+        if (!strcmp(parser->key, "ip-address")) {
             if (!(parser->entry.ipaddr = strndup((char *)stringVal, stringLen)))
                 return 0;
-        } else if (STREQ(parser->key, "mac-address")) {
+        } else if (!strcmp(parser->key, "mac-address")) {
             if (!(parser->entry.macaddr = strndup((char *)stringVal, stringLen)))
                 return 0;
-        } else if (STREQ(parser->key, "hostname")) {
+        } else if (!strcmp(parser->key, "hostname")) {
             if (!(parser->entry.hostname = strndup((char *)stringVal, stringLen)))
                 return 0;
         } else {
@@ -264,12 +265,12 @@ findLeasesParserEndMap(void *ctx)
         DEBUG("Check %zu macs", parser->nmacs);
         for (i = 0; i < parser->nmacs && !found; i++) {
             DEBUG("Check mac '%s' vs '%s'", parser->macs[i], NULLSTR(parser->entry.macaddr));
-            if (STREQ_NULLABLE(parser->macs[i], parser->entry.macaddr))
+            if (parser->entry.macaddr && !strcmp(parser->macs[i], parser->entry.macaddr))
                 found = true;
         }
     } else {
         DEBUG("Check name '%s' vs '%s'", parser->name, NULLSTR(parser->entry.hostname));
-        if (STREQ_NULLABLE(parser->name, parser->entry.hostname))
+        if (parser->entry.hostname && !strcmp(parser->name, parser->entry.hostname))
             found = true;
     }
     DEBUG("Found %d", found);
index e213681e4665515381067f362c89331115d8a8ab..c451742152eb812095ec612a97d03a4c50ede84e 100644 (file)
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include "internal.h"
+#include <sys/types.h>
 
 typedef struct {
     unsigned char addr[16];
index fb5526bd7ba3470d85520956ecacd486a537cdc7..26ba4bf5158f2aca9de1c916eaf802109e31af56 100644 (file)
@@ -67,7 +67,7 @@ findMACsParserString(void *ctx,
         return 0;
 
     if (parser->state == FIND_MACS_STATE_ENTRY) {
-        if (STRNEQ(parser->key, "domain"))
+        if (strcmp(parser->key, "domain"))
             return 0;
 
         free(parser->entry.name);
@@ -75,7 +75,7 @@ findMACsParserString(void *ctx,
             return 0;
     } else if (parser->state == FIND_MACS_STATE_ENTRY_MACS) {
         char **macs;
-        if (STRNEQ(parser->key, "macs"))
+        if (strcmp(parser->key, "macs"))
             return 0;
 
         if (!(macs = realloc(parser->entry.macs,
@@ -142,7 +142,7 @@ findMACsParserEndMap(void *ctx)
     if (parser->state != FIND_MACS_STATE_ENTRY)
         return 0;
 
-    if (STREQ(parser->entry.name, parser->name)) {
+    if (!strcmp(parser->entry.name, parser->name)) {
         char **macs = realloc(*parser->macs,
                               sizeof(char *) * ((*parser->nmacs) + parser->entry.nmacs));
         if (!macs)
index 64e291f549c7541749915f62f0cdf8f121bf66b3..2774f3a9f2d2081a79373c0bf0fdf74a4154537b 100644 (file)
@@ -20,7 +20,7 @@
 
 #pragma once
 
-#include "internal.h"
+#include <sys/types.h>
 
 int
 findMACs(const char *file,
index 41d0b349aa3bab58ba8e48b34e3b5ce9ddd96141..f92cc0a74912423a14cf0032410a8577f250ac8f 100644 (file)
 #include <errno.h>
 #include <string.h>
 
-#include "configmake.h"
-#include "intprops.h"
+/*
+ * These gnulib files are used for their macros only,
+ * so don't introduce a link time dep, which we must avoid
+ */
+#include "gnulib/lib/configmake.h"
+#include "gnulib/lib/intprops.h"
 
 int main(int argc, char **argv) {
     char uidstr[INT_BUFSIZE_BOUND(uid_t)];