Skip to contentSkip to conversation

package/busybox: update S10mdev

PATCH New Titouan Christophe 2 participants 4 messages May 29, 2019 – Jun 19, 2019 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 package/busybox: update S10mdev

Avoid race conditions in mdev invocations
* use the uevent daemon if possible
* fallback to hotplug (as before) and initialize /dev/mdev.seq
* otherwise print an error message and do nothing else

---
 package/busybox/S10mdev | 66 +++++++++++++++++++++++++++++++++++------
 1 file changed, 57 insertions(+), 9 deletions(-)
package/busybox/S10mdev +57 -9
index 7075b77016..f1a836da32 100644
@@ -1,20 +1,68 @@
 #!/bin/sh
 #
-# Start mdev....
+# Start mdev, using the uevent daemon whereas possible
 #
 
-case "$1" in
-  start)
-	echo "Starting mdev..."
-	echo /sbin/mdev >/proc/sys/kernel/hotplug
+DAEMON="uevent"
+PIDFILE="/var/run/$DAEMON.pid"
+
+has_uevent_and_netlink() {
+	[ -f /proc/net/netlink ] && [ -x /sbin/uevent ]
+}
+
+has_hotplug() {
+	[ -w /proc/sys/kernel/hotplug ]
+}
+
+
+start() {
+	if has_uevent_and_netlink; then
+		echo -n "Starting mdev within uevent... "
+		start-stop-daemon -S -b -m -p $PIDFILE -x /sbin/uevent -- /sbin/mdev
+		[ $? -eq 0 ] && echo "OK" || echo "FAIL"
+	elif has_hotplug; then
+		echo "Installing mdev as hotplug helper"
+		# Initialize the seq counter to prevent plug/unplug races
+		touch /dev/mdev.seq
+		echo /sbin/mdev > /proc/sys/kernel/hotplug
+	else
+		echo "ERROR: neither netlink+uevent nor hotplug are available"
+		echo "       Unable to start mdev !"
+		exit 1
+	fi
+
+	# Run boot time /sys scan
 	/sbin/mdev -s
+
 	# coldplug modules
 	find /sys/ -name modalias -print0 | xargs -0 sort -u | tr '\n' '\0' | \
 	    xargs -0 modprobe -abq
-	;;
-  stop)
-	;;
-  restart|reload)
+}
+
+stop() {
+	if has_uevent_and_netlink; then
+		echo -n "Stopping mdev within uevent... "
+		start-stop-daemon -K -p $PIDFILE
+		[ $? -eq 0 ] && echo "OK" || echo "FAIL"
+	elif has_hotplug; then
+		echo "Uninstalling mdev from hotplug helper"
+		echo > /proc/sys/kernel/hotplug
+	else
+		echo "ERROR: neither netlink+uevent nor hotplug are available"
+		echo "       Unable to stop mdev !"
+		exit 1
+	fi
+}
+
+restart() {
+	stop
+	start
+}
+
+
+case "$1" in
+  start|stop|restart)
+	$1
 	;;
   *)
 	echo "Usage: $0 {start|stop|restart}"
Signature · 1 line
2.21.0

A message that is not in the archive (sent off-list or not yet received): [email protected]

#2 lore raw

PATCH 1/1 package/busybox: update S10mdev

Hello Andy,

Thank you for following up !

Quoted 7 lines · Andy Shevchenko
Quoted 5 lines · Titouan Christophe

Avoid race conditions in mdev invocations
* use the uevent daemon if possible
* fallback to hotplug (as before) and initialize /dev/mdev.seq
* otherwise print an error message and do nothing else

Quoted 6 lines

Thanks!

What are we going to do with this?
As of today Buildroot can not be used with mdev in current state.

In the meantime Busybox did introduce the daemon mode for mdev, which renders this patch obsolete (see the thread "linux: enable UEVENT_HELPER when mdev is used" over there
http://lists.busybox.net/pipermail/buildroot/2019-June/251744.html).

I discussed this with Arnout on IRC, and the outcome is that we will adapt the S10mdev script to use the new daemon mode as soon as the next Busybox release is available.

In the meantime, I guess the best option is to keep this patched script out of tree (this is what I'm doing right now).

Best regards,

Titouan

Quoted 89 lines
Quoted 88 lines
---
  package/busybox/S10mdev | 66 +++++++++++++++++++++++++++++++++++------
  1 file changed, 57 insertions(+), 9 deletions(-)
package/busybox/S10mdev +57 -9
index 7075b77016..f1a836da32 100644
@@ -1,20 +1,68 @@
  #!/bin/sh
  #
-# Start mdev....
+# Start mdev, using the uevent daemon whereas possible
  #
 
-case "$1" in
-  start)
-	echo "Starting mdev..."
-	echo /sbin/mdev >/proc/sys/kernel/hotplug
+DAEMON="uevent"
+PIDFILE="/var/run/$DAEMON.pid"
+
+has_uevent_and_netlink() {
+	[ -f /proc/net/netlink ] && [ -x /sbin/uevent ]
+}
+
+has_hotplug() {
+	[ -w /proc/sys/kernel/hotplug ]
+}
+
+
+start() {
+	if has_uevent_and_netlink; then
+		echo -n "Starting mdev within uevent... "
+		start-stop-daemon -S -b -m -p $PIDFILE -x /sbin/uevent -- /sbin/mdev
+		[ $? -eq 0 ] && echo "OK" || echo "FAIL"
+	elif has_hotplug; then
+		echo "Installing mdev as hotplug helper"
+		# Initialize the seq counter to prevent plug/unplug races
+		touch /dev/mdev.seq
+		echo /sbin/mdev > /proc/sys/kernel/hotplug
+	else
+		echo "ERROR: neither netlink+uevent nor hotplug are available"
+		echo "       Unable to start mdev !"
+		exit 1
+	fi
+
+	# Run boot time /sys scan
  	/sbin/mdev -s
+
  	# coldplug modules
  	find /sys/ -name modalias -print0 | xargs -0 sort -u | tr '\n' '\0' | \
  	    xargs -0 modprobe -abq
-	;;
-  stop)
-	;;
-  restart|reload)
+}
+
+stop() {
+	if has_uevent_and_netlink; then
+		echo -n "Stopping mdev within uevent... "
+		start-stop-daemon -K -p $PIDFILE
+		[ $? -eq 0 ] && echo "OK" || echo "FAIL"
+	elif has_hotplug; then
+		echo "Uninstalling mdev from hotplug helper"
+		echo > /proc/sys/kernel/hotplug
+	else
+		echo "ERROR: neither netlink+uevent nor hotplug are available"
+		echo "       Unable to stop mdev !"
+		exit 1
+	fi
+}
+
+restart() {
+	stop
+	start
+}
+
+
+case "$1" in
+  start|stop|restart)
+	$1
  	;;
    *)
  	echo "Usage: $0 {start|stop|restart}"
#3 lore raw

PATCH 1/1 package/busybox: update S10mdev

Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Titouan" == Titouan Christophe <[email protected]> writes:

Hi,

Quoted 8 lines

In the meantime Busybox did introduce the daemon mode for mdev, which renders this patch obsolete (see the thread "linux: enable UEVENT_HELPER when mdev is used" over there
http://lists.busybox.net/pipermail/buildroot/2019-June/251744.html).

I discussed this with Arnout on IRC, and the outcome is that we will adapt the S10mdev script to use the new daemon mode as soon as the next Busybox release is available.

Busybox 1.31.0 was released last week with this new daemon option:

https://busybox.net/

Signature · 1 line
Bye, Peter Korsgaard
#4 lore raw

PATCH 1/1 package/busybox: update S10mdev

Hello Peter,

Quoted 9 lines · Peter Korsgaard
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

"Titouan" == Titouan Christophe <[email protected]> writes:

Hi,

Quoted 4 lines

In the meantime Busybox did introduce the daemon mode for mdev, which renders this patch obsolete (see the thread "linux: enable UEVENT_HELPER when mdev is used" over there
http://lists.busybox.net/pipermail/buildroot/2019-June/251744.html).

Quoted 7 lines
Quoted 3 lines

I discussed this with Arnout on IRC, and the outcome is that we will adapt the S10mdev script to use the new daemon mode as soon as the next Busybox release is available.

Busybox 1.31.0 was released last week with this new daemon option:

https://busybox.net/

Thank you for the heads up.

I submitted a patch series for the aforementioned changes, see
http://patchwork.ozlabs.org/project/buildroot/list/?series=114874

Best regards,

Titouan