From a44c286fdb6478992a0d99cf886fbdb6a67ea301 Mon Sep 17 00:00:00 2001
From: Felix Fietkau <nbd@openwrt.org>
Date: Sun, 4 Mar 2007 20:31:53 +0000
Subject: [PATCH] nuke mdev and replace it with hotplug2 :)

SVN-Revision: 6512
---
 include/kernel-build.mk                                |  3 +++
 package/base-files/files/etc/functions.sh              |  2 +-
 package/base-files/files/etc/hotplug2.rules            |  7 +++++++
 package/base-files/files/etc/init.d/boot               |  7 +++++--
 package/base-files/files/etc/mdev.conf                 |  5 -----
 package/base-files/files/lib/network/config.sh         |  2 +-
 .../base-files/files/sbin/{hotplug => hotplug-call}    |  2 --
 package/base-files/files/sbin/ifdown                   |  2 +-
 package/base-files/files/sbin/mount_root               |  2 +-
 .../base-files/files/usr/share/udhcpc/default.script   |  2 +-
 package/busybox/config/util-linux/Config.in            |  4 ++--
 package/busybox/target-config.in                       |  7 -------
 package/comgt/files/3g.button                          |  3 ++-
 package/ppp/files/etc/ppp/ip-down                      |  2 +-
 package/ppp/files/etc/ppp/ip-up                        |  2 +-
 package/udev/patches/02-udevtrigger_no_config.patch    | 10 ++++++++++
 target/linux/brcm-2.4/base-files/default/etc/preinit   |  2 +-
 target/linux/generic-2.6/files/init                    |  2 +-
 18 files changed, 38 insertions(+), 28 deletions(-)
 create mode 100644 package/base-files/files/etc/hotplug2.rules
 delete mode 100644 package/base-files/files/etc/mdev.conf
 rename package/base-files/files/sbin/{hotplug => hotplug-call} (89%)
 create mode 100644 package/udev/patches/02-udevtrigger_no_config.patch

diff --git a/include/kernel-build.mk b/include/kernel-build.mk
index 93bf66dbcb3..3193e9d1859 100644
--- a/include/kernel-build.mk
+++ b/include/kernel-build.mk
@@ -37,6 +37,9 @@ FEATURES:=$(sort $(FEATURES))
 
 # For target profile selection - the default set
 DEFAULT_PACKAGES:=base-files libgcc uclibc bridge busybox dnsmasq dropbear iptables mtd ppp ppp-mod-pppoe mtd kmod-ipt-nathelper
+ifneq ($(KERNEL),2.4)
+  DEFAULT_PACKAGES+=udevtrigger hotplug2
+endif
 
 ifeq ($(DUMP),1)
   all: dumpinfo
diff --git a/package/base-files/files/etc/functions.sh b/package/base-files/files/etc/functions.sh
index c29ae772ac3..4d84bb81e07 100755
--- a/package/base-files/files/etc/functions.sh
+++ b/package/base-files/files/etc/functions.sh
@@ -12,7 +12,7 @@ _C=0
 NO_EXPORT=1
 
 hotplug_dev() {
-	env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug net
+	env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug-call net
 }
 
 append() {
diff --git a/package/base-files/files/etc/hotplug2.rules b/package/base-files/files/etc/hotplug2.rules
new file mode 100644
index 00000000000..d2a931adcf9
--- /dev/null
+++ b/package/base-files/files/etc/hotplug2.rules
@@ -0,0 +1,7 @@
+DEVPATH is set {
+			makedev /dev/%DEVICENAME% 0644
+}
+
+MODALIAS is set {
+			exec /sbin/modprobe -q %MODALIAS% ;
+}
diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot
index db7ec8cc3aa..ed5e7d8ba56 100755
--- a/package/base-files/files/etc/init.d/boot
+++ b/package/base-files/files/etc/init.d/boot
@@ -20,8 +20,11 @@ start() {
 	
 	# manually trigger hotplug before loading modules
 	for iface in $(awk -F: '/:/ {print $1}' /proc/net/dev); do
-		/usr/bin/env -i ACTION=add INTERFACE="$iface" /sbin/hotplug net
+		/usr/bin/env -i ACTION=add INTERFACE="$iface" /sbin/hotplug-call net
 	done
-	
+
+	/sbin/hotplug2 --persistent &
+	echo /sbin/hotplug-call > /proc/sys/kernel/hotplug
+
 	load_modules /etc/modules.d/*
 }
diff --git a/package/base-files/files/etc/mdev.conf b/package/base-files/files/etc/mdev.conf
deleted file mode 100644
index 89355830f0f..00000000000
--- a/package/base-files/files/etc/mdev.conf
+++ /dev/null
@@ -1,5 +0,0 @@
-null 0:0 777
-zero 0:0 666
-console 0:5 0600
-tty 0:5 0660
-ttyS* 0:20 640
diff --git a/package/base-files/files/lib/network/config.sh b/package/base-files/files/lib/network/config.sh
index 95954bf15ac..8a596874d4c 100755
--- a/package/base-files/files/lib/network/config.sh
+++ b/package/base-files/files/lib/network/config.sh
@@ -157,7 +157,7 @@ setup_interface() {
 				done
 			}
 
-			env -i ACTION="ifup" INTERFACE="$config" DEVICE="$iface" PROTO=static /sbin/hotplug "iface" &
+			env -i ACTION="ifup" INTERFACE="$config" DEVICE="$iface" PROTO=static /sbin/hotplug-call "iface" &
 		;;
 		dhcp)
 			# prevent udhcpc from starting more than once
diff --git a/package/base-files/files/sbin/hotplug b/package/base-files/files/sbin/hotplug-call
similarity index 89%
rename from package/base-files/files/sbin/hotplug
rename to package/base-files/files/sbin/hotplug-call
index 189cfee67c8..b1b6f97b234 100755
--- a/package/base-files/files/sbin/hotplug
+++ b/package/base-files/files/sbin/hotplug-call
@@ -1,8 +1,6 @@
 #!/bin/sh
 # Copyright (C) 2006 OpenWrt.org
 
-[ -x /sbin/mdev -a -n "$ACTION" -a -n "$DEVPATH" ] && /sbin/mdev "$@"
-
 # bypass the normal hotplug path for firmware loading
 # would otherwise cause problems with drivers like bcm43xx
 [ "$1" = "firmware" -a "$ACTION" = "add" ] && {
diff --git a/package/base-files/files/sbin/ifdown b/package/base-files/files/sbin/ifdown
index 540c69f1691..e00a4e38da3 100755
--- a/package/base-files/files/sbin/ifdown
+++ b/package/base-files/files/sbin/ifdown
@@ -21,7 +21,7 @@ config_get proto "$cfg" proto
 
 config_get iface "$cfg" device
 [ "$proto" = "static" ] && {
-	env -i ACTION="ifdown" INTERFACE="$config" DEVICE="$iface" PROTO=static /sbin/hotplug "iface" &
+	env -i ACTION="ifdown" INTERFACE="$config" DEVICE="$iface" PROTO=static /sbin/hotplug-call "iface" &
 }
 
 # call interface stop handler
diff --git a/package/base-files/files/sbin/mount_root b/package/base-files/files/sbin/mount_root
index 9a87fadbaa0..dd9d99d8e6a 100755
--- a/package/base-files/files/sbin/mount_root
+++ b/package/base-files/files/sbin/mount_root
@@ -12,7 +12,7 @@ else
 	mount -t tmpfs tmpfs /dev -o size=512K
 	mknod /dev/console c 5 1
 	mkdir /dev/shm
-	/sbin/mdev -s
+	/sbin/hotplug2 --no-persistent --coldplug
 fi
 mkdir -p /dev/pts
 mount none /dev/pts -t devpts
diff --git a/package/base-files/files/usr/share/udhcpc/default.script b/package/base-files/files/usr/share/udhcpc/default.script
index f39d21ed8c2..c7239535660 100755
--- a/package/base-files/files/usr/share/udhcpc/default.script
+++ b/package/base-files/files/usr/share/udhcpc/default.script
@@ -14,7 +14,7 @@ hotplug_event() {
 		config_get proto $ifc proto
 		[ "$proto" = "dhcp" ] || continue
 
-		env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug iface
+		env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug-call iface
 	done
 }
 
diff --git a/package/busybox/config/util-linux/Config.in b/package/busybox/config/util-linux/Config.in
index 0f219d70e24..ab3dc3731dd 100644
--- a/package/busybox/config/util-linux/Config.in
+++ b/package/busybox/config/util-linux/Config.in
@@ -267,7 +267,7 @@ config BUSYBOX_CONFIG_LOSETUP
 
 config BUSYBOX_CONFIG_MDEV
 	bool "mdev"
-	default y
+	default n
 	help
 	  mdev is a mini-udev implementation: call it with -s to populate
 	  /dev from /sys, then "echo /sbin/mdev > /proc/sys/kernel/hotplug" to
@@ -276,7 +276,7 @@ config BUSYBOX_CONFIG_MDEV
 
 config BUSYBOX_CONFIG_FEATURE_MDEV_CONF
 	bool "Support /etc/mdev.conf"
-	default y
+	default n
 	depends on BUSYBOX_CONFIG_MDEV
 	help
 	  The mdev config file contains lines that look like:
diff --git a/package/busybox/target-config.in b/package/busybox/target-config.in
index 77c58cef142..86f270b5909 100644
--- a/package/busybox/target-config.in
+++ b/package/busybox/target-config.in
@@ -2,10 +2,3 @@ config BUSYBOX_CONFIG_FEATURE_DEVFS
 	default y if LINUX_2_4
 	default n if LINUX_2_6
 
-config BUSYBOX_CONFIG_MDEV
-	default n if LINUX_2_4
-	default y if LINUX_2_6
-
-config BUSYBOX_CONFIG_FEATURE_MDEV_CONF
-	default n if LINUX_2_4
-	default y if LINUX_2_6
diff --git a/package/comgt/files/3g.button b/package/comgt/files/3g.button
index 54997d870ae..57f42860731 100644
--- a/package/comgt/files/3g.button
+++ b/package/comgt/files/3g.button
@@ -13,6 +13,7 @@ button_action() {(
 )}
 
 [ "$ACTION" = "released" -a "$BUTTON" = "3g" ] && {
+	HOTPLUG="$(cat /proc/sys/kernel/hotplug)"
 	(echo /bin/true > /proc/sys/kernel/hotplug)
 
 	include /lib/network
@@ -31,5 +32,5 @@ button_action() {(
 	}
 	config_load network
 
-	(echo /sbin/hotplug > /proc/sys/kernel/hotplug)
+	(echo $HOTPLUG > /proc/sys/kernel/hotplug)
 } &
diff --git a/package/ppp/files/etc/ppp/ip-down b/package/ppp/files/etc/ppp/ip-down
index 334bcb885af..6bff00ca035 100755
--- a/package/ppp/files/etc/ppp/ip-down
+++ b/package/ppp/files/etc/ppp/ip-down
@@ -1,5 +1,5 @@
 #!/bin/sh
-[ -z "$6" ] || env -i ACTION="ifdown" INTERFACE="$6" PROTO=ppp /sbin/hotplug "iface"
+[ -z "$6" ] || env -i ACTION="ifdown" INTERFACE="$6" PROTO=ppp /sbin/hotplug-call "iface"
 
 [ -d /etc/ppp/ip-down.d ] && {
 	for SCRIPT in /etc/ppp/ip-down.d/*
diff --git a/package/ppp/files/etc/ppp/ip-up b/package/ppp/files/etc/ppp/ip-up
index 34b4b50e15a..53a91343a51 100755
--- a/package/ppp/files/etc/ppp/ip-up
+++ b/package/ppp/files/etc/ppp/ip-up
@@ -1,5 +1,5 @@
 #!/bin/sh
-[ -z "$6" ] || env -i ACTION="ifup" INTERFACE="$6" PROTO=ppp /sbin/hotplug "iface"
+[ -z "$6" ] || env -i ACTION="ifup" INTERFACE="$6" PROTO=ppp /sbin/hotplug-call "iface"
 
 [ -d /etc/ppp/ip-up.d ] && {
 	for SCRIPT in /etc/ppp/ip-up.d/*
diff --git a/package/udev/patches/02-udevtrigger_no_config.patch b/package/udev/patches/02-udevtrigger_no_config.patch
new file mode 100644
index 00000000000..e9c22d4c0b1
--- /dev/null
+++ b/package/udev/patches/02-udevtrigger_no_config.patch
@@ -0,0 +1,10 @@
+--- udev.old/udevtrigger.c	2007-03-03 18:42:09.000000000 +0100
++++ udev.dev/udevtrigger.c	2007-03-04 21:15:18.459211632 +0100
+@@ -446,7 +446,6 @@
+ 	};
+ 
+ 	logging_init("udevtrigger");
+-	udev_config_init();
+ 	dbg("version %s", UDEV_VERSION);
+ 	sysfs_init();
+ 
diff --git a/target/linux/brcm-2.4/base-files/default/etc/preinit b/target/linux/brcm-2.4/base-files/default/etc/preinit
index 1c4e59f1520..b7a9f047721 100755
--- a/target/linux/brcm-2.4/base-files/default/etc/preinit
+++ b/target/linux/brcm-2.4/base-files/default/etc/preinit
@@ -65,7 +65,7 @@ eval ${FAILSAFE:+failsafe}
 
 lock -w /tmp/.failsafe
 set_state preinit
-echo /sbin/hotplug > /proc/sys/kernel/hotplug
+echo /sbin/hotplug-call > /proc/sys/kernel/hotplug
 
 ifconfig $ifname 0.0.0.0 down
 
diff --git a/target/linux/generic-2.6/files/init b/target/linux/generic-2.6/files/init
index 292d429dcd5..af397d9abbc 100755
--- a/target/linux/generic-2.6/files/init
+++ b/target/linux/generic-2.6/files/init
@@ -12,7 +12,7 @@ else
 	mknod /dev/console c 5 1
 	mkdir /dev/pts
 	mkdir /dev/shm
-	/sbin/mdev -s
+	/sbin/hotplug2 --no-persistent --coldplug
 fi
 
 mount none /dev/pts -t devpts
-- 
GitLab