bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: On OpenBSD and if_freenameindex(3).


From: Eric Blake
Subject: Re: On OpenBSD and if_freenameindex(3).
Date: Tue, 21 Sep 2010 15:27:54 -0600
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100907 Fedora/3.1.3-1.fc13 Mnenhy/0.8.3 Thunderbird/3.1.3

On 09/21/2010 02:41 PM, Simon Josefsson wrote:
Eric Blake<address@hidden>  writes:

On 09/21/2010 06:22 AM, Simon Josefsson wrote:
As an initial response to this problem, I'm installing a self check of
the net/if.h interface.  See below.  Mats, if you could quote the
compiler errors you get when building the self-check below on OpenBSD,
that would be useful.  The next step is to see how gnulib can provide a
replacement that works on various systems.  Perhaps OpenBSD isn't the
only system not working here.

+#include<net/if.h>
+#include<stddef.h>  /* NULL */
+#include<stdio.h>  /* printf */
+
+int
+main (int argc, char *argv[])
+{
+  struct if_nameindex ifn, *ifnp, *p;
+  void (*if_fni) (struct if_nameindex *) = if_freenameindex;

Rather than doing this via a struct in main(), after you have already
dragged in other headers, it would be nicer to use "signature.h" and
do signature validation at the top of the file.  Would you like me to
prepare a patch along those lines?

Yes please do and push it.  I haven't used the signature.h mechanism (or
I have forgotten how to), so I'll learn if you post the patch.

It turns out that MirBSD has the same bug regarding if_freenameindex not being a function. So I've gone ahead and documented that; we can update the documentation when we implement the net_if (replacement header) and if_freenameindex (function implementation) modules.

Also, if the test fails, it should print to stderr, not stdout.

Meanwhile, we have generally been writing the tests so that the header test only checks things guaranteed by the header replacement with no other function modules in use, such as macros like IF_NAMESIZE and types like struct if_nameindex; while leaving signature checks up to the modules that actually replace functions. But until we have any function modules, then the header test is the right place to test signatures. So, when we actually implement an if_freenameindex module, we'll probably rearrange part of this test into a new test file. But I've run out of time for implementing net_if and if_freenameindex today, so here's what I'm pushing now:


diff --git i/ChangeLog w/ChangeLog
index 088122e..9434ba5 100644
--- i/ChangeLog
+++ w/ChangeLog
@@ -1,3 +1,11 @@
+2010-09-21  Eric Blake  <address@hidden>
+
+       net_if: enhance tests
+       * tests/test-net_if.c (main): Move signature checks earlier.
+       Print failures to stderr.
+       * doc/posix-functions/if_freenameindex.texi (if_freenameindex):
+       Document the bug that we do not yet fix.
+
 2010-09-21  Reuben Thomas  <address@hidden>

        * doc/gnulib.texi (Out of memory handling): Rewrite section to be
diff --git i/doc/posix-functions/if_freenameindex.texi w/doc/posix-functions/if_freenameindex.texi
index 97cdc9f..1dcf096 100644
--- i/doc/posix-functions/if_freenameindex.texi
+++ w/doc/posix-functions/if_freenameindex.texi
@@ -14,5 +14,11 @@ if_freenameindex
 @itemize
 @item
 This function is missing on some platforms:
-OpenBSD 3.8, HP-UX 11, IRIX 6.5, OSF/1 4.0, Solaris 7, Cygwin 1.5.x, mingw, Interix 3.5, BeOS.
+OpenBSD 3.8, HP-UX 11, IRIX 6.5, OSF/1 4.0, Solaris 7, Cygwin 1.5.x,
+mingw, Interix 3.5, BeOS.
+
address@hidden
+This is available only as a macro, rather than a function, on some
+platforms:
+OpenBSD 4.6, MirBSD 10.
 @end itemize
diff --git i/modules/net_if-tests w/modules/net_if-tests
index 4349e85..ace657d 100644
--- i/modules/net_if-tests
+++ w/modules/net_if-tests
@@ -1,5 +1,6 @@
 Files:
 tests/test-net_if.c
+tests/signature.h

 Depends-on:

diff --git i/tests/test-net_if.c w/tests/test-net_if.c
index f1cdb99..15926ff 100644
--- i/tests/test-net_if.c
+++ w/tests/test-net_if.c
@@ -17,32 +17,33 @@
 /* Written by Simon Josefsson <address@hidden>, 2010.  */

 #include <config.h>
+
 #include <net/if.h>
+
+#include "signature.h"
+SIGNATURE_CHECK (if_freenameindex, void, (struct if_nameindex *));
+SIGNATURE_CHECK (if_indextoname, char *, (unsigned int, char *));
+SIGNATURE_CHECK (if_nameindex, struct if_nameindex *, (void));
+SIGNATURE_CHECK (if_nametoindex, unsigned int, (const char *));
+
 #include <stddef.h> /* NULL */
-#include <stdio.h> /* printf */
+#include <stdio.h> /* fprintf */

 int
 main (int argc, char *argv[])
 {
-  struct if_nameindex ifn, *ifnp, *p;
-  void (*if_fni) (struct if_nameindex *) = if_freenameindex;
-  char *(*if_itn)(unsigned, char *) = if_indextoname;
-  struct if_nameindex  *(*if_ni)(void) = if_nameindex;
-  unsigned (*if_nti)(const char *) = if_nametoindex;
-
-  ifn.if_index = 42;
-  ifn.if_name = "foo";
+  struct if_nameindex *ifnp, *p;

   p = ifnp = if_nameindex ();
   if (ifnp == NULL)
     {
-      printf ("if_nameindex returned NULL\n");
+      fputs ("if_nameindex returned NULL\n", stderr);
       return 1;
     }

   while (p->if_index)
     {
-      unsigned idx;
+      unsigned int idx;
       char buf[IF_NAMESIZE];
       char *q;

@@ -52,25 +53,26 @@ main (int argc, char *argv[])
       idx = if_nametoindex (p->if_name);
       if (idx != p->if_index)
         {
-          printf ("if_nametoindex (%s) = %d != %d\n",
-                  p->if_name, idx, p->if_index);
+          fprintf (stderr, "if_nametoindex (%s) = %d != %d\n",
+                   p->if_name, idx, p->if_index);
           return 1;
         }

       q = if_indextoname (p->if_index, buf);
       if (q == NULL)
         {
-          printf ("if_indextoname (%d) returned NULL\n", p->if_index);
+ fprintf (stderr, "if_indextoname (%d) returned NULL\n", p->if_index);
           return 1;
         }
       if (q != buf)
         {
-          printf ("if_indextoname (%d) buffer mismatch?\n", p->if_index);
+          fprintf (stderr, "if_indextoname (%d) buffer mismatch?\n",
+                   p->if_index);
           return 1;
         }
       if (strcmp (p->if_name, q) != 0)
         {
-          printf ("if_indextoname (%s) = %s ?!\n", p->if_name, q);
+          fprintf (stderr, "if_indextoname (%s) = %s ?!\n", p->if_name, q);
           return 1;
         }



--
Eric Blake   address@hidden    +1-801-349-2682
Libvirt virtualization library http://libvirt.org



reply via email to

[Prev in Thread] Current Thread [Next in Thread]