[PATCH 64/73] acpid: Fix build on musl

Khem Raj
2016-01-17T11:37:56Z

implement isfdtype() if libc does not provide it

Fix build when S != B

use top_builddir instead of top_srcdir

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
meta/recipes-bsp/acpid/acpid.inc | 2 +
...1-Define-isfdtype-if-libc-doesn-t-have-it.patch | 62 ++++++++++++++++++++++
...-config.h-from-builddir-instead-of-srcdir.patch | 51 ++++++++++++++++++
3 files changed, 115 insertions(+)
create mode 100644 meta/recipes-bsp/acpid/acpid/0001-Define-isfdtype-if-libc-doesn-t-have-it.patch
create mode 100644 meta/recipes-bsp/acpid/acpid/0001-Use-config.h-from-builddir-instead-of-srcdir.patch

diff --git a/meta/recipes-bsp/acpid/acpid.inc b/meta/recipes-bsp/acpid/acpid.inc
index e015619..1d1ce98 100644
--- a/meta/recipes-bsp/acpid/acpid.inc
+++ b/meta/recipes-bsp/acpid/acpid.inc
@@ -5,6 +5,8 @@ SECTION = "base"
LICENSE = "GPLv2+"

SRC_URI = "${SOURCEFORGE_MIRROR}/acpid2/acpid-${PV}.tar.xz \
+ file://0001-Define-isfdtype-if-libc-doesn-t-have-it.patch \
+ file://0001-Use-config.h-from-builddir-instead-of-srcdir.patch \
file://init \
file://acpid.service \
"
diff --git a/meta/recipes-bsp/acpid/acpid/0001-Define-isfdtype-if-libc-doesn-t-have-it.patch b/meta/recipes-bsp/acpid/acpid/0001-Define-isfdtype-if-libc-doesn-t-have-it.patch
new file mode 100644
index 0000000..9ffae30
--- /dev/null
+++ b/meta/recipes-bsp/acpid/acpid/0001-Define-isfdtype-if-libc-doesn-t-have-it.patch
@@ -0,0 +1,62 @@
+From 61c9d448e2f18ed46b1a18fe82113e7c75f64d7e Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Tue, 12 Jan 2016 08:18:08 +0000
+Subject: [PATCH] Define isfdtype() if libc doesn't have it.
+
+musl does not implement isfdtype() so don't assume libc will always
+provide it, instead check for it and provide an implementation if libc
+doesn't provide one.
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+Upstream-Status: Submitted
+
+ configure.ac | 2 +-
+ sock.c | 12 +++++++++++-
+ 2 files changed, 12 insertions(+), 2 deletions(-)
+
+diff --git a/configure.ac b/configure.ac
+index 241db45..8cef8a4 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -41,7 +41,7 @@ AC_CHECK_FUNC(fstatat, AC_DEFINE(HAVE_FSTATAT, 1, "Define if fstatat() exists"),
+ AC_CHECK_FUNC(openat, AC_DEFINE(HAVE_OPENAT, 1, "Define if openat() exists"), AC_MSG_ERROR(["openat() not found"]))
+ AC_CHECK_FUNC(asprintf, AC_DEFINE(HAVE_ASPRINTF, 1, "Define if asprintf() exists"), AC_MSG_ERROR(["asprintf() not found"]))
+ # These are actually required. Should switch to above form.
+-AC_CHECK_FUNCS([alarm dup2 memset regcomp select socket strcasecmp strdup strerror strrchr strtol])
++AC_CHECK_FUNCS([alarm dup2 isfdtype memset regcomp select socket strcasecmp strdup strerror strrchr strtol])
+
+ # removed for now as kacpimon was not included in dist target
+ #AC_ARG_ENABLE([kacpimon],AS_HELP_STRING([--enable-kacpimon], [Build kacpimon]))
+diff --git a/sock.c b/sock.c
+index 31f816d..546e1b2 100644
+--- a/sock.c
++++ b/sock.c
+@@ -50,13 +50,23 @@ int clientmax = ACPID_CLIENTMAX;
+ /* the number of non-root clients that are connected */
+ int non_root_clients;
+
++#ifndef HAVE_ISFDTYPE
++static int
++isfdtype (int fd, int fdtype)
++{
++ struct stat64 st;
++ if (fstat64 (fd, &st) != 0)
++ return -1;
++ return ((st.st_mode & S_IFMT) == (mode_t) fdtype);
++}
++#endif
++
+ /* determine if a file descriptor is in fact a socket */
+ int
+ is_socket(int fd)
+ {
+ return (isfdtype(fd, S_IFSOCK) == 1);
+ }
+-
+ /* accept a new client connection */
+ static void
+ process_sock(int fd)
+--
+2.7.0
+
diff --git a/meta/recipes-bsp/acpid/acpid/0001-Use-config.h-from-builddir-instead-of-srcdir.patch b/meta/recipes-bsp/acpid/acpid/0001-Use-config.h-from-builddir-instead-of-srcdir.patch
new file mode 100644
index 0000000..81f2215
--- /dev/null
+++ b/meta/recipes-bsp/acpid/acpid/0001-Use-config.h-from-builddir-instead-of-srcdir.patch
@@ -0,0 +1,51 @@
+From df452e28eccead1ca04cff228bc7cf55413e5b0c Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Tue, 12 Jan 2016 09:35:07 -0800
+Subject: [PATCH] Use config.h from builddir instead of srcdir
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+Upstream-Status: Submitted
+
+ Changelog | 3 +++
+ Makefile.am | 4 ++--
+ 2 files changed, 5 insertions(+), 2 deletions(-)
+
+diff --git a/Changelog b/Changelog
+index a9bcaeb..17afd08 100644
+--- a/Changelog
++++ b/Changelog
+@@ -6,6 +6,9 @@
+ - Fix missing libc_compat.h in release tarball.
+ (Makefile.am kacpimon/Makefile.am kacpimon/libc_compat.h)
+ (Ted Felix)
++ - Fix out of tree build.
++ (Makefile.am)
++ (Khem Raj)
+
+ * Sat Aug 15 2015 Ted Felix <ted@tedfelix.com>
+ - 2.0.24 release
+diff --git a/Makefile.am b/Makefile.am
+index a27e0fe..417528f 100644
+--- a/Makefile.am
++++ b/Makefile.am
+@@ -7,7 +7,7 @@
+ SUBDIRS = kacpimon
+
+ AM_CFLAGS = -Wall -Wmissing-declarations -Wmissing-prototypes -Wredundant-decls -Wshadow -Wstrict-prototypes -Wformat=2
+-AM_CPPFLAGS = -include $(top_srcdir)/config.h
++AM_CPPFLAGS = -include $(top_builddir)/config.h
+
+ sbin_PROGRAMS = acpid
+ bin_PROGRAMS = acpi_listen
+@@ -23,6 +23,6 @@ dist_man8_MANS = acpid.8 acpi_listen.8
+ dist_doc_DATA = COPYING Changelog README TESTPLAN TODO
+
+ # Just docs to add to the dist.
+-# One problem with this is that it includes all files in the samples dir
++# One problem with this is that it includes all files in the samples dir
+ # including editor backups ending in ~. It's the best we've got for now.
+ EXTRA_DIST = acpid-design.odg samples
+--
+2.7.0
+
--
2.7.0