All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iproute2] Use libbsd for strlcpy if available
@ 2018-10-29 10:46 Luca Boccassi
  2018-10-29 15:27 ` David Ahern
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Luca Boccassi @ 2018-10-29 10:46 UTC (permalink / raw)
  To: netdev; +Cc: stephen, dsahern

If libc does not provide strlcpy check for libbsd with pkg-config to
avoid relying on inline version.

Signed-off-by: Luca Boccassi <bluca@debian.org>
---
This allows distro maintainers to be able to choose to reduce
duplication and let this code be maintained in one place, in the
external library.

 configure | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 744d6282..1dd9ce84 100755
--- a/configure
+++ b/configure
@@ -330,8 +330,16 @@ EOF
     then
 	echo "no"
     else
-	echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
-	echo "yes"
+	if ${PKG_CONFIG} libbsd --exists
+	then
+		echo 'CFLAGS += -include' `${PKG_CONFIG} libbsd --variable=includedir`'/bsd/string.h' \
+			`${PKG_CONFIG} libbsd --cflags` >>$CONFIG
+		echo 'LDLIBS +=' `${PKG_CONFIG} libbsd --libs` >> $CONFIG
+		echo "no"
+	else
+		echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
+		echo "yes"
+	fi
     fi
     rm -f $TMPDIR/strtest.c $TMPDIR/strtest
 }
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2] Use libbsd for strlcpy if available
  2018-10-29 10:46 [PATCH iproute2] Use libbsd for strlcpy if available Luca Boccassi
@ 2018-10-29 15:27 ` David Ahern
  2018-10-29 15:37   ` Luca Boccassi
  2018-10-31 15:09 ` Stephen Hemminger
  2018-10-31 18:00 ` [PATCH iproute2 v2] " Luca Boccassi
  2 siblings, 1 reply; 6+ messages in thread
From: David Ahern @ 2018-10-29 15:27 UTC (permalink / raw)
  To: Luca Boccassi, netdev; +Cc: stephen

On 10/29/18 4:46 AM, Luca Boccassi wrote:
> If libc does not provide strlcpy check for libbsd with pkg-config to
> avoid relying on inline version.
> 
> Signed-off-by: Luca Boccassi <bluca@debian.org>
> ---
> This allows distro maintainers to be able to choose to reduce
> duplication and let this code be maintained in one place, in the
> external library.
> 
>  configure | 12 ++++++++++--
>  1 file changed, 10 insertions(+), 2 deletions(-)
> 
> diff --git a/configure b/configure
> index 744d6282..1dd9ce84 100755
> --- a/configure
> +++ b/configure
> @@ -330,8 +330,16 @@ EOF
>      then
>  	echo "no"
>      else
> -	echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
> -	echo "yes"
> +	if ${PKG_CONFIG} libbsd --exists
> +	then
> +		echo 'CFLAGS += -include' `${PKG_CONFIG} libbsd --variable=includedir`'/bsd/string.h' \
> +			`${PKG_CONFIG} libbsd --cflags` >>$CONFIG
> +		echo 'LDLIBS +=' `${PKG_CONFIG} libbsd --libs` >> $CONFIG
> +		echo "no"
> +	else
> +		echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
> +		echo "yes"
> +	fi
>      fi
>      rm -f $TMPDIR/strtest.c $TMPDIR/strtest
>  }
> 

How long has libbsd had an implementation of strlcpy? Would be safer to
have a compile test to verify libbsd has it.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2] Use libbsd for strlcpy if available
  2018-10-29 15:27 ` David Ahern
@ 2018-10-29 15:37   ` Luca Boccassi
  0 siblings, 0 replies; 6+ messages in thread
From: Luca Boccassi @ 2018-10-29 15:37 UTC (permalink / raw)
  To: David Ahern, netdev; +Cc: stephen

[-- Attachment #1: Type: text/plain, Size: 1610 bytes --]

On Mon, 2018-10-29 at 09:27 -0600, David Ahern wrote:
> On 10/29/18 4:46 AM, Luca Boccassi wrote:
> > If libc does not provide strlcpy check for libbsd with pkg-config
> > to
> > avoid relying on inline version.
> > 
> > Signed-off-by: Luca Boccassi <bluca@debian.org>
> > ---
> > This allows distro maintainers to be able to choose to reduce
> > duplication and let this code be maintained in one place, in the
> > external library.
> > 
> >  configure | 12 ++++++++++--
> >  1 file changed, 10 insertions(+), 2 deletions(-)
> > 
> > diff --git a/configure b/configure
> > index 744d6282..1dd9ce84 100755
> > --- a/configure
> > +++ b/configure
> > @@ -330,8 +330,16 @@ EOF
> >      then
> >  	echo "no"
> >      else
> > -	echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
> > -	echo "yes"
> > +	if ${PKG_CONFIG} libbsd --exists
> > +	then
> > +		echo 'CFLAGS += -include' `${PKG_CONFIG} libbsd --
> > variable=includedir`'/bsd/string.h' \
> > +			`${PKG_CONFIG} libbsd --cflags` >>$CONFIG
> > +		echo 'LDLIBS +=' `${PKG_CONFIG} libbsd --libs` >>
> > $CONFIG
> > +		echo "no"
> > +	else
> > +		echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
> > +		echo "yes"
> > +	fi
> >      fi
> >      rm -f $TMPDIR/strtest.c $TMPDIR/strtest
> >  }
> > 
> 
> How long has libbsd had an implementation of strlcpy? Would be safer
> to
> have a compile test to verify libbsd has it.

Hi,

0.0 from 10+ years ago has it, so I think we are safe :-)

https://gitlab.freedesktop.org/libbsd/libbsd/blob/0.0/include/bsd/string.h#L34

-- 
Kind regards,
Luca Boccassi

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2] Use libbsd for strlcpy if available
  2018-10-29 10:46 [PATCH iproute2] Use libbsd for strlcpy if available Luca Boccassi
  2018-10-29 15:27 ` David Ahern
@ 2018-10-31 15:09 ` Stephen Hemminger
  2018-10-31 17:54   ` Luca Boccassi
  2018-10-31 18:00 ` [PATCH iproute2 v2] " Luca Boccassi
  2 siblings, 1 reply; 6+ messages in thread
From: Stephen Hemminger @ 2018-10-31 15:09 UTC (permalink / raw)
  To: Luca Boccassi; +Cc: netdev, dsahern

On Mon, 29 Oct 2018 10:46:50 +0000
Luca Boccassi <bluca@debian.org> wrote:

> If libc does not provide strlcpy check for libbsd with pkg-config to
> avoid relying on inline version.
> 
> Signed-off-by: Luca Boccassi <bluca@debian.org>
> ---
> This allows distro maintainers to be able to choose to reduce
> duplication and let this code be maintained in one place, in the
> external library.
> 

I like the idea, but it causes warnings on Debian testing, and maybe other distros.

ipnetns.c:2: warning: "_ATFILE_SOURCE" redefined
 #define _ATFILE_SOURCE
 
In file included from /usr/include/x86_64-linux-gnu/bits/libc-header-start.h:33,
                 from /usr/include/string.h:26,
                 from /usr/include/bsd/string.h:30,
                 from <command-line>:
/usr/include/features.h:326: note: this is the location of the previous definition
 # define _ATFILE_SOURCE 1


Please figure out how to handle this and resubmit.  SUSE open build service might
also work to test multiple distro's

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH iproute2] Use libbsd for strlcpy if available
  2018-10-31 15:09 ` Stephen Hemminger
@ 2018-10-31 17:54   ` Luca Boccassi
  0 siblings, 0 replies; 6+ messages in thread
From: Luca Boccassi @ 2018-10-31 17:54 UTC (permalink / raw)
  To: Stephen Hemminger; +Cc: netdev, dsahern

[-- Attachment #1: Type: text/plain, Size: 2177 bytes --]

On Wed, 2018-10-31 at 08:09 -0700, Stephen Hemminger wrote:
> On Mon, 29 Oct 2018 10:46:50 +0000
> Luca Boccassi <bluca@debian.org> wrote:
> 
> > If libc does not provide strlcpy check for libbsd with pkg-config
> > to
> > avoid relying on inline version.
> > 
> > Signed-off-by: Luca Boccassi <bluca@debian.org>
> > ---
> > This allows distro maintainers to be able to choose to reduce
> > duplication and let this code be maintained in one place, in the
> > external library.
> > 
> 
> I like the idea, but it causes warnings on Debian testing, and maybe
> other distros.
> 
> ipnetns.c:2: warning: "_ATFILE_SOURCE" redefined
>  #define _ATFILE_SOURCE
>  
> In file included from /usr/include/x86_64-linux-gnu/bits/libc-header-
> start.h:33,
>                  from /usr/include/string.h:26,
>                  from /usr/include/bsd/string.h:30,
>                  from <command-line>:
> /usr/include/features.h:326: note: this is the location of the
> previous definition
>  # define _ATFILE_SOURCE 1
> 
> 
> Please figure out how to handle this and resubmit.  SUSE open build
> service might
> also work to test multiple distro's

Ah missed that. That happens because features.h defines _ATFILE_SOURCE
to 1, but ip/ipnetns.c defines it without a value. According to the
spec either way doesn't change the result.

This happens because of the quick hack of using -include
/usr/include/bsd/string.h which was, well, a quick hack and didn't
require to add the include manually everywhere strlcpy was used, even
in the future. But it has side effects like this.

So I'll send v2 with a less hacky fix, which means defining HAVE_LIBBSD
in configure and doing #ifdef HAVE_LIBBSD #include <bsd/string.h> in
every file. It also means that this needs to be done for every future
use of strlcpy, or the build with libbsd will break.

If you or David prefer the hacky way, I can instead send a v3 that does
the quick hack, and also changes _ATFILE_SOURCE to 1 so that there is
no complaint from the compiler, as the values will be the same.

-- 
Kind regards,
Luca Boccassi

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH iproute2 v2] Use libbsd for strlcpy if available
  2018-10-29 10:46 [PATCH iproute2] Use libbsd for strlcpy if available Luca Boccassi
  2018-10-29 15:27 ` David Ahern
  2018-10-31 15:09 ` Stephen Hemminger
@ 2018-10-31 18:00 ` Luca Boccassi
  2 siblings, 0 replies; 6+ messages in thread
From: Luca Boccassi @ 2018-10-31 18:00 UTC (permalink / raw)
  To: netdev; +Cc: stephen, dsahern

If libc does not provide strlcpy check for libbsd with pkg-config to
avoid relying on inline version.

Signed-off-by: Luca Boccassi <bluca@debian.org>
---
Changed from -include /usr/include/bsd/string.h hack to HAVE_LIBBSD
and proper includes in each file that uses strlcpy.
The hack causes a compiler warning as ip/ipnetns.c defines
_ATFILE_SOURCE without a value, but system headers use 1, so there's
a mismatch.

 configure             | 11 +++++++++--
 genl/ctrl.c           |  3 +++
 ip/iplink.c           |  3 +++
 ip/ipnetns.c          |  3 +++
 ip/iproute_lwtunnel.c |  3 +++
 ip/ipvrf.c            |  3 +++
 ip/ipxfrm.c           |  3 +++
 ip/tunnel.c           |  3 +++
 ip/xfrm_state.c       |  3 +++
 lib/bpf.c             |  3 +++
 lib/fs.c              |  3 +++
 lib/inet_proto.c      |  3 +++
 misc/ss.c             |  3 +++
 tc/em_ipset.c         |  3 +++
 tc/m_pedit.c          |  3 +++
 15 files changed, 51 insertions(+), 2 deletions(-)

diff --git a/configure b/configure
index 744d6282..c5655978 100755
--- a/configure
+++ b/configure
@@ -330,8 +330,15 @@ EOF
     then
 	echo "no"
     else
-	echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
-	echo "yes"
+	if ${PKG_CONFIG} libbsd --exists
+	then
+		echo 'CFLAGS += -DHAVE_LIBBSD' `${PKG_CONFIG} libbsd --cflags` >>$CONFIG
+		echo 'LDLIBS +=' `${PKG_CONFIG} libbsd --libs` >> $CONFIG
+		echo "no"
+	else
+		echo 'CFLAGS += -DNEED_STRLCPY' >>$CONFIG
+		echo "yes"
+	fi
     fi
     rm -f $TMPDIR/strtest.c $TMPDIR/strtest
 }
diff --git a/genl/ctrl.c b/genl/ctrl.c
index 6133336a..fef6aaa9 100644
--- a/genl/ctrl.c
+++ b/genl/ctrl.c
@@ -18,6 +18,9 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 
 #include "utils.h"
 #include "genl_utils.h"
diff --git a/ip/iplink.c b/ip/iplink.c
index b5519201..067f5409 100644
--- a/ip/iplink.c
+++ b/ip/iplink.c
@@ -24,6 +24,9 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <sys/ioctl.h>
 #include <stdbool.h>
 #include <linux/mpls.h>
diff --git a/ip/ipnetns.c b/ip/ipnetns.c
index 0eac18cf..da019d76 100644
--- a/ip/ipnetns.c
+++ b/ip/ipnetns.c
@@ -8,6 +8,9 @@
 #include <sys/syscall.h>
 #include <stdio.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <sched.h>
 #include <fcntl.h>
 #include <dirent.h>
diff --git a/ip/iproute_lwtunnel.c b/ip/iproute_lwtunnel.c
index 8f497015..2285bc1d 100644
--- a/ip/iproute_lwtunnel.c
+++ b/ip/iproute_lwtunnel.c
@@ -16,6 +16,9 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <linux/ila.h>
 #include <linux/lwtunnel.h>
 #include <linux/mpls_iptunnel.h>
diff --git a/ip/ipvrf.c b/ip/ipvrf.c
index 8a6b7f97..8572b4f2 100644
--- a/ip/ipvrf.c
+++ b/ip/ipvrf.c
@@ -21,6 +21,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <dirent.h>
 #include <errno.h>
 #include <limits.h>
diff --git a/ip/ipxfrm.c b/ip/ipxfrm.c
index 17ab4abe..b02f30a6 100644
--- a/ip/ipxfrm.c
+++ b/ip/ipxfrm.c
@@ -28,6 +28,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <time.h>
diff --git a/ip/tunnel.c b/ip/tunnel.c
index d0d55f37..73abb2e2 100644
--- a/ip/tunnel.c
+++ b/ip/tunnel.c
@@ -24,6 +24,9 @@
 
 #include <stdio.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <unistd.h>
 #include <errno.h>
 #include <sys/types.h>
diff --git a/ip/xfrm_state.c b/ip/xfrm_state.c
index e8c01746..18e0c6fa 100644
--- a/ip/xfrm_state.c
+++ b/ip/xfrm_state.c
@@ -27,6 +27,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <netdb.h>
 #include "utils.h"
 #include "xfrm.h"
diff --git a/lib/bpf.c b/lib/bpf.c
index 45f279fa..35d7c45a 100644
--- a/lib/bpf.c
+++ b/lib/bpf.c
@@ -15,6 +15,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <stdbool.h>
 #include <stdint.h>
 #include <errno.h>
diff --git a/lib/fs.c b/lib/fs.c
index 86efd4ed..af36bea0 100644
--- a/lib/fs.c
+++ b/lib/fs.c
@@ -20,6 +20,9 @@
 #include <stdlib.h>
 #include <unistd.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <errno.h>
 #include <limits.h>
 
diff --git a/lib/inet_proto.c b/lib/inet_proto.c
index 0836a4c9..b379d8f8 100644
--- a/lib/inet_proto.c
+++ b/lib/inet_proto.c
@@ -18,6 +18,9 @@
 #include <netinet/in.h>
 #include <netdb.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 
 #include "rt_names.h"
 #include "utils.h"
diff --git a/misc/ss.c b/misc/ss.c
index 4d12fb5d..c472fbd9 100644
--- a/misc/ss.c
+++ b/misc/ss.c
@@ -19,6 +19,9 @@
 #include <sys/sysmacros.h>
 #include <netinet/in.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <errno.h>
 #include <netdb.h>
 #include <arpa/inet.h>
diff --git a/tc/em_ipset.c b/tc/em_ipset.c
index 48b287f5..550b2101 100644
--- a/tc/em_ipset.c
+++ b/tc/em_ipset.c
@@ -20,6 +20,9 @@
 #include <netdb.h>
 #include <unistd.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <stdlib.h>
 #include <getopt.h>
 
diff --git a/tc/m_pedit.c b/tc/m_pedit.c
index 2aeb56d9..baacc80d 100644
--- a/tc/m_pedit.c
+++ b/tc/m_pedit.c
@@ -23,6 +23,9 @@
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <string.h>
+#ifdef HAVE_LIBBSD
+#include <bsd/string.h>
+#endif
 #include <dlfcn.h>
 #include "utils.h"
 #include "tc_util.h"
-- 
2.19.1

^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2018-11-01  2:59 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-29 10:46 [PATCH iproute2] Use libbsd for strlcpy if available Luca Boccassi
2018-10-29 15:27 ` David Ahern
2018-10-29 15:37   ` Luca Boccassi
2018-10-31 15:09 ` Stephen Hemminger
2018-10-31 17:54   ` Luca Boccassi
2018-10-31 18:00 ` [PATCH iproute2 v2] " Luca Boccassi

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.