Mail archive
alpine-aports

[alpine-aports] [PATCH v2 1/2] testing/nldev: new aport

From: Sören Tempel <soeren+git_at_soeren-tempel.net>
Date: Mon, 29 Feb 2016 22:58:39 +0100

---
 ...01-Revert-nldev-set-kernel-buffer-to-16kb.patch | 26 +++++++
 ...02-Preserve-the-PATH-environment-variable.patch | 46 +++++++++++
 ...Change-the-default-mdev-path-to-sbin-mdev.patch | 41 ++++++++++
 .../nldev/0004-arg.h-fixed-argv-checks-order.patch | 28 +++++++
 testing/nldev/APKBUILD                             | 88 ++++++++++++++++++++++
 testing/nldev/nldev-trigger.initd                  | 13 ++++
 testing/nldev/nldev.initd                          | 21 ++++++
 7 files changed, 263 insertions(+)
 create mode 100644 testing/nldev/0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
 create mode 100644 testing/nldev/0002-Preserve-the-PATH-environment-variable.patch
 create mode 100644 testing/nldev/0003-Change-the-default-mdev-path-to-sbin-mdev.patch
 create mode 100644 testing/nldev/0004-arg.h-fixed-argv-checks-order.patch
 create mode 100644 testing/nldev/APKBUILD
 create mode 100644 testing/nldev/nldev-trigger.initd
 create mode 100644 testing/nldev/nldev.initd
diff --git a/testing/nldev/0001-Revert-nldev-set-kernel-buffer-to-16kb.patch b/testing/nldev/0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
new file mode 100644
index 0000000..3b8456e
--- /dev/null
+++ b/testing/nldev/0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
_at_@ -0,0 +1,26 @@
+From 6df459de208c7f148f2c0f06b0712ea1708ed614 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git_at_soeren-tempel.net>
+Date: Wed, 10 Feb 2016 22:57:13 +0100
+Subject: [PATCH 1/4] Revert "nldev: set kernel buffer to 16kb"
+
+This reverts commit 025a4aef1a05cf523fbdf98ed71fd2e7b902d7fd.
+---
+ nldev.c | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/nldev.c b/nldev.c
+index 018ed86..9153fd2 100644
+--- a/nldev.c
++++ b/nldev.c
+_at_@ -161,7 +161,7 @@ init_netlink_socket(void)
+ 	if (fd < 0)
+ 		edie("socket");
+ 
+-	slen = 16*1024;
++	slen = 128*1024*1024;
+ 	if (setsockopt(fd, SOL_SOCKET, SO_RCVBUFFORCE, &slen,
+ 				sizeof(slen)) < 0) {
+ 		edie("setsockopt");
+-- 
+2.7.2
+
diff --git a/testing/nldev/0002-Preserve-the-PATH-environment-variable.patch b/testing/nldev/0002-Preserve-the-PATH-environment-variable.patch
new file mode 100644
index 0000000..d6c4ffe
--- /dev/null
+++ b/testing/nldev/0002-Preserve-the-PATH-environment-variable.patch
_at_@ -0,0 +1,46 @@
+From 980c9181b9bf44be6007462ef54568759aabbc5a Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git_at_soeren-tempel.net>
+Date: Wed, 10 Feb 2016 23:26:23 +0100
+Subject: [PATCH 2/4] Preserve the PATH environment variable
+
+No idea why this wasn't done before...
+---
+ nldev.c | 8 ++++++--
+ 1 file changed, 6 insertions(+), 2 deletions(-)
+
+diff --git a/nldev.c b/nldev.c
+index 9153fd2..deabf10 100644
+--- a/nldev.c
++++ b/nldev.c
+_at_@ -193,7 +193,7 @@ main(int argc, char *argv[])
+ 	struct msghdr hdr;
+ 	struct iovec iov;
+ 	char buf[4097], *subsystem, *runpath, *key, *value,
+-	     cbuf[CMSG_SPACE(sizeof(struct ucred))];
++	     *origpath, cbuf[CMSG_SPACE(sizeof(struct ucred))];
+ 	struct cmsghdr *chdr;
+ 	struct ucred *cred;
+ 	int i, len, slen, showudev, showkernel;
+_at_@ -203,6 +203,10 @@ main(int argc, char *argv[])
+ 	subsystem = NULL;
+ 	runpath = "/bin/mdev";
+ 
++	origpath = getenv("PATH");
++	if (!origpath || strlen(origpath) <= 0)
++		origpath = "/sbin:/bin";
++
+ 	ARGBEGIN {
+ 	case 'b':
+ 		dofork = 1;
+_at_@ -242,7 +246,7 @@ main(int argc, char *argv[])
+ 	buf[sizeof(buf)-1] = '\0';
+ 	while (poll(&fds, 1, -1) > -1) {
+ 		clearenv();
+-		setenv("PATH", "/sbin:/bin", 1);
++		setenv("PATH", origpath, 1);
+ 
+ 		iov.iov_base = &buf;
+ 		iov.iov_len = sizeof(buf);
+-- 
+2.7.2
+
diff --git a/testing/nldev/0003-Change-the-default-mdev-path-to-sbin-mdev.patch b/testing/nldev/0003-Change-the-default-mdev-path-to-sbin-mdev.patch
new file mode 100644
index 0000000..395f674
--- /dev/null
+++ b/testing/nldev/0003-Change-the-default-mdev-path-to-sbin-mdev.patch
_at_@ -0,0 +1,41 @@
+From 5a979c33e4859d07660fad54d253c91202cf2a37 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git_at_soeren-tempel.net>
+Date: Wed, 10 Feb 2016 23:29:04 +0100
+Subject: [PATCH 3/4] Change the default mdev path to /sbin/mdev
+
+You can set it using the -r command line flag but I prefer it when
+things work out of the box (the flag is nice to have non the less).
+---
+ nldev.8 | 2 +-
+ nldev.c | 2 +-
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/nldev.8 b/nldev.8
+index b1c18db..45c307b 100644
+--- a/nldev.8
++++ b/nldev.8
+_at_@ -56,7 +56,7 @@ Only show netlink messages from libudev.
+ .
+ .It Fl r Ar runpath
+ This option specifies the runpath for the helper that is launched
+-on every received netlink event (default: /bin/mdev).
++on every received netlink event (default: /sbin/mdev).
+ .El
+ .
+ .Sh AUTHORS
+diff --git a/nldev.c b/nldev.c
+index deabf10..a1d529a 100644
+--- a/nldev.c
++++ b/nldev.c
+_at_@ -201,7 +201,7 @@ main(int argc, char *argv[])
+ 	showkernel = 1;
+ 	showudev = 1;
+ 	subsystem = NULL;
+-	runpath = "/bin/mdev";
++	runpath = "/sbin/mdev";
+ 
+ 	origpath = getenv("PATH");
+ 	if (!origpath || strlen(origpath) <= 0)
+-- 
+2.7.2
+
diff --git a/testing/nldev/0004-arg.h-fixed-argv-checks-order.patch b/testing/nldev/0004-arg.h-fixed-argv-checks-order.patch
new file mode 100644
index 0000000..4fdeb40
--- /dev/null
+++ b/testing/nldev/0004-arg.h-fixed-argv-checks-order.patch
_at_@ -0,0 +1,28 @@
+From 686bc79ed87fb9c57afcc523d4dc8e217b03bac6 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?S=C3=B6ren=20Tempel?= <soeren+git_at_soeren-tempel.net>
+Date: Mon, 29 Feb 2016 22:45:43 +0100
+Subject: [PATCH 4/4] arg.h: fixed argv checks order
+
+This prevents accessing to a potentially out-of-bounds memory section.
+---
+ arg.h | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/arg.h b/arg.h
+index 2b189fe..c234e75 100644
+--- a/arg.h
++++ b/arg.h
+_at_@ -12,8 +12,8 @@ extern char *argv0;
+ 
+ /* use main(int argc, char *argv[]) */
+ #define ARGBEGIN	for (argv0 = *argv, argv++, argc--;\
+-					argv[0] && argv[0][1]\
+-					&& argv[0][0] == '-';\
++					argv[0] && argv[0][0] == '-'\
++					&& argv[0][1];\
+ 					argc--, argv++) {\
+ 				char _argc;\
+ 				char **_argv;\
+-- 
+2.7.2
+
diff --git a/testing/nldev/APKBUILD b/testing/nldev/APKBUILD
new file mode 100644
index 0000000..a254c85
--- /dev/null
+++ b/testing/nldev/APKBUILD
_at_@ -0,0 +1,88 @@
+# Contributor: Sören Tempel <soeren+alpine_at_soeren-tempel.net>
+# Maintainer: Sören Tempel <soeren+alpine_at_soeren-tempel.net>
+pkgname=nldev
+pkgver=0.3_git20160229
+pkgrel=0
+verbase=0.3
+pkgdesc="A simple netlink device manager"
+url="http://git.r-36.net/nldev/"
+arch="all"
+license="MIT"
+depends=""
+depends_dev=""
+makedepends="linux-headers"
+install=""
+subpackages="$pkgname-doc"
+source="http://dev.alpinelinux.org/archive/$pkgname/$pkgname-$pkgver.tar.gz
+	${pkgname}.initd
+	${pkgname}-trigger.initd
+	
+	0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
+	0002-Preserve-the-PATH-environment-variable.patch
+	0003-Change-the-default-mdev-path-to-sbin-mdev.patch
+	0004-arg.h-fixed-argv-checks-order.patch"
+
+disturl="dev.alpinelinux.org:/archive/$pkgname"
+reporev="e8a7f8c4131d39eaff0ebb186f6ee01a08db3e59"
+giturl="git://git.r-36.net/$pkgname"
+
+_builddir="$srcdir"/$pkgname-$pkgver
+build() {
+	make CFLAGS="$CFLAGS \${INCS} \${CPPFLAGS}" \
+		LDFLAGS="$LDFLAGS \${LIBS}" CC="${CC:-gcc}" \
+		-C "$_builddir" || return 1
+}
+
+package() {
+	cd "$_builddir"
+	make DESTDIR="$pkgdir" PREFIX=/ \
+		MANPREFIX=/usr/share/man install || return 1
+
+	# Move nldev to /sbin
+	mkdir -p "$pkgdir"/sbin/
+	mv "$pkgdir"/bin/$pkgname "$pkgdir"/sbin/ || return 1
+
+	# We don't need run_nldev, use the init script instead
+	rm -f "$pkgdir"/bin/run_$pkgname
+
+	# Install OpenRC service files
+	for service in ${pkgname} ${pkgname}-trigger; do
+		install -Dm755 "$srcdir"/$service.initd \
+			"$pkgdir"/etc/init.d/$service || return 1
+	done
+	
+	# Install utility scripts
+	mkdir -p "$pkgdir"/lib/$pkgname || return 1
+	install -m755 mdev/lib/* "$pkgdir"/lib/$pkgname/ || return 1
+
+	# Install additional documentation
+	mkdir -p "$pkgdir"/usr/share/doc/$pkgname/examples/
+	install -m644 FIXES.md README.md \
+		"$pkgdir"/usr/share/doc/$pkgname/ || return 1
+	install -m644 mdev/etc/* \
+		"$pkgdir"/usr/share/doc/$pkgname/examples || return 1
+	install -m755 mdev/lib/* \
+		"$pkgdir"/usr/share/doc/$pkgname/examples || return 1
+}
+
+md5sums="f2963c34927895755f4ab2139497d52a  nldev-0.3_git20160229.tar.gz
+cfd5fdea112868ef460cd34a60c8bb6a  nldev.initd
+f57e754d52f06529e82979db8bd3106e  nldev-trigger.initd
+e565d056ea4dd5c74b308c397e7e27e5  0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
+a921cc18e879114a1c8009d2f9cfb552  0002-Preserve-the-PATH-environment-variable.patch
+bfc26b861b96d253b89defb14697523a  0003-Change-the-default-mdev-path-to-sbin-mdev.patch
+f1909e7952099c1cef74de5c180b81a2  0004-arg.h-fixed-argv-checks-order.patch"
+sha256sums="2fb6278b3fa6b0c5055b14572cfa2e278c50c58812a4dd8e64d6edcd0fd4de65  nldev-0.3_git20160229.tar.gz
+5bf4054e53415221929973f8e2b96944a138a30091f20a24de94cd062a5fef3a  nldev.initd
+1ab6163a350a7c7e377f0e6ea9070c736c434c9a55c3ef28438af552effa1714  nldev-trigger.initd
+22e295e2f3391c139b735098f11c8dfabf835373ad80a1d12f0df3d4ee4ffc7d  0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
+7d47ff02a42273446fed0774658d0f9f199e4d9b1ede3e02143985db6fab3d0f  0002-Preserve-the-PATH-environment-variable.patch
+a861166721ecae633bffa91a6ac055c23f3ad5a1070cb7c9a303816326328619  0003-Change-the-default-mdev-path-to-sbin-mdev.patch
+b1656f45eed463b265bf5d65b0885fdad0052e3706dd7c5fe34830a49059de45  0004-arg.h-fixed-argv-checks-order.patch"
+sha512sums="ea5fb3d77f1cd46561813a16bc48625ab1aa2765eb63df3ae96ff9daeb4e4f3267a8b6a52d316fb17e2132d97a9b34884a356107d11577c7547f4f43df19a8da  nldev-0.3_git20160229.tar.gz
+022d596e2c598a0904721d042d6b33151c2df5ea5643ba6f8acec4993ce5ce47e68cd7ecfec1236dd68daa306ea6bcc386b4c28ab610ddac8acf7dc79606d17b  nldev.initd
+0e34e2db640bcfe7ba8b8e2a07a681906e7e6a2fe267f255a216c36e93db5096b7ed4865935ef448aabc8c4c130a786e555113d8ba90bed58f4ae3450890a1ea  nldev-trigger.initd
+7821f54b0eeab13355d0a534bafc7c07250b91dcd43e334ffe9bcd9ee601680489ade4aa97b45543d38be93279c3cb11357d58497a3fb7e66052bf743917088f  0001-Revert-nldev-set-kernel-buffer-to-16kb.patch
+3d592c4f5a8ae1081aa3780d099b98e3c9869cecc1a3d06dff096e8ee1ea00059c8d5c702fdbb6c5829a429a813f37deab7de7164d38887834d62c0da6165173  0002-Preserve-the-PATH-environment-variable.patch
+b9128249077981718d34477b5b81655f256f0a28a549099ed20a611d5aeb54e0d837debe623d6f65071a036fd31322454bb99906058e6309b18c0178c5ce3e5e  0003-Change-the-default-mdev-path-to-sbin-mdev.patch
+c26d889f3525eea3ff1bd4c9ce7fd5713f3ffa001177d81639616f253fcfdcc5b27e032905582bab9ebeb2d010ca8e0a5e390419ec8b089f45c925f8f8c4554f  0004-arg.h-fixed-argv-checks-order.patch"
diff --git a/testing/nldev/nldev-trigger.initd b/testing/nldev/nldev-trigger.initd
new file mode 100644
index 0000000..65482d8
--- /dev/null
+++ b/testing/nldev/nldev-trigger.initd
_at_@ -0,0 +1,13 @@
+#!/sbin/openrc-run
+
+depend() {
+	need nldev
+	provide dev
+	keyword -lxc -vserver
+}
+
+start() {
+	ebegin "Populating /dev with existing devices through uevents"
+	/bin/nltrigger add all
+	eend $?
+}
diff --git a/testing/nldev/nldev.initd b/testing/nldev/nldev.initd
new file mode 100644
index 0000000..ea53273
--- /dev/null
+++ b/testing/nldev/nldev.initd
_at_@ -0,0 +1,21 @@
+#!/sbin/openrc-run
+
+name="$SVCNAME"
+command="/sbin/$SVCNAME"
+command_args="${NLDEV_OPTS:--k}"
+pidfile="/var/run/$SVCNAME.pid"
+command_background="yes"
+
+depend() {
+	provide dev
+	need sysfs dev-mount
+	before checkfs fsck
+	keyword -lxc -vserver
+}
+
+start_pre() {
+	if [ -e /proc/self/fd ]; then
+		rm -f /dev/fd 2>/dev/null
+		ln -sf /proc/self/fd /dev/fd
+	fi
+}
-- 
2.7.2
---
Unsubscribe:  alpine-aports+unsubscribe_at_lists.alpinelinux.org
Help:         alpine-aports+help_at_lists.alpinelinux.org
---
Received on Mon Feb 29 2016 - 22:58:39 GMT