2014-03-14 09:59:24

by Natanael Copa

[permalink] [raw]
Subject: [PATCH 0/3] Various build fixes for building bluez with musl libc

The following fixes are needed to make bluez build on Alpine Linuz with
musl libc.

This is kind of a rebase of the previously posted patches:
http://www.spinics.net/lists/linux-bluetooth/msg43070.html

Changes since then are:
- mention Alpine Linux in commit message
- rebase to current git
- added fix for proper header include for be32toh, htobe32 and htobe64

Please note that "unit: prevent unintended use of glibc's error(3)"
fixes a bug in the unit test that affects glibc too. I suppose that if
you add a testcase that triggers any error logging from sdpd-request.c
it will likely segfault instead of gracfully hande the error condition.
(it only affects the unit test though)

Natanael Copa (3):
shared: include endian.h for be32toh, htobe32 and htobe64 functions
unit: prevent unintended use of glibc's error(3)
bnep: avoid use of caddr_t

Makefile.am | 1 +
profiles/network/bnep.c | 4 ++--
src/shared/btsnoop.c | 1 +
unit/test-sdp.c | 9 +++------
4 files changed, 7 insertions(+), 8 deletions(-)

--
1.9.0



2014-03-14 11:30:31

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 0/3] Various build fixes for building bluez with musl libc

Hi,

On Fri, Mar 14, 2014, Johan Hedberg wrote:
> On Fri, Mar 14, 2014, Natanael Copa wrote:
> > The following fixes are needed to make bluez build on Alpine Linuz with
> > musl libc.
> >
> > This is kind of a rebase of the previously posted patches:
> > http://www.spinics.net/lists/linux-bluetooth/msg43070.html
> >
> > Changes since then are:
> > - mention Alpine Linux in commit message
> > - rebase to current git
> > - added fix for proper header include for be32toh, htobe32 and htobe64
> >
> > Please note that "unit: prevent unintended use of glibc's error(3)"
> > fixes a bug in the unit test that affects glibc too. I suppose that if
> > you add a testcase that triggers any error logging from sdpd-request.c
> > it will likely segfault instead of gracfully hande the error condition.
> > (it only affects the unit test though)
> >
> > Natanael Copa (3):
> > shared: include endian.h for be32toh, htobe32 and htobe64 functions
> > unit: prevent unintended use of glibc's error(3)
> > bnep: avoid use of caddr_t
> >
> > Makefile.am | 1 +
> > profiles/network/bnep.c | 4 ++--
> > src/shared/btsnoop.c | 1 +
> > unit/test-sdp.c | 9 +++------
> > 4 files changed, 7 insertions(+), 8 deletions(-)
>
> I've applied patches 1 and 3, but am waiting for a v2 on patch 2 since
> it breaks the build:
>
> unit/test-sdp.c: In function ‘main’:
> unit/test-sdp.c:795:3: error: implicit declaration of function ‘__btd_log_init’ [-Werror=implicit-function-declaration]
> __btd_log_init("*", 0);

I went ahead and fixed the missing include myself. The patch is now
applied.

Johan

2014-03-14 11:07:19

by Johan Hedberg

[permalink] [raw]
Subject: Re: [PATCH 0/3] Various build fixes for building bluez with musl libc

Hi Natanael,

On Fri, Mar 14, 2014, Natanael Copa wrote:
> The following fixes are needed to make bluez build on Alpine Linuz with
> musl libc.
>
> This is kind of a rebase of the previously posted patches:
> http://www.spinics.net/lists/linux-bluetooth/msg43070.html
>
> Changes since then are:
> - mention Alpine Linux in commit message
> - rebase to current git
> - added fix for proper header include for be32toh, htobe32 and htobe64
>
> Please note that "unit: prevent unintended use of glibc's error(3)"
> fixes a bug in the unit test that affects glibc too. I suppose that if
> you add a testcase that triggers any error logging from sdpd-request.c
> it will likely segfault instead of gracfully hande the error condition.
> (it only affects the unit test though)
>
> Natanael Copa (3):
> shared: include endian.h for be32toh, htobe32 and htobe64 functions
> unit: prevent unintended use of glibc's error(3)
> bnep: avoid use of caddr_t
>
> Makefile.am | 1 +
> profiles/network/bnep.c | 4 ++--
> src/shared/btsnoop.c | 1 +
> unit/test-sdp.c | 9 +++------
> 4 files changed, 7 insertions(+), 8 deletions(-)

I've applied patches 1 and 3, but am waiting for a v2 on patch 2 since
it breaks the build:

unit/test-sdp.c: In function ‘main’:
unit/test-sdp.c:795:3: error: implicit declaration of function ‘__btd_log_init’ [-Werror=implicit-function-declaration]
__btd_log_init("*", 0);

Johan

2014-03-14 09:59:27

by Natanael Copa

[permalink] [raw]
Subject: [PATCH 3/3] bnep: avoid use of caddr_t

caddr_t is legacy BSD and should be avoided.

This fixes the following compile error on Alpine Linux with musl libc:
profiles/network/bnep.c: In function 'bnep_if_up':
profiles/network/bnep.c:205:33: error: 'caddr_t' undeclared (first use in this function)
err = ioctl(sk, SIOCSIFFLAGS, (caddr_t) &ifr);
---

For more details please see:
http://stackoverflow.com/questions/6381526/what-is-the-significance-of-caddr-t-and-when-is-it-used

profiles/network/bnep.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/profiles/network/bnep.c b/profiles/network/bnep.c
index ece979f..b93027a 100644
--- a/profiles/network/bnep.c
+++ b/profiles/network/bnep.c
@@ -204,7 +204,7 @@ static int bnep_if_up(const char *devname)
ifr.ifr_flags |= IFF_UP;
ifr.ifr_flags |= IFF_MULTICAST;

- err = ioctl(sk, SIOCSIFFLAGS, (caddr_t) &ifr);
+ err = ioctl(sk, SIOCSIFFLAGS, (void *) &ifr);

close(sk);

@@ -229,7 +229,7 @@ static int bnep_if_down(const char *devname)
ifr.ifr_flags &= ~IFF_UP;

/* Bring down the interface */
- err = ioctl(sk, SIOCSIFFLAGS, (caddr_t) &ifr);
+ err = ioctl(sk, SIOCSIFFLAGS, (void *) &ifr);

close(sk);

--
1.9.0


2014-03-14 09:59:25

by Natanael Copa

[permalink] [raw]
Subject: [PATCH 1/3] shared: include endian.h for be32toh, htobe32 and htobe64 functions

The man page says that #include <endian.h> is needed for those.

This fixes the following compile error when building with musl libc on
Alpine Linux:

src/shared/btsnoop.o: In function `btsnoop_write':
.../src/bluez/src/shared/btsnoop.c:208: undefined reference to `htobe32'
.../src/bluez/src/shared/btsnoop.c:209: undefined reference to `htobe32'
.../src/bluez/src/shared/btsnoop.c:210: undefined reference to `htobe32'
.../src/bluez/src/shared/btsnoop.c:211: undefined reference to `htobe32'
.../src/bluez/src/shared/btsnoop.c:212: undefined reference to `htobe64'
src/shared/btsnoop.o: In function `btsnoop_open':
.../src/bluez/src/shared/btsnoop.c:100: undefined reference to `be32toh'
.../src/bluez/src/shared/btsnoop.c:103: undefined reference to `be32toh'
src/shared/btsnoop.o: In function `btsnoop_create':
.../src/bluez/src/shared/btsnoop.c:151: undefined reference to `htobe32'
.../src/bluez/src/shared/btsnoop.c:152: undefined reference to `htobe32'
src/shared/btsnoop.o: In function `pklg_read_hci':
.../src/bluez/src/shared/btsnoop.c:336: undefined reference to `be32toh'
.../src/bluez/src/shared/btsnoop.c:338: undefined reference to `be64toh'
src/shared/btsnoop.o: In function `btsnoop_read_hci':
.../src/bluez/src/shared/btsnoop.c:416: undefined reference to `be32toh'
.../src/bluez/src/shared/btsnoop.c:417: undefined reference to `be32toh'
.../src/bluez/src/shared/btsnoop.c:419: undefined reference to `be64toh'
---

This was introduced with 83afd2d1a (shared: Use be32toh, htobe32 and
htobe64 functions)

src/shared/btsnoop.c | 1 +
1 file changed, 1 insertion(+)

diff --git a/src/shared/btsnoop.c b/src/shared/btsnoop.c
index d2b3b4b..17a872c 100644
--- a/src/shared/btsnoop.c
+++ b/src/shared/btsnoop.c
@@ -25,6 +25,7 @@
#include <config.h>
#endif

+#include <endian.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
--
1.9.0


2014-03-14 09:59:26

by Natanael Copa

[permalink] [raw]
Subject: [PATCH 2/3] unit: prevent unintended use of glibc's error(3)

When building the test-sdp we don't want src/sdpd-request.c end up
using the incompatible GNU libc's error(3) instead of the intended
src/log.c's error().

This also fixes the following compile error on Alpine Linux with musl
libc which does not implement the error(3) GNU extension:

src/sdpd-request.o: In function `extract_des':
/home/ncopa/src/bluez/src/sdpd-request.c:126: undefined reference to `error'
src/sdpd-request.o: In function `process_request':
/home/ncopa/src/bluez/src/sdpd-request.c:1022: undefined reference to `error'
/home/ncopa/src/bluez/src/sdpd-request.c:1045: undefined reference to `error'
---
Makefile.am | 1 +
unit/test-sdp.c | 9 +++------
2 files changed, 4 insertions(+), 6 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index fb11230..700b956 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -265,6 +265,7 @@ unit_tests += unit/test-sdp
unit_test_sdp_SOURCES = unit/test-sdp.c \
src/shared/util.h src/shared/util.c \
src/sdpd.h src/sdpd-database.c \
+ src/log.h src/log.c \
src/sdpd-service.c src/sdpd-request.c
unit_test_sdp_LDADD = lib/libbluetooth-internal.la @GLIB_LIBS@

diff --git a/unit/test-sdp.c b/unit/test-sdp.c
index 9b82343..853576d 100644
--- a/unit/test-sdp.c
+++ b/unit/test-sdp.c
@@ -128,12 +128,6 @@ static void sdp_debug(const char *str, void *user_data)
g_print("%s%s\n", prefix, str);
}

-void btd_debug(const char *format, ...);
-
-void btd_debug(const char *format, ...)
-{
-}
-
static void context_quit(struct context *context)
{
g_main_loop_quit(context->main_loop);
@@ -797,6 +791,9 @@ int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);

+ if (g_test_verbose())
+ __btd_log_init("*", 0);
+
/*
* Service Search Request
*
--
1.9.0