* [PATCH] iproute2: devlink: use sys/queue.h from libbsd as a fallback
@ 2019-07-24 8:18 Sergei Trofimovich
2019-07-26 18:29 ` Stephen Hemminger
0 siblings, 1 reply; 4+ messages in thread
From: Sergei Trofimovich @ 2019-07-24 8:18 UTC (permalink / raw)
To: netdev; +Cc: Sergei Trofimovich, Stephen Hemminger
On sys/queue.h does not exist linux-musl targets and
fails build as:
devlink.c:28:10: fatal error: sys/queue.h: No such file or directory
28 | #include <sys/queue.h>
| ^~~~~~~~~~~~~
The change pulls in 'sys/queue.h' from libbsd in case
system headers don't already provides it.
Tested on linux-musl and linux-glibc.
Bug: https://bugs.gentoo.org/690486
CC: Stephen Hemminger <stephen@networkplumber.org>
CC: netdev@vger.kernel.org
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
---
configure | 30 ++++++++++++++++++++++++++++++
devlink/devlink.c | 9 ++++++++-
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/configure b/configure
index 45fcffb6..a1ee946f 100755
--- a/configure
+++ b/configure
@@ -323,6 +323,33 @@ check_cap()
fi
}
+check_sys_queue()
+{
+ cat >$TMPDIR/queue_test.c <<EOF
+#include <sys/queue.h>
+struct nest_qentry {
+ int attr_type;
+ TAILQ_ENTRY(nest_qentry) nest_entries;
+};
+int main(int argc, char **argv) {
+ return 0;
+}
+EOF
+ if $CC -I$INCLUDE -o $TMPDIR/queue_test $TMPDIR/queue_test.c >/dev/null 2>&1; then
+ echo "no"
+ else
+ if ${PKG_CONFIG} libbsd --exists; then
+ echo 'CFLAGS += -DHAVE_LIBBSD_SYS_QUEUE' `${PKG_CONFIG} libbsd --cflags` >>$CONFIG
+ echo 'LDLIBS +=' `${PKG_CONFIG} libbsd --libs` >> $CONFIG
+ echo "no"
+ else
+ echo 'CFLAGS += -DNEED_SYS_QUEUE' >>$CONFIG
+ echo "yes"
+ fi
+ fi
+ rm -f $TMPDIR/queue_test.c $TMPDIR/queue_test
+}
+
quiet_config()
{
cat <<EOF
@@ -398,6 +425,9 @@ check_strlcpy
echo -n "libcap support: "
check_cap
+echo -n "need for sys/queue.h API: "
+check_sys_queue
+
echo >> $CONFIG
echo "%.o: %.c" >> $CONFIG
echo ' $(QUIET_CC)$(CC) $(CFLAGS) $(EXTRA_CFLAGS) $(CPPFLAGS) -c -o $@ $<' >> $CONFIG
diff --git a/devlink/devlink.c b/devlink/devlink.c
index bb023c0c..fd91198c 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -25,7 +25,14 @@
#include <linux/devlink.h>
#include <libmnl/libmnl.h>
#include <netinet/ether.h>
-#include <sys/queue.h>
+#ifdef HAVE_LIBBSD_SYS_QUEUE
+# include <bsd/sys/queue.h>
+#else
+# include <sys/queue.h>
+#endif
+#ifdef NEED_SYS_QUEUE
+# error "No <sys/queue.h> implementation found."
+#endif
#include "SNAPSHOT.h"
#include "list.h"
--
2.22.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] iproute2: devlink: use sys/queue.h from libbsd as a fallback
2019-07-24 8:18 [PATCH] iproute2: devlink: use sys/queue.h from libbsd as a fallback Sergei Trofimovich
@ 2019-07-26 18:29 ` Stephen Hemminger
2019-07-26 21:01 ` [PATCH v2] iproute2: devlink: port from sys/queue.h to list.h Sergei Trofimovich
0 siblings, 1 reply; 4+ messages in thread
From: Stephen Hemminger @ 2019-07-26 18:29 UTC (permalink / raw)
To: Sergei Trofimovich; +Cc: netdev
On Wed, 24 Jul 2019 09:18:38 +0100
Sergei Trofimovich <slyfox@gentoo.org> wrote:
> On sys/queue.h does not exist linux-musl targets and
> fails build as:
>
> devlink.c:28:10: fatal error: sys/queue.h: No such file or directory
> 28 | #include <sys/queue.h>
> | ^~~~~~~~~~~~~
>
> The change pulls in 'sys/queue.h' from libbsd in case
> system headers don't already provides it.
>
> Tested on linux-musl and linux-glibc.
>
> Bug: https://bugs.gentoo.org/690486
> CC: Stephen Hemminger <stephen@networkplumber.org>
> CC: netdev@vger.kernel.org
> Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
> ---
This is ugly and causes more maintainability issues.
Maybe just fix devlink not to depend on sys/queue.h at all.
It makes more sense to have common code style and usage across all of
iproute2.
We already have local version list.h, why continue with BSD stuff.
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v2] iproute2: devlink: port from sys/queue.h to list.h
2019-07-26 18:29 ` Stephen Hemminger
@ 2019-07-26 21:01 ` Sergei Trofimovich
2019-07-26 22:02 ` Stephen Hemminger
0 siblings, 1 reply; 4+ messages in thread
From: Sergei Trofimovich @ 2019-07-26 21:01 UTC (permalink / raw)
To: Stephen Hemminger; +Cc: Sergei Trofimovich, netdev
sys/queue.h does not exist on linux-musl targets and fails build as:
devlink.c:28:10: fatal error: sys/queue.h: No such file or directory
28 | #include <sys/queue.h>
| ^~~~~~~~~~~~~
The change ports to list.h API and drops dependency of 'sys/queue.h'.
The API maps one-to-one.
Build-tested on linux-musl and linux-glibc.
Bug: https://bugs.gentoo.org/690486
CC: Stephen Hemminger <stephen@networkplumber.org>
CC: netdev@vger.kernel.org
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
---
devlink/devlink.c | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/devlink/devlink.c b/devlink/devlink.c
index bb023c0c..0ea401ae 100644
--- a/devlink/devlink.c
+++ b/devlink/devlink.c
@@ -25,7 +25,6 @@
#include <linux/devlink.h>
#include <libmnl/libmnl.h>
#include <netinet/ether.h>
-#include <sys/queue.h>
#include "SNAPSHOT.h"
#include "list.h"
@@ -5981,13 +5980,13 @@ static int fmsg_value_show(struct dl *dl, int type, struct nlattr *nl_data)
struct nest_qentry {
int attr_type;
- TAILQ_ENTRY(nest_qentry) nest_entries;
+ struct list_head nest_entries;
};
struct fmsg_cb_data {
struct dl *dl;
uint8_t value_type;
- TAILQ_HEAD(, nest_qentry) qhead;
+ struct list_head qhead;
};
static int cmd_fmsg_nest_queue(struct fmsg_cb_data *fmsg_data,
@@ -6001,13 +6000,13 @@ static int cmd_fmsg_nest_queue(struct fmsg_cb_data *fmsg_data,
return -ENOMEM;
entry->attr_type = *attr_value;
- TAILQ_INSERT_HEAD(&fmsg_data->qhead, entry, nest_entries);
+ list_add(&fmsg_data->qhead, &entry->nest_entries);
} else {
- if (TAILQ_EMPTY(&fmsg_data->qhead))
+ if (list_empty(&fmsg_data->qhead))
return MNL_CB_ERROR;
- entry = TAILQ_FIRST(&fmsg_data->qhead);
+ entry = list_first_entry(&fmsg_data->qhead, struct nest_qentry, nest_entries);
*attr_value = entry->attr_type;
- TAILQ_REMOVE(&fmsg_data->qhead, entry, nest_entries);
+ list_del(&entry->nest_entries);
free(entry);
}
return MNL_CB_OK;
@@ -6116,7 +6115,7 @@ static int cmd_health_object_common(struct dl *dl, uint8_t cmd, uint16_t flags)
return err;
data.dl = dl;
- TAILQ_INIT(&data.qhead);
+ INIT_LIST_HEAD(&data.qhead);
err = _mnlg_socket_sndrcv(dl->nlg, nlh, cmd_fmsg_object_cb, &data);
return err;
}
--
2.22.0
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] iproute2: devlink: port from sys/queue.h to list.h
2019-07-26 21:01 ` [PATCH v2] iproute2: devlink: port from sys/queue.h to list.h Sergei Trofimovich
@ 2019-07-26 22:02 ` Stephen Hemminger
0 siblings, 0 replies; 4+ messages in thread
From: Stephen Hemminger @ 2019-07-26 22:02 UTC (permalink / raw)
To: Sergei Trofimovich; +Cc: netdev
On Fri, 26 Jul 2019 22:01:05 +0100
Sergei Trofimovich <slyfox@gentoo.org> wrote:
> sys/queue.h does not exist on linux-musl targets and fails build as:
>
> devlink.c:28:10: fatal error: sys/queue.h: No such file or directory
> 28 | #include <sys/queue.h>
> | ^~~~~~~~~~~~~
>
> The change ports to list.h API and drops dependency of 'sys/queue.h'.
> The API maps one-to-one.
>
> Build-tested on linux-musl and linux-glibc.
>
> Bug: https://bugs.gentoo.org/690486
> CC: Stephen Hemminger <stephen@networkplumber.org>
> CC: netdev@vger.kernel.org
> Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Looks good, thanks for following through.
Applied.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-07-26 22:02 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-24 8:18 [PATCH] iproute2: devlink: use sys/queue.h from libbsd as a fallback Sergei Trofimovich
2019-07-26 18:29 ` Stephen Hemminger
2019-07-26 21:01 ` [PATCH v2] iproute2: devlink: port from sys/queue.h to list.h Sergei Trofimovich
2019-07-26 22:02 ` Stephen Hemminger
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.