[v2] package/eudev: S10udevd: wait for udevd before triggering events

Message ID 20261126192612.1598984-1-dario.binacchi@amarulasolutions.com
State New
Headers
Series [v2] package/eudev: S10udevd: wait for udevd before triggering events |

Commit Message

Dario Binacchi Nov. 26, 2026, 7:26 p.m. UTC
start-stop-daemon starts udevd in the background and returns before
udevd listens to kernel events. The coldplug events generated right
after by "udevadm trigger" may then get lost, so that no module is
loaded at boot.

  Starting network: Waiting for interface eth0 to appear............... timeout!

Wait until udevd answers on its control socket before triggering the
events. The udevadm control command of eudev has no --ping option, so
use --start-exec-queue, which has no effect on a daemon whose queue is
already running.

While at it, return right away when udevd fails to start, as there is
no point in triggering events then.

Fixes: 41258a81948fddfa7fc8ac06b69d77fa051b744d ("package/eudev: refactor init script and rename it to S10udevd")
Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>
---
Changes in v2:
- Return right away when udevd fails to start and move the wait loop
  out of the if statement.
- Use '[ "$i" -lt 50 ] || break' to leave the loop.
- Explain in the commit message why --start-exec-queue is used.

v1: https://lore.kernel.org/buildroot/20261029164212.672884-1-dario.binacchi@amarulasolutions.com

 package/eudev/S10udevd | 9 +++++++++
 1 file changed, 9 insertions(+)

-- 
2.43.0
  

Comments

Fiona Klute Nov. 26, 2026, 10:33 p.m. UTC | #1
Am 26.11.26 um 20:26 schrieb Dario Binacchi:
> start-stop-daemon starts udevd in the background and returns before
> udevd listens to kernel events. The coldplug events generated right
> after by "udevadm trigger" may then get lost, so that no module is
> loaded at boot.
> 
>    Starting network: Waiting for interface eth0 to appear............... timeout!
> 
> Wait until udevd answers on its control socket before triggering the
> events. The udevadm control command of eudev has no --ping option, so
> use --start-exec-queue, which has no effect on a daemon whose queue is
> already running.
> 
> While at it, return right away when udevd fails to start, as there is
> no point in triggering events then.
> 
> Fixes: 41258a81948fddfa7fc8ac06b69d77fa051b744d ("package/eudev: refactor init script and rename it to S10udevd")
> Signed-off-by: Dario Binacchi <dario.binacchi@amarulasolutions.com>

Applied to master, thank you!

> ---
> Changes in v2:
> - Return right away when udevd fails to start and move the wait loop
>    out of the if statement.
> - Use '[ "$i" -lt 50 ] || break' to leave the loop.
> - Explain in the commit message why --start-exec-queue is used.
> 
> v1: https://lore.kernel.org/buildroot/20261029164212.672884-1-dario.binacchi@amarulasolutions.com
> 
>   package/eudev/S10udevd | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/package/eudev/S10udevd b/package/eudev/S10udevd
> index 8bb8f6eb3a01..8eb764f65215 100644
> --- a/package/eudev/S10udevd
> +++ b/package/eudev/S10udevd
> @@ -37,7 +37,16 @@ start() {
>   		echo "OK"
>   	else
>   		echo "FAIL"
> +		return "$status"
>   	fi
> +	# start-stop-daemon returns before udevd listens to kernel events.
> +	# Wait for it, or the events triggered below may get lost.
> +	i=0
> +	while ! udevadm control --start-exec-queue 2>/dev/null; do
> +		i=$((i + 1))
> +		[ "$i" -lt 50 ] || break
> +		sleep 0.1
> +	done
>   	udevadm trigger --type=subsystems --action=add
>   	udevadm trigger --type=devices --action=add
>   	udevadm settle --timeout=$SETTLE_TIMEOUT || echo "udevadm settle failed"
  
Peter Korsgaard Nov. 27, 2026, 8:44 a.m. UTC | #2
>>>>> "Dario" == Dario Binacchi <dario.binacchi@amarulasolutions.com> writes:

 > start-stop-daemon starts udevd in the background and returns before
 > udevd listens to kernel events. The coldplug events generated right
 > after by "udevadm trigger" may then get lost, so that no module is
 > loaded at boot.

 >   Starting network: Waiting for interface eth0 to appear............... timeout!

 > Wait until udevd answers on its control socket before triggering the
 > events. The udevadm control command of eudev has no --ping option, so
 > use --start-exec-queue, which has no effect on a daemon whose queue is
 > already running.

 > While at it, return right away when udevd fails to start, as there is
 > no point in triggering events then.

 > Fixes: 41258a81948fddfa7fc8ac06b69d77fa051b744d ("package/eudev: refactor init script and rename it to S10udevd")

Sorry, I know this is already committed - But if the bug was introduced
by the move to backgrounding with start-stop-daemon, wouldn't it be
simpler to just drop the --background argument to start-stop-daemon and
instead ask udevd to background itself with -d like we did before?

-- 
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
  
Fiona Klute Nov. 27, 2026, 8:53 a.m. UTC | #3
Am 27.11.26 um 09:44 schrieb Peter Korsgaard:
>>>>>> "Dario" == Dario Binacchi <dario.binacchi@amarulasolutions.com> writes:
> 
>   > start-stop-daemon starts udevd in the background and returns before
>   > udevd listens to kernel events. The coldplug events generated right
>   > after by "udevadm trigger" may then get lost, so that no module is
>   > loaded at boot.
> 
>   >   Starting network: Waiting for interface eth0 to appear............... timeout!
> 
>   > Wait until udevd answers on its control socket before triggering the
>   > events. The udevadm control command of eudev has no --ping option, so
>   > use --start-exec-queue, which has no effect on a daemon whose queue is
>   > already running.
> 
>   > While at it, return right away when udevd fails to start, as there is
>   > no point in triggering events then.
> 
>   > Fixes: 41258a81948fddfa7fc8ac06b69d77fa051b744d ("package/eudev: refactor init script and rename it to S10udevd")
> 
> Sorry, I know this is already committed - But if the bug was introduced
> by the move to backgrounding with start-stop-daemon, wouldn't it be
> simpler to just drop the --background argument to start-stop-daemon and
> instead ask udevd to background itself with -d like we did before?
The problem is that eudev doesn't write a PID file, and if we don't let 
start-stop-daemon handle backgrounding the one it writes will be wrong 
(before commit 41258a81948fddfa7fc8ac06b69d77fa051b744d, the init script 
didn't create one at all). :-(
  
Peter Korsgaard Nov. 27, 2026, 1:02 p.m. UTC | #4
>>>>> "Fiona" == Fiona Klute <fiona.klute@gmx.de> writes:

Hi,

 >> by the move to backgrounding with start-stop-daemon, wouldn't it be
 >> simpler to just drop the --background argument to start-stop-daemon and
 >> instead ask udevd to background itself with -d like we did before?

> The problem is that eudev doesn't write a PID file, and if we don't
 > let start-stop-daemon handle backgrounding the one it writes will be
 > wrong (before commit 41258a81948fddfa7fc8ac06b69d77fa051b744d, the
 > init script didn't create one at all). :-(

True. Is there any uses for having more than 1 udevd on a system?

-- 
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
  

Patch

diff --git a/package/eudev/S10udevd b/package/eudev/S10udevd
index 8bb8f6eb3a01..8eb764f65215 100644
--- a/package/eudev/S10udevd
+++ b/package/eudev/S10udevd
@@ -37,7 +37,16 @@  start() {
 		echo "OK"
 	else
 		echo "FAIL"
+		return "$status"
 	fi
+	# start-stop-daemon returns before udevd listens to kernel events.
+	# Wait for it, or the events triggered below may get lost.
+	i=0
+	while ! udevadm control --start-exec-queue 2>/dev/null; do
+		i=$((i + 1))
+		[ "$i" -lt 50 ] || break
+		sleep 0.1
+	done
 	udevadm trigger --type=subsystems --action=add
 	udevadm trigger --type=devices --action=add
 	udevadm settle --timeout=$SETTLE_TIMEOUT || echo "udevadm settle failed"