[netlabel_tools] Add patch to support libnl3, Use %%license, Cleanup spec

Peter Robinson pbrobinson at fedoraproject.org
Sat Mar 21 13:53:16 UTC 2015


commit 0a49d8afa240553b6ca3facc4a419ff0439434a7
Author: Peter Robinson <pbrobinson at gmail.com>
Date:   Sat Mar 21 13:53:08 2015 +0000

    Add patch to support libnl3, Use %%license, Cleanup spec

 0001-Port-to-libnl3.patch | 222 ++++++++++++++++++++++++++++++++++++++++++++++
 netlabel_tools.spec       |  25 ++++--
 2 files changed, 239 insertions(+), 8 deletions(-)
---
diff --git a/0001-Port-to-libnl3.patch b/0001-Port-to-libnl3.patch
new file mode 100644
index 0000000..e9e7f6d
--- /dev/null
+++ b/0001-Port-to-libnl3.patch
@@ -0,0 +1,222 @@
+From d82ed2081cf58fb2504ba037d7a1e6444ec5019a Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Cristian=20Rodr=C3=ADguez?= <crrodriguez at opensuse.org>
+Date: Wed, 28 May 2014 00:11:37 -0400
+Subject: [PATCH] Port to libnl3
+
+---
+ libnetlabel/netlabel_comm.c     | 35 -----------------------------
+ libnetlabel/netlabel_internal.h | 49 +++++++----------------------------------
+ libnetlabel/netlabel_msg.c      |  4 ----
+ macros.mk                       |  2 +-
+ netlabelctl/Makefile            |  2 +-
+ 5 files changed, 10 insertions(+), 82 deletions(-)
+
+diff --git a/libnetlabel/netlabel_comm.c b/libnetlabel/netlabel_comm.c
+index 289629b..02869e8 100644
+--- a/libnetlabel/netlabel_comm.c
++++ b/libnetlabel/netlabel_comm.c
+@@ -102,13 +102,8 @@ struct nlbl_handle *nlbl_comm_open(void)
+ 		goto open_failure;
+ 
+ 	/* set the netlink handle properties */
+-#if LIBNL_VERSION >= 1008
+ 	nl_socket_set_peer_port(hndl->nl_hndl, 0);
+ 	nl_set_passcred(hndl->nl_hndl, 1);
+-#elif LIBNL_VERSION == 1006
+-	nl_handle_set_peer_pid(hndl->nl_hndl, 0);
+-	nl_set_passcred(hndl->nl_hndl, 1);
+-#endif
+ 	nl_disable_sequence_check(hndl->nl_hndl);
+ 
+ 	/* connect to the generic netlink subsystem in the kernel */
+@@ -177,11 +172,7 @@ int nlbl_comm_recv_raw(struct nlbl_handle *hndl, unsigned char **data)
+ 	 * no data is waiting to be read from the handle */
+ 	timeout.tv_sec = nlcomm_read_timeout;
+ 	timeout.tv_usec = 0;
+-#if LIBNL_VERSION >= 1008
+ 	nl_fd = nl_socket_get_fd(hndl->nl_hndl);
+-#else
+-	nl_fd = nl_handle_get_fd(hndl->nl_hndl);
+-#endif
+ 	FD_ZERO(&read_fds);
+ 	FD_SET(nl_fd, &read_fds);
+ 	ret_val = select(nl_fd + 1, &read_fds, NULL, NULL, &timeout);
+@@ -192,15 +183,9 @@ int nlbl_comm_recv_raw(struct nlbl_handle *hndl, unsigned char **data)
+ 
+ 	/* perform the read operation */
+ 	*data = NULL;
+-#if LIBNL_VERSION >= 1006
+ 	ret_val = nl_recv(hndl->nl_hndl, &peer_nladdr, data, &creds);
+ 	if (ret_val < 0)
+ 		return ret_val;
+-#else
+-	ret_val = nl_recv(hndl->nl_hndl, &peer_nladdr, data);
+-	if (ret_val < 0)
+-		return ret_val;
+-#endif
+ 
+ 	/* if we are setup to receive credentials, only accept messages from
+ 	 * the kernel (ignore all others and send an -EAGAIN) */
+@@ -251,11 +236,7 @@ int nlbl_comm_recv(struct nlbl_handle *hndl, nlbl_msg **msg)
+ 	 * no data is waiting to be read from the handle */
+ 	timeout.tv_sec = nlcomm_read_timeout;
+ 	timeout.tv_usec = 0;
+-#if LIBNL_VERSION >= 1008
+ 	nl_fd = nl_socket_get_fd(hndl->nl_hndl);
+-#else
+-	nl_fd = nl_handle_get_fd(hndl->nl_hndl);
+-#endif
+ 	FD_ZERO(&read_fds);
+ 	FD_SET(nl_fd, &read_fds);
+ 	ret_val = select(nl_fd + 1, &read_fds, NULL, NULL, &timeout);
+@@ -265,19 +246,9 @@ int nlbl_comm_recv(struct nlbl_handle *hndl, nlbl_msg **msg)
+ 		return -EAGAIN;
+ 
+ 	/* perform the read operation */
+-#if LIBNL_VERSION >= 1100
+ 	ret_val = nl_recv(hndl->nl_hndl, &peer_nladdr, &data, &creds);
+ 	if (ret_val < 0)
+ 		return ret_val;
+-#elif LIBNL_VERSION >= 1006
+-	ret_val = nl_recv(hndl->nl_hndl, &peer_nladdr, data, &creds);
+-	if (ret_val < 0)
+-		return ret_val;
+-#else
+-	ret_val = nl_recv(hndl->nl_hndl, &peer_nladdr, data);
+-	if (ret_val < 0)
+-		return ret_val;
+-#endif
+ 
+ 	/* if we are setup to receive credentials, only accept messages from
+ 	 * the kernel (ignore all others and send an -EAGAIN) */
+@@ -344,9 +315,7 @@ int nlbl_comm_send(struct nlbl_handle *hndl, nlbl_msg *msg)
+ 	creds.gid = getegid();
+ 
+ 	/* set the message properties */
+-#if LIBNL_VERSION >= 1006
+ 	nlmsg_set_creds(msg, &creds);
+-#endif
+ 
+ 	/* request a netlink ack message */
+ 	nl_hdr = nlbl_msg_nlhdr(msg);
+@@ -355,9 +324,5 @@ int nlbl_comm_send(struct nlbl_handle *hndl, nlbl_msg *msg)
+ 	nl_hdr->nlmsg_flags |= NLM_F_ACK;
+ 
+ 	/* send the message */
+-#if LIBNL_VERSION == 1005
+-	return nl_send_auto_complete(hndl->nl_hndl, nlbl_msg_nlhdr(msg));
+-#elif LIBNL_VERSION >= 1006
+ 	return nl_send_auto_complete(hndl->nl_hndl, msg);
+-#endif
+ }
+diff --git a/libnetlabel/netlabel_internal.h b/libnetlabel/netlabel_internal.h
+index acc2f03..54200af 100644
+--- a/libnetlabel/netlabel_internal.h
++++ b/libnetlabel/netlabel_internal.h
+@@ -27,6 +27,14 @@
+ 
+ #include <netlink/netlink.h>
+ 
++#define nl_handle_alloc             nl_socket_alloc
++#define nl_handle_destroy           nl_socket_free
++#define nl_handle                   nl_sock
++#define nlmsg_build(ptr)            nlmsg_inherit(ptr)
++#define nl_set_passcred             nl_socket_set_passcred
++#define nl_disable_sequence_check   nl_socket_disable_seq_check
++#define nlmsg_len                   nlmsg_datalen
++
+ /* NetLabel communication handle */
+ struct nlbl_handle {
+ 	struct nl_handle *nl_hndl;
+@@ -37,46 +45,5 @@ struct nlbl_handle {
+ 	 (((hdr)->nlmsg_flags & NLM_F_MULTI) && \
+ 	  ((hdr)->nlmsg_type != NLMSG_DONE)))
+ 
+-/* Specify which version of libnl we are using */
+-/*  1.0-pre5 => 1005 */
+-/*  1.0-pre6 => 1006 */
+-/*  1.0-pre8 => 1008 */
+-/*  1.1      => 1100 */
+-#define LIBNL_VERSION		1100
+-
+-/* XXX - this whole block will most likely go away once libnl supports Generic
+- * Netlink */
+-#if LIBNL_VERSION <= 1006 /* Generic Netlink types */
+-
+-/* Generic Netlink message header */
+-struct genlmsghdr {
+-	uint8_t cmd;
+-	uint8_t version;
+-	uint16_t reserved;
+-};
+-
+-#define GENL_ID_CTRL		0x10
+-
+-enum {
+-	CTRL_CMD_UNSPEC,
+-	CTRL_CMD_NEWFAMILY,
+-	CTRL_CMD_DELFAMILY,
+-	CTRL_CMD_GETFAMILY,
+-	CTRL_CMD_NEWOPS,
+-	CTRL_CMD_DELOPS,
+-	CTRL_CMD_GETOPS,
+-	__CTRL_CMD_MAX,
+-};
+-#define CTRL_CMD_MAX (__CTRL_CMD_MAX - 1)
+-
+-enum {
+-	CTRL_ATTR_UNSPEC,
+-	CTRL_ATTR_FAMILY_ID,
+-	CTRL_ATTR_FAMILY_NAME,
+-	__CTRL_ATTR_MAX,
+-};
+-#define CTRL_ATTR_MAX (__CTRL_ATTR_MAX - 1)
+-
+-#endif /* Generic Netlink types */
+ 
+ #endif
+diff --git a/libnetlabel/netlabel_msg.c b/libnetlabel/netlabel_msg.c
+index fb2fc58..af00fbe 100644
+--- a/libnetlabel/netlabel_msg.c
++++ b/libnetlabel/netlabel_msg.c
+@@ -63,11 +63,7 @@ nlbl_msg *nlbl_msg_new(void)
+ 	struct genlmsghdr genl_hdr;
+ 
+ 	/* create the message with a simple netlink header */
+-#if LIBNL_VERSION >= 1008
+ 	msg = nlmsg_alloc();
+-#else
+-	msg = nlmsg_build_no_hdr();
+-#endif
+ 	if (msg == NULL)
+ 		goto msg_new_failure;
+ 
+diff --git a/macros.mk b/macros.mk
+index a9466f0..b9f8813 100644
+--- a/macros.mk
++++ b/macros.mk
+@@ -53,7 +53,7 @@ CPPFLAGS += -I$(TOPDIR) -I$(TOPDIR)/include
+ LIBFLAGS =
+ 
+ CFLAGS ?= -Wl,-z,relro -Wall -O0 -g
+-CFLAGS += -fPIC
++CFLAGS += `pkg-config --cflags libnl-3.0` -fPIC
+ LDFLAGS ?= -z relro -g
+ 
+ #
+diff --git a/netlabelctl/Makefile b/netlabelctl/Makefile
+index 06af6a5..07cebbb 100644
+--- a/netlabelctl/Makefile
++++ b/netlabelctl/Makefile
+@@ -49,7 +49,7 @@ CONF_FILE = netlabel.rules
+ 
+ OBJS = main.o mgmt.o map.o unlabeled.o cipsov4.o
+ 
+-LDFLAGS := ../libnetlabel/libnetlabel.a -lnl -lm
++LDFLAGS := ../libnetlabel/libnetlabel.a `pkg-config --libs libnl-3.0` -lm
+ 
+ DEPS = $(OBJS:%.o=%.d)
+ 
+-- 
+1.8.4.5
+
diff --git a/netlabel_tools.spec b/netlabel_tools.spec
index f7ba64d..ce394ac 100644
--- a/netlabel_tools.spec
+++ b/netlabel_tools.spec
@@ -6,13 +6,15 @@ License: GPLv2
 Group: System Environment/Daemons
 URL: http://netlabel.sf.net/
 Source0: http://downloads.sourceforge.net/netlabel/%{name}-%{version}.tar.gz
-BuildRoot: %{_tmppath}/%{name}-%{version}
-Requires: kernel >= 2.6.19
+# http://sourceforge.net/p/netlabel/bugs/1/
+Patch0: 0001-Port-to-libnl3.patch
+
+Requires: kernel
 Requires(post): systemd
 Requires(preun): systemd
 Requires(postun): systemd
-BuildRequires: kernel-headers >= 2.6.19
-BuildRequires: libnl-devel
+BuildRequires: kernel-headers
+BuildRequires: libnl3-devel
 BuildRequires: doxygen
 BuildRequires: systemd
 
@@ -25,13 +27,13 @@ kernel subsystem.
 
 %prep
 %setup -q
+%patch0 -p1 -b .nl3
 
 %build
 ./configure --prefix="%{_prefix}" --libdir="%{_libdir}" --enable-systemd
 CFLAGS="%{optflags}" make V=1 %{?_smp_mflags}
 
 %install
-rm -rf "%{buildroot}"
 mkdir -p "%{buildroot}/etc"
 mkdir -p "%{buildroot}/%{_sbindir}"
 mkdir -p "%{buildroot}/%{_unitdir}"
@@ -42,14 +44,15 @@ make V=1 DESTDIR="%{buildroot}" install
 %systemd_preun netlabel.service
 
 %postun
-%systemd_postun
+%systemd_postun netlabel.service
 
 %post
 %systemd_post netlabel.service
 
 %files
-%defattr(-,root,root)
-%doc README CHANGELOG LICENSE
+%{!?_licensedir:%global license %%doc}
+%license LICENSE
+%doc README CHANGELOG
 %attr(0644,root,root) %{_mandir}/man8/*
 %attr(0755,root,root) %{_sbindir}/netlabelctl
 %attr(0755,root,root) %{_sbindir}/netlabel-config
@@ -57,6 +60,11 @@ make V=1 DESTDIR="%{buildroot}" install
 %attr(0644,root,root) %config(noreplace) /etc/netlabel.rules
 
 %changelog
+* Sat Mar 21 2015 Peter Robinson <pbrobinson at fedoraproject.org> 0.20-5
+- Add patch to support libnl3
+- Use %%license
+- Cleanup spec
+
 * Sun Aug 17 2014 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 0.20-4
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_21_22_Mass_Rebuild
 
@@ -65,6 +73,7 @@ make V=1 DESTDIR="%{buildroot}" install
 
 * Thu Feb 27 2014 Paul Moore <pmoore at redhat.com> - 0.20-2
 - Build with CFLAGS="${optflags}"
+
 * Sat Aug 03 2013 Fedora Release Engineering <rel-eng at lists.fedoraproject.org> - 0.20-1
 - Rebuilt for https://fedoraproject.org/wiki/Fedora_20_Mass_Rebuild
 


More information about the scm-commits mailing list