Skip to contentSkip to conversation

eudev: create static-nodes in init script

PATCH Superseded [email protected] 2 participants 4 messages May 19, 2022 – May 20, 2022

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 eudev: create static-nodes in init script

From: Changqing Li <[email protected]>

dev in modules.devname should be populated in /dev on boot. remove create static mode from udevd will make these devices cannot be populated. Since commit [1], when use sysVinit, devices like /dev/net/tun will not be created.

more info:
udevd in systemd also remove create static mode in udevd, but using service kmod-static-nodes.service and systemd-tmpfiles-setup-dev.service in systemd to create these node, so systemd works well.

For sysV, parse kmod static-nodes and generate the device nodes in init

[1] https://gitweb.gentoo.org/proj/eudev.git/commit/?id=2b7abd5ec9cc47a8b895df6db77fb1537c6f1a39

---
 meta/recipes-core/udev/eudev/init      | 36 ++++++++++++++++++++++++++
 meta/recipes-core/udev/eudev_3.2.11.bb |  2 ++
 2 files changed, 38 insertions(+)
meta/recipes-core/udev/eudev/init +36 -0
index c60dbbf6d5..5c2fb4a9fb 100644
@@ -23,6 +23,41 @@ kill_udevd () {
     [ -n "$pid" ] && kill $pid
 }
 
+make_static_nodes () {
+    [ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
+    [ -x @KMOD@ ] || return 0
+
+    kmod static-nodes --format=tmpfiles --output=/proc/self/fd/1 |
+    while read TTYPE TPATH TMODE TUSER TGROUP TAGE TARG; do
+    case "${TTYPE}" in
+    'd')
+            test -d "${TPATH}" || mkdir -p -m "${TMODE}" "${TPATH}"
+            ;;
+
+    'c!')
+            if [ ! -c "${TPATH}" ]; then
+                    old_ifs="${IFS}"
+                    IFS=:
+                    set -- ${TARG}
+                    IFS="${old_ifs}"
+                    mknod -m "${TMODE}" "${TPATH}" c "$@"
+            fi
+            ;;
+
+    *)
+            echo ERROR
+            exit 1
+            ;;
+    esac
+    if [ "${TUSER}" != "-" ]; then
+            chown "${TUSER}" "${TPATH}"
+    fi
+    if [ "${TGROUP}" != "-" ]; then
+            chgrp "${TGROUP}" "${TPATH}"
+    fi
+    done
+}
+
 case "$1" in
   start)
     export ACTION=add
@@ -51,6 +86,7 @@ case "$1" in
     # make_extra_nodes
     kill_udevd > "/dev/null" 2>&1
 
+    make_static_nodes
     # trigger the sorted events
     [ -e /proc/sys/kernel/hotplug ] && printf '\0\n' >/proc/sys/kernel/hotplug
     @UDEVD@ -d
meta/recipes-core/udev/eudev_3.2.11.bb +2 -0
index 841039f6d7..e4f78c2b0c 100644
@@ -41,6 +41,7 @@ do_install:append() {
 	install -d ${D}${sysconfdir}/init.d
 	install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/udev
 	sed -i s%@UDEVD@%${base_sbindir}/udevd% ${D}${sysconfdir}/init.d/udev
+	sed -i s%@KMOD@%${base_sbindir}/kmod% ${D}${sysconfdir}/init.d/udev
 
 	install -d ${D}${sysconfdir}/udev/rules.d
 	install -m 0644 ${WORKDIR}/local.rules ${D}${sysconfdir}/udev/rules.d/local.rules
@@ -73,6 +74,7 @@ FILES:libudev = "${base_libdir}/libudev.so.*"
 FILES:eudev-hwdb = "${sysconfdir}/udev/hwdb.d"
 
 RDEPENDS:eudev-hwdb += "eudev"
+RDEPENDS:eudev += "kmod"
 
 RPROVIDES:${PN} = "hotplug udev"
 RPROVIDES:eudev-hwdb += "udev-hwdb"
Signature · 1 line
2.25.1
#1 lore raw
Quoted 28 lines · On Thu, May 19, 2022 at 9:57 AM <[email protected]> wrote:

From: Changqing Li <[email protected]>

dev in modules.devname should be populated in /dev on boot. remove create static mode from udevd will make these devices cannot be populated. Since commit [1], when use sysVinit, devices like /dev/net/tun will not be created.

more info:
udevd in systemd also remove create static mode in udevd, but using service kmod-static-nodes.service and systemd-tmpfiles-setup-dev.service in systemd to create these node, so systemd works well.

For sysV, parse kmod static-nodes and generate the device nodes in init

[1] https://gitweb.gentoo.org/proj/eudev.git/commit/?id=2b7abd5ec9cc47a8b895df6db77fb1537c6f1a39

---
 meta/recipes-core/udev/eudev/init      | 36 ++++++++++++++++++++++++++
 meta/recipes-core/udev/eudev_3.2.11.bb |  2 ++
 2 files changed, 38 insertions(+)
meta/recipes-core/udev/eudev/init +0 -0
index c60dbbf6d5..5c2fb4a9fb 100644

meta/recipes-core/udev/eudev/init kill_udevd () { · line 30

Quoted 8 lines
meta/recipes-core/udev/eudev/init +5 -0
@@ -23,6 +23,41 @@ kill_udevd () {
     [ -n "$pid" ] && kill $pid
 }
 
+make_static_nodes () {
+    [ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
+    [ -x @KMOD@ ] || return 0
+
+    kmod static-nodes --format=tmpfiles --output=/proc/self/fd/1 |

Is that --output=... really needed? Also if we're substituting for the full kmod path with @KMOD@ we should do the same here.

Quoted 9 lines
meta/recipes-core/udev/eudev/init +9 -0
+    while read TTYPE TPATH TMODE TUSER TGROUP TAGE TARG; do
+    case "${TTYPE}" in
+    'd')
+            test -d "${TPATH}" || mkdir -p -m "${TMODE}" "${TPATH}"
+            ;;
+
+    'c!')
+            if [ ! -c "${TPATH}" ]; then
+                    old_ifs="${IFS}"

meta/recipes-core/udev/eudev/init kill_udevd () { · line 49

Quoted 10 lines
meta/recipes-core/udev/eudev/init +10 -0
+                    IFS=:
+                    set -- ${TARG}
+                    IFS="${old_ifs}"
+                    mknod -m "${TMODE}" "${TPATH}" c "$@"
+            fi
+            ;;
+
+    *)
+            echo ERROR
+            exit 1

I don't know what the right answer is if you end up here - blundering on regardless I guess is more typical behaviour for sysvinit, so just use a better error message and don't exit?

Quoted 45 lines
meta/recipes-core/udev/eudev/init +12 -0
+            ;;
+    esac
+    if [ "${TUSER}" != "-" ]; then
+            chown "${TUSER}" "${TPATH}"
+    fi
+    if [ "${TGROUP}" != "-" ]; then
+            chgrp "${TGROUP}" "${TPATH}"
+    fi
+    done
+}
+
 case "$1" in
   start)
     export ACTION=add
@@ -51,6 +86,7 @@ case "$1" in
     # make_extra_nodes
     kill_udevd > "/dev/null" 2>&1
 
+    make_static_nodes
     # trigger the sorted events
     [ -e /proc/sys/kernel/hotplug ] && printf '\0\n' >/proc/sys/kernel/hotplug
     @UDEVD@ -d
meta/recipes-core/udev/eudev_3.2.11.bb +2 -1
index 841039f6d7..e4f78c2b0c 100644
@@ -41,6 +41,7 @@ do_install:append() {
        install -d ${D}${sysconfdir}/init.d
        install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/udev
        sed -i s%@UDEVD@%${base_sbindir}/udevd% ${D}${sysconfdir}/init.d/udev
+       sed -i s%@KMOD@%${base_sbindir}/kmod% ${D}${sysconfdir}/init.d/udev
 
        install -d ${D}${sysconfdir}/udev/rules.d
        install -m 0644 ${WORKDIR}/local.rules ${D}${sysconfdir}/udev/rules.d/local.rules
@@ -73,6 +74,7 @@ FILES:libudev = "${base_libdir}/libudev.so.*"
 FILES:eudev-hwdb = "${sysconfdir}/udev/hwdb.d"
 
 RDEPENDS:eudev-hwdb += "eudev"
+RDEPENDS:eudev += "kmod"
 
 RPROVIDES:${PN} = "hotplug udev"
 RPROVIDES:eudev-hwdb += "udev-hwdb"
--

2.25.1

Signature · 1 line
Alex Kiernan
#2 lore raw

________________________________
From: Alex Kiernan <[email protected]>
Sent: Thursday, May 19, 2022 10:14 PM
To: Li, Changqing <[email protected]>
Cc: Patches and discussions about the oe-core layer <[email protected]>; Richard Purdie <[email protected]>
Subject: Re: [PATCH] eudev: create static-nodes in init script

[Please note: This e-mail is from an EXTERNAL e-mail address]

Quoted 28 lines · On Thu, May 19, 2022 at 9:57 AM <[email protected]> wrote:

From: Changqing Li <[email protected]>

dev in modules.devname should be populated in /dev on boot. remove create static mode from udevd will make these devices cannot be populated. Since commit [1], when use sysVinit, devices like /dev/net/tun will not be created.

more info:
udevd in systemd also remove create static mode in udevd, but using service kmod-static-nodes.service and systemd-tmpfiles-setup-dev.service in systemd to create these node, so systemd works well.

For sysV, parse kmod static-nodes and generate the device nodes in init

[1] https://gitweb.gentoo.org/proj/eudev.git/commit/?id=2b7abd5ec9cc47a8b895df6db77fb1537c6f1a39

---
 meta/recipes-core/udev/eudev/init      | 36 ++++++++++++++++++++++++++
 meta/recipes-core/udev/eudev_3.2.11.bb |  2 ++
 2 files changed, 38 insertions(+)
meta/recipes-core/udev/eudev/init +0 -0
index c60dbbf6d5..5c2fb4a9fb 100644

meta/recipes-core/udev/eudev/init kill_udevd () { · line 30

Quoted 8 lines
meta/recipes-core/udev/eudev/init +5 -0
@@ -23,6 +23,41 @@ kill_udevd () {
     [ -n "$pid" ] && kill $pid
 }
 
+make_static_nodes () {
+    [ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
+    [ -x @KMOD@ ] || return 0
+
+    kmod static-nodes --format=tmpfiles --output=/proc/self/fd/1 |

Is that --output=... really needed?

add output since kmod output to /dev/stdout by default,but we run make_static_nodes before udevd, /dev/stdout is created by udevd.

Also if we're substituting for the full kmod path with @KMOD@ we should do the same here. OK.

Quoted 9 lines
meta/recipes-core/udev/eudev/init +9 -0
+    while read TTYPE TPATH TMODE TUSER TGROUP TAGE TARG; do
+    case "${TTYPE}" in
+    'd')
+            test -d "${TPATH}" || mkdir -p -m "${TMODE}" "${TPATH}"
+            ;;
+
+    'c!')
+            if [ ! -c "${TPATH}" ]; then
+                    old_ifs="${IFS}"

meta/recipes-core/udev/eudev/init kill_udevd () { · line 49

Quoted 10 lines
meta/recipes-core/udev/eudev/init +10 -0
+                    IFS=:
+                    set -- ${TARG}
+                    IFS="${old_ifs}"
+                    mknod -m "${TMODE}" "${TPATH}" c "$@"
+            fi
+            ;;
+
+    *)
+            echo ERROR
+            exit 1

I don't know what the right answer is if you end up here - blundering on regardless I guess is more typical behaviour for sysvinit, so just use a better error message and don't exit?

Get this.

Quoted 43 lines
meta/recipes-core/udev/eudev/init +12 -0
+            ;;
+    esac
+    if [ "${TUSER}" != "-" ]; then
+            chown "${TUSER}" "${TPATH}"
+    fi
+    if [ "${TGROUP}" != "-" ]; then
+            chgrp "${TGROUP}" "${TPATH}"
+    fi
+    done
+}
+
 case "$1" in
   start)
     export ACTION=add
@@ -51,6 +86,7 @@ case "$1" in
     # make_extra_nodes
     kill_udevd > "/dev/null" 2>&1
 
+    make_static_nodes
     # trigger the sorted events
     [ -e /proc/sys/kernel/hotplug ] && printf '\0\n' >/proc/sys/kernel/hotplug
     @UDEVD@ -d
meta/recipes-core/udev/eudev_3.2.11.bb +2 -1
index 841039f6d7..e4f78c2b0c 100644
@@ -41,6 +41,7 @@ do_install:append() {
        install -d ${D}${sysconfdir}/init.d
        install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/udev
        sed -i s%@UDEVD@%${base_sbindir}/udevd% ${D}${sysconfdir}/init.d/udev
+       sed -i s%@KMOD@%${base_sbindir}/kmod% ${D}${sysconfdir}/init.d/udev
 
        install -d ${D}${sysconfdir}/udev/rules.d
        install -m 0644 ${WORKDIR}/local.rules ${D}${sysconfdir}/udev/rules.d/local.rules
@@ -73,6 +74,7 @@ FILES:libudev = "${base_libdir}/libudev.so.*"
 FILES:eudev-hwdb = "${sysconfdir}/udev/hwdb.d"
 
 RDEPENDS:eudev-hwdb += "eudev"
+RDEPENDS:eudev += "kmod"
 
 RPROVIDES:${PN} = "hotplug udev"
 RPROVIDES:eudev-hwdb += "udev-hwdb"
--
Quoted 2 lines

2.25.1

--
Alex Kiernan

#3 lore raw
Quoted 52 lines · Changqing

________________________________
From: Alex Kiernan <[email protected]>
Sent: Thursday, May 19, 2022 10:14 PM
To: Li, Changqing <[email protected]>
Cc: Patches and discussions about the oe-core layer <[email protected]>; Richard Purdie <[email protected]>
Subject: Re: [PATCH] eudev: create static-nodes in init script

[Please note: This e-mail is from an EXTERNAL e-mail address]

Quoted 28 lines · On Thu, May 19, 2022 at 9:57 AM <[email protected]> wrote:

From: Changqing Li <[email protected]>

dev in modules.devname should be populated in /dev on boot. remove create static mode from udevd will make these devices cannot be populated. Since commit [1], when use sysVinit, devices like /dev/net/tun will not be created.

more info:
udevd in systemd also remove create static mode in udevd, but using service kmod-static-nodes.service and systemd-tmpfiles-setup-dev.service in systemd to create these node, so systemd works well.

For sysV, parse kmod static-nodes and generate the device nodes in init

[1] https://gitweb.gentoo.org/proj/eudev.git/commit/?id=2b7abd5ec9cc47a8b895df6db77fb1537c6f1a39

---
 meta/recipes-core/udev/eudev/init      | 36 ++++++++++++++++++++++++++
 meta/recipes-core/udev/eudev_3.2.11.bb |  2 ++
 2 files changed, 38 insertions(+)
meta/recipes-core/udev/eudev/init +0 -0
index c60dbbf6d5..5c2fb4a9fb 100644

meta/recipes-core/udev/eudev/init kill_udevd () { · line 30

Quoted 8 lines
meta/recipes-core/udev/eudev/init +5 -0
@@ -23,6 +23,41 @@ kill_udevd () {
     [ -n "$pid" ] && kill $pid
 }
 
+make_static_nodes () {
+    [ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
+    [ -x @KMOD@ ] || return 0
+
+    kmod static-nodes --format=tmpfiles --output=/proc/self/fd/1 |

Is that --output=... really needed?

Quoted 3 lines

add output since kmod output to /dev/stdout by default,but we run make_static_nodes before udevd, /dev/stdout is created by udevd.

Oh, that's interesting - I suspect it's worth capturing as a comment so the next person looking at it doesn't have the same question as me!

Quoted 78 lines

Also if we're substituting for the full kmod path with @KMOD@ we should do the same here. OK.

Quoted 9 lines
meta/recipes-core/udev/eudev/init +9 -0
+    while read TTYPE TPATH TMODE TUSER TGROUP TAGE TARG; do
+    case "${TTYPE}" in
+    'd')
+            test -d "${TPATH}" || mkdir -p -m "${TMODE}" "${TPATH}"
+            ;;
+
+    'c!')
+            if [ ! -c "${TPATH}" ]; then
+                    old_ifs="${IFS}"

meta/recipes-core/udev/eudev/init kill_udevd () { · line 49

Quoted 10 lines
meta/recipes-core/udev/eudev/init +10 -0
+                    IFS=:
+                    set -- ${TARG}
+                    IFS="${old_ifs}"
+                    mknod -m "${TMODE}" "${TPATH}" c "$@"
+            fi
+            ;;
+
+    *)
+            echo ERROR
+            exit 1

I don't know what the right answer is if you end up here - blundering on regardless I guess is more typical behaviour for sysvinit, so just use a better error message and don't exit?

Get this.

Quoted 43 lines
meta/recipes-core/udev/eudev/init +12 -0
+            ;;
+    esac
+    if [ "${TUSER}" != "-" ]; then
+            chown "${TUSER}" "${TPATH}"
+    fi
+    if [ "${TGROUP}" != "-" ]; then
+            chgrp "${TGROUP}" "${TPATH}"
+    fi
+    done
+}
+
 case "$1" in
   start)
     export ACTION=add
@@ -51,6 +86,7 @@ case "$1" in
     # make_extra_nodes
     kill_udevd > "/dev/null" 2>&1
 
+    make_static_nodes
     # trigger the sorted events
     [ -e /proc/sys/kernel/hotplug ] && printf '\0\n' >/proc/sys/kernel/hotplug
     @UDEVD@ -d
meta/recipes-core/udev/eudev_3.2.11.bb +2 -1
index 841039f6d7..e4f78c2b0c 100644
@@ -41,6 +41,7 @@ do_install:append() {
        install -d ${D}${sysconfdir}/init.d
        install -m 0755 ${WORKDIR}/init ${D}${sysconfdir}/init.d/udev
        sed -i s%@UDEVD@%${base_sbindir}/udevd% ${D}${sysconfdir}/init.d/udev
+       sed -i s%@KMOD@%${base_sbindir}/kmod% ${D}${sysconfdir}/init.d/udev
 
        install -d ${D}${sysconfdir}/udev/rules.d
        install -m 0644 ${WORKDIR}/local.rules ${D}${sysconfdir}/udev/rules.d/local.rules
@@ -73,6 +74,7 @@ FILES:libudev = "${base_libdir}/libudev.so.*"
 FILES:eudev-hwdb = "${sysconfdir}/udev/hwdb.d"
 
 RDEPENDS:eudev-hwdb += "eudev"
+RDEPENDS:eudev += "kmod"
 
 RPROVIDES:${PN} = "hotplug udev"
 RPROVIDES:eudev-hwdb += "udev-hwdb"
--
Quoted 2 lines

2.25.1

--
Alex Kiernan

Signature · 1 line
Alex Kiernan