From 0ccd825d817a104689bac58a7835ab9dbccc4ce0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Llu=C3=ADs=20Batlle=20i=20Rossell?=
 <viric@vicerveza.homeunix.net>
Date: Thu, 27 Oct 2011 15:13:26 +0000
Subject: [PATCH] Adding an udev patch for kernels not having the accept4 call.
 armv5tel 3.0, for example.

svn path=/nixpkgs/trunk/; revision=30053
---
 pkgs/os-specific/linux/udev/173.nix           |  3 +-
 .../linux/udev/pre-accept4-kernel.patch       | 43 +++++++++++++++++++
 2 files changed, 45 insertions(+), 1 deletion(-)
 create mode 100644 pkgs/os-specific/linux/udev/pre-accept4-kernel.patch

diff --git a/pkgs/os-specific/linux/udev/173.nix b/pkgs/os-specific/linux/udev/173.nix
index ba96717e494..f5076a9ed15 100644
--- a/pkgs/os-specific/linux/udev/173.nix
+++ b/pkgs/os-specific/linux/udev/173.nix
@@ -44,7 +44,8 @@ stdenv.mkDerivation rec {
       rm -frv $out/share/gtk-doc
     '';
 
-  patches = [ ./custom-rules.patch ];
+  patches = [ ./custom-rules.patch ] ++
+    stdenv.lib.optional (stdenv.system == "armv5tel-linux") ./pre-accept4-kernel.patch;
 
   meta = {
     homepage = http://www.kernel.org/pub/linux/utils/kernel/hotplug/udev.html;
diff --git a/pkgs/os-specific/linux/udev/pre-accept4-kernel.patch b/pkgs/os-specific/linux/udev/pre-accept4-kernel.patch
new file mode 100644
index 00000000000..2cf549d99a7
--- /dev/null
+++ b/pkgs/os-specific/linux/udev/pre-accept4-kernel.patch
@@ -0,0 +1,43 @@
+From:
+https://github.com/archlinuxarm/PKGBUILDs/blob/master/core/udev-oxnas/pre-accept4-kernel.patch
+
+diff -urN a/udev/udev-ctrl.c b/udev/udev-ctrl.c
+--- a/udev/udev-ctrl.c	2011-10-09 17:10:32.000000000 -0600
++++ b/udev/udev-ctrl.c	2011-10-25 15:11:09.000000000 -0600
+@@ -15,6 +15,7 @@
+ #include <stddef.h>
+ #include <string.h>
+ #include <unistd.h>
++#include <fcntl.h>
+ #include <sys/types.h>
+ #include <sys/poll.h>
+ #include <sys/socket.h>
+@@ -182,6 +183,7 @@
+ 	struct ucred ucred;
+ 	socklen_t slen;
+ 	const int on = 1;
++	int flgs;
+ 
+ 	conn = calloc(1, sizeof(struct udev_ctrl_connection));
+ 	if (conn == NULL)
+@@ -189,13 +191,19 @@
+ 	conn->refcount = 1;
+ 	conn->uctrl = uctrl;
+ 
+-	conn->sock = accept4(uctrl->sock, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK);
++//	conn->sock = accept4(uctrl->sock, NULL, NULL, SOCK_CLOEXEC|SOCK_NONBLOCK);
++	conn->sock = accept(uctrl->sock, NULL, NULL);
+ 	if (conn->sock < 0) {
+ 		if (errno != EINTR)
+ 			err(uctrl->udev, "unable to receive ctrl connection: %m\n");
+ 		goto err;
+ 	}
+ 
++// Since we don't have accept4
++	flgs = fcntl(conn->sock, F_GETFL, NULL);
++	if(flgs >= 0) fcntl(conn->sock, F_SETFL, flgs | O_NONBLOCK);
++	fcntl(conn->sock, F_SETFD, FD_CLOEXEC);
++
+ 	/* check peer credential of connection */
+ 	slen = sizeof(ucred);
+ 	if (getsockopt(conn->sock, SOL_SOCKET, SO_PEERCRED, &ucred, &slen) < 0) {