On Thu, 27 Jul 2023 11:11:41 +0100
Mark Hindley <m...@hindley.org.uk> wrote:

Hi Mark,

> On Wed, Jul 26, 2023 at 08:22:15PM +0100, Matthew Vernon wrote:
> > Hi,
> > 
> > On 26/07/2023 19:43, lorenzo wrote:
> > 
> > > may I suggest to add this script to initscripts
> > > package(sysvinit:src) instead of o-s-s?
> > > A system without udev is not very common after all and the vast
> > > majority of scripts strictly needed to boot and shutdown the
> > > system are shipped there.
> > 
> [...]
> 
> I can see some logic to this approach. 
> 
> I am away until next week, but can look at it then.
> 

I'm attaching git patches that can be 'git am' on top of the master
branch at
https://salsa.debian.org/debian/sysvinit/-/tree/master?ref_type=heads

Since I'm on holiday and away from from my testing setup, I did no test
to ensure that this warks as intended, so consider it as experimental.
Also, the "breaks and replaces" patch need to be amended with the
version of systemd that removes the udev script, which is unknwnown to
me (I used the unreleased 254.1-3, which of course is wrong).
Anyway I think there need to be some work on udev's side to ensure that
the udev script is not removed when the initscripts package is
installed in the system.

Hope this helps,
Lorenzo

> Mark

>From db26e458e3d84430069a063d928d7ee8bffb59a4 Mon Sep 17 00:00:00 2001
From: Lorenzo Puliti <plore...@disroot.org>
Date: Sat, 19 Aug 2023 18:07:30 +0200
Subject: [PATCH 1/5] Import udev script from systemd:src

import udev script as a copy of udev.init from systemd source
---
 debian/src/initscripts/etc/init.d/udev | 255 +++++++++++++++++++++++++
 1 file changed, 255 insertions(+)
 create mode 100644 debian/src/initscripts/etc/init.d/udev

diff --git a/debian/src/initscripts/etc/init.d/udev b/debian/src/initscripts/etc/init.d/udev
new file mode 100644
index 00000000..bb54f610
--- /dev/null
+++ b/debian/src/initscripts/etc/init.d/udev
@@ -0,0 +1,255 @@
+#!/bin/sh -e
+### BEGIN INIT INFO
+# Provides:          udev
+# Required-Start:    mountkernfs
+# Required-Stop:     umountroot
+# Default-Start:     S
+# Default-Stop:      0 6
+# Short-Description: Start systemd-udevd, populate /dev and load drivers.
+### END INIT INFO
+
+PATH="/sbin:/bin"
+NAME="systemd-udevd"
+DAEMON="/lib/systemd/systemd-udevd"
+DESC="hotplug events dispatcher"
+PIDFILE="/run/udev.pid"
+CTRLFILE="/run/udev/control"
+OMITDIR="/run/sendsigs.omit.d"
+
+# we need to unmount /dev/pts/ and remount it later over the devtmpfs
+unmount_devpts() {
+  if mountpoint -q /dev/pts/; then
+    umount -n -l /dev/pts/
+  fi
+
+  if mountpoint -q /dev/shm/; then
+    umount -n -l /dev/shm/
+  fi
+}
+
+# mount a devtmpfs over /dev, if somebody did not already do it
+mount_devtmpfs() {
+  if grep -E -q "^[^[:space:]]+ /dev devtmpfs" /proc/mounts; then
+    mount -n -o remount,nosuid,size=$tmpfs_size,mode=0755 -t devtmpfs devtmpfs /dev
+    return
+  fi
+
+  if ! mount -n -o nosuid,size=$tmpfs_size,mode=0755 -t devtmpfs devtmpfs /dev; then
+    log_failure_msg "udev requires devtmpfs support, not started"
+    log_end_msg 1
+  fi
+
+  return 0
+}
+
+create_dev_makedev() {
+  if [ -e /sbin/MAKEDEV ]; then
+    ln -sf /sbin/MAKEDEV /dev/MAKEDEV
+  else
+    ln -sf /bin/true /dev/MAKEDEV
+  fi
+}
+
+# shell version of /usr/bin/tty
+my_tty() {
+  [ -x /bin/readlink ] || return 0
+  [ -e /proc/self/fd/0 ] || return 0
+  readlink --silent /proc/self/fd/0 || true
+}
+
+warn_if_interactive() {
+  if [ "$RUNLEVEL" = "S" -a "$PREVLEVEL" = "N" ]; then
+    return
+  fi
+
+  TTY=$(my_tty)
+  if [ -z "$TTY" -o "$TTY" = "/dev/console" -o "$TTY" = "/dev/null" ]; then
+    return
+  fi
+
+  printf "\n\n\nIt has been detected that the command\n\n\t$0 $*\n\n"
+  printf "has been run from an interactive shell.\n"
+  printf "It will probably not do what you expect, so this script will wait\n"
+  printf "60 seconds before continuing. Press ^C to stop it.\n"
+  printf "RUNNING THIS COMMAND IS HIGHLY DISCOURAGED!\n\n\n\n"
+  sleep 60
+}
+
+make_static_nodes() {
+  [ -e /lib/modules/$(uname -r)/modules.devname ] || return 0
+  [ -x /bin/kmod ] || return 0
+
+  /bin/kmod static-nodes --format=tmpfiles --output=/proc/self/fd/1 | \
+  while read type name mode uid gid age arg; do
+    [ -e $name ] && continue
+    case "$type" in
+      c|b|c!|b!) mknod -m $mode $name $type $(echo $arg | sed 's/:/ /') ;;
+      d|d!) mkdir $name ;;
+      *) echo "unparseable line ($type $name $mode $uid $gid $age $arg)" >&2 ;;
+    esac
+
+    if [ -x /sbin/restorecon ]; then
+      /sbin/restorecon $name
+    fi
+  done
+}
+
+
+##############################################################################
+
+
+[ -x $DAEMON ] || exit 0
+
+# defaults
+tmpfs_size="10M"
+
+if [ -e /etc/udev/udev.conf ]; then
+  . /etc/udev/udev.conf
+fi
+
+. /lib/lsb/init-functions
+
+if [ ! -e /proc/filesystems ]; then
+  log_failure_msg "udev requires a mounted procfs, not started"
+  log_end_msg 1
+fi
+
+if ! grep -q '[[:space:]]devtmpfs$' /proc/filesystems; then
+  log_failure_msg "udev requires devtmpfs support, not started"
+  log_end_msg 1
+fi
+
+if [ ! -d /sys/class/ ]; then
+  log_failure_msg "udev requires a mounted sysfs, not started"
+  log_end_msg 1
+fi
+
+if [ ! -w /sys ]; then
+  log_warning_msg "udev does not support containers, not started"
+  exit 0
+fi
+
+if [ -d /sys/class/mem/null -a ! -L /sys/class/mem/null ] || \
+   [ -e /sys/block -a ! -e /sys/class/block ]; then
+  log_warning_msg "CONFIG_SYSFS_DEPRECATED must not be selected"
+  log_warning_msg "Booting will continue in 30 seconds but many things will be broken"
+  sleep 30
+fi
+
+# When modifying this script, do not forget that between the time that the
+# new /dev has been mounted and udevadm trigger has been run there will be
+# no /dev/null. This also means that you cannot use the "&" shell command.
+
+case "$1" in
+    start)
+    if [ ! -e "/run/udev/" ]; then
+        warn_if_interactive
+    fi
+
+    if [ -w /sys/kernel/uevent_helper ]; then
+        echo > /sys/kernel/uevent_helper
+    fi
+
+    if ! mountpoint -q /dev/; then
+        unmount_devpts
+        mount_devtmpfs
+        [ -d /proc/1 ] || mount -n /proc
+    fi
+
+    make_static_nodes
+
+    # clean up parts of the database created by the initramfs udev
+    udevadm info --cleanup-db
+
+    # set the SELinux context for devices created in the initramfs
+    [ -x /sbin/restorecon ] && /sbin/restorecon -R /dev
+
+    log_daemon_msg "Starting $DESC" "$NAME"
+    if start-stop-daemon --start --name $NAME --user root --quiet \
+        --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile \
+        --notify-await; then
+        # prevents udevd to be killed by sendsigs (see #791944)
+        mkdir -p $OMITDIR
+        ln -sf $PIDFILE $OMITDIR/$NAME
+        log_end_msg $?
+    else
+        log_warning_msg $?
+        log_warning_msg "Waiting 15 seconds and trying to continue anyway"
+        sleep 15
+    fi
+
+    log_action_begin_msg "Synthesizing the initial hotplug events (subsystems)"
+    if udevadm trigger --type=subsystems --action=add; then
+        log_action_end_msg $?
+    else
+        log_action_end_msg $?
+    fi
+    log_action_begin_msg "Synthesizing the initial hotplug events (devices)"
+    if udevadm trigger --type=devices --action=add; then
+        log_action_end_msg $?
+    else
+        log_action_end_msg $?
+    fi
+
+    create_dev_makedev
+
+    # wait for the systemd-udevd childs to finish
+    log_action_begin_msg "Waiting for /dev to be fully populated"
+    if udevadm settle; then
+        log_action_end_msg 0
+    else
+        log_action_end_msg 0 'timeout'
+    fi
+    ;;
+
+    stop)
+    log_daemon_msg "Stopping $DESC" "$NAME"
+    if start-stop-daemon --stop --name $NAME --user root --quiet \
+        --pidfile $PIDFILE --remove-pidfile --oknodo --retry 5; then
+        # prevents cryptsetup/dmsetup hangs (see #791944)
+        rm -f $CTRLFILE
+        log_end_msg $?
+    else
+        log_end_msg $?
+    fi
+    ;;
+
+    restart)
+    log_daemon_msg "Stopping $DESC" "$NAME"
+    if start-stop-daemon --stop --name $NAME --user root --quiet \
+        --pidfile $PIDFILE --remove-pidfile --oknodo --retry 5; then
+        # prevents cryptsetup/dmsetup hangs (see #791944)
+        rm -f $CTRLFILE
+        log_end_msg $?
+    else
+        log_end_msg $? || true
+    fi
+
+    log_daemon_msg "Starting $DESC" "$NAME"
+    if start-stop-daemon --start --name $NAME --user root --quiet \
+        --pidfile $PIDFILE --exec $DAEMON --background --make-pidfile \
+        --notify-await; then
+        # prevents udevd to be killed by sendsigs (see #791944)
+        mkdir -p $OMITDIR
+        ln -sf $PIDFILE $OMITDIR/$NAME
+        log_end_msg $?
+    else
+        log_end_msg $?
+    fi
+    ;;
+
+    reload|force-reload)
+    udevadm control --reload-rules
+    ;;
+
+    status)
+    status_of_proc $DAEMON $NAME && exit 0 || exit $?
+    ;;
+
+    *)
+    echo "Usage: /etc/init.d/udev {start|stop|restart|reload|force-reload|status}" >&2
+    exit 1
+    ;;
+esac
+
+exit 0
-- 
2.40.1

>From cf58e90dc0d08fbdf6385e3f22d30247cb1b3df8 Mon Sep 17 00:00:00 2001
From: Lorenzo Puliti <plore...@disroot.org>
Date: Sat, 19 Aug 2023 18:24:31 +0200
Subject: [PATCH 2/5] add udev to initscripts postinst and postrm

Add udev to the list of scripts that are acted on in initscript's
postinst and postrm
---
 debian/initscripts.postinst | 2 +-
 debian/initscripts.postrm   | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/debian/initscripts.postinst b/debian/initscripts.postinst
index 32c0afb0..dd7c9715 100755
--- a/debian/initscripts.postinst
+++ b/debian/initscripts.postinst
@@ -20,7 +20,7 @@ esac
 
 umask 022
 
-INITSCRIPTS="mountkernfs.sh mount-configfs brightness hostname.sh mountdevsubfs.sh checkroot.sh \
+INITSCRIPTS="mountkernfs.sh udev mount-configfs brightness hostname.sh mountdevsubfs.sh checkroot.sh \
 	checkroot-bootclean.sh checkfs.sh mountall.sh mountall-bootclean.sh \
 	mountnfs.sh mountnfs-bootclean.sh bootmisc.sh urandom halt reboot \
 	umountroot umountfs umountnfs.sh sendsigs killprocs single motd \
diff --git a/debian/initscripts.postrm b/debian/initscripts.postrm
index 5e232568..929ed853 100755
--- a/debian/initscripts.postrm
+++ b/debian/initscripts.postrm
@@ -5,7 +5,7 @@
 
 set -e
 
-INITSCRIPTS="mountkernfs.sh mount-configfs brightness hostname.sh mountdevsubfs.sh checkroot.sh \
+INITSCRIPTS="mountkernfs.sh udev mount-configfs brightness hostname.sh mountdevsubfs.sh checkroot.sh \
 	checkroot-bootclean.sh checkfs.sh mountall.sh mountall-bootclean.sh \
 	mountnfs.sh mountnfs-bootclean.sh bootmisc.sh urandom halt reboot \
 	umountroot umountfs umountnfs.sh sendsigs killprocs single motd \
-- 
2.40.1

From 09dea2221b810ab9f0ce325dcbe46c238b7fbf4c Mon Sep 17 00:00:00 2001
From: Lorenzo Puliti <plore...@disroot.org>
Date: Sat, 19 Aug 2023 18:41:17 +0200
Subject: [PATCH 3/5] update d/copyright

update copyright with info provided by Luca Boccassi <bl...@debian.org>
in #1042082
---
 debian/copyright | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/debian/copyright b/debian/copyright
index 884a7790..0ee4bcb2 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -44,6 +44,14 @@ Copyright: 1996-2004 Miquel van Smoorenburg <miqu...@cistron.nl>
            2021 Mark Hindley <lee...@debian.org>
 License: GPL-2.0+
 
+Files: debian/src/initscripts/etc/init.d/udev
+Copyright: 2013 Michael Stapelberg <mich...@stapelberg.de>
+           2014-2015 Martin Pitt <martin.p...@ubuntu.com>
+           2018 Felipe Sateler <fsate...@debian.org>
+           2013-2019 Michael Biebl <bi...@debian.org>
+           2020 Topi Miettinen <toiwo...@gmail.com>
+License: LGPL-2.1+
+
 Files: contrib/sysd2v.sh
 Copyright: 2019 Trek http://www.trek.eu.org/devel/sysd2v
 License: GPL-3.0
@@ -87,3 +95,21 @@ License: GPL-2.0
  .
  On Debian systems you can find a local copy of the GNU General Public License
  in /usr/share/common-licenses/GPL-2.
+
+License: LGPL-2.1+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1, or (at your option)
+ any later version.
+ .
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ GNU Lesser General Public License for more details.
+ .
+ You should have received a copy of the GNU Lesser General Public License along
+ with this program; if not, write to the Free Software Foundation,
+ Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ .
+ On Debian systems, the complete text of the GNU Lesser General Public
+ License version 2.1 can be found in ‘/usr/share/common-licenses/LGPL-2.1’.
-- 
2.40.1

>From 7be66c25a9fae8699a0a293a0b10459f916a4ad4 Mon Sep 17 00:00:00 2001
From: Lorenzo Puliti <plore...@disroot.org>
Date: Sat, 19 Aug 2023 18:57:49 +0200
Subject: [PATCH 4/5] remove x mode from udev on non-linux archs

initscripts postinst: remove x mode from udev script on non-linux
archs so that the script is skipped by update-rc.d
---
 debian/initscripts.postinst | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/debian/initscripts.postinst b/debian/initscripts.postinst
index dd7c9715..202fc3fd 100755
--- a/debian/initscripts.postinst
+++ b/debian/initscripts.postinst
@@ -26,6 +26,11 @@ INITSCRIPTS="mountkernfs.sh udev mount-configfs brightness hostname.sh mountdevs
 	umountroot umountfs umountnfs.sh sendsigs killprocs single motd \
 	bootlogs rc.local rmnologin"
 
+if [ "$(uname -s)" != Linux ]; then
+# udev is linux-any but this  package is arch:all
+	chmod -x /etc/init.d/udev
+fi
+
 for F in $INITSCRIPTS; do
 	if [ -x /etc/init.d/$F ]; then
 		update-rc.d $F defaults >/dev/null || exit $?
-- 
2.40.1

>From 4d29549627e5af17c35686a03b0924107fa4b094 Mon Sep 17 00:00:00 2001
From: Lorenzo Puliti <plore...@disroot.org>
Date: Sat, 19 Aug 2023 19:59:56 +0200
Subject: [PATCH 5/5] Breaks and Replaces with udev

breaks and replaces with the last version of udev that ships
udev.init as initscript

Closes: #1042082
---
 debian/control | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/debian/control b/debian/control
index e3b9c91c..c9bd40af 100644
--- a/debian/control
+++ b/debian/control
@@ -100,6 +100,8 @@ Depends:
  sysvinit-utils (>= 3.05-1),
  sysv-rc | file-rc | openrc,
  ${misc:Depends},
+Replaces: udev (<< 254.1-3)
+Breaks: udev (<< 254.1-3)
 Recommends:
  e2fsprogs,
  psmisc,
-- 
2.40.1

Reply via email to