From 60d48d451c97582bb7638a65540a09cf188e23c9 Mon Sep 17 00:00:00 2001 From: Nora Schiffer Date: Fri, 27 Feb 2026 20:30:32 +0100 Subject: [PATCH 1/2] gluon-setup-mode: create init.d in addition to rc.d directory Make the setup-mode-specific init scripts a bit more regular, for use with `procd -I ...`. --- .../files/lib/gluon/setup-mode/init.d/uhttpd | 14 +++ .../files/lib/gluon/setup-mode/rc.d/S50uhttpd | 15 +--- package/gluon-setup-mode/Makefile | 5 +- .../lib/gluon/setup-mode/init.d/bootcount | 7 ++ .../files/lib/gluon/setup-mode/init.d/dnsmasq | 17 ++++ .../lib/gluon/setup-mode/init.d/dropbear | 15 ++++ .../gluon/setup-mode/init.d/gluon-setup-mode | 19 ++++ .../files/lib/gluon/setup-mode/init.d/led | 30 +++++++ .../files/lib/gluon/setup-mode/init.d/network | 88 ++++++++++++++++++ .../files/lib/gluon/setup-mode/init.d/urngd | 7 ++ .../lib/gluon/setup-mode/rc.d/K90network | 1 + .../lib/gluon/setup-mode/rc.d/S11bootcount | 8 +- .../files/lib/gluon/setup-mode/rc.d/S13urngd | 8 +- .../gluon/setup-mode/rc.d/S15gluon-setup-mode | 20 +---- .../lib/gluon/setup-mode/rc.d/S20network | 89 +------------------ .../lib/gluon/setup-mode/rc.d/S50dropbear | 16 +--- .../lib/gluon/setup-mode/rc.d/S60dnsmasq | 18 +--- .../files/lib/gluon/setup-mode/rc.d/S96led | 31 +------ 18 files changed, 208 insertions(+), 200 deletions(-) create mode 100755 package/gluon-config-mode-core/files/lib/gluon/setup-mode/init.d/uhttpd mode change 100755 => 120000 package/gluon-config-mode-core/files/lib/gluon/setup-mode/rc.d/S50uhttpd create mode 100755 package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/bootcount create mode 100755 package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/dnsmasq create mode 100755 package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/dropbear create mode 100755 package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/gluon-setup-mode create mode 100755 package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/led create mode 100755 package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/network create mode 100755 package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/urngd create mode 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K90network mode change 100755 => 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11bootcount mode change 100755 => 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S13urngd mode change 100755 => 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S15gluon-setup-mode mode change 100755 => 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network mode change 100755 => 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear mode change 100755 => 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S60dnsmasq mode change 100755 => 120000 package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led diff --git a/package/gluon-config-mode-core/files/lib/gluon/setup-mode/init.d/uhttpd b/package/gluon-config-mode-core/files/lib/gluon/setup-mode/init.d/uhttpd new file mode 100755 index 0000000000..efd1d6121f --- /dev/null +++ b/package/gluon-config-mode-core/files/lib/gluon/setup-mode/init.d/uhttpd @@ -0,0 +1,14 @@ +#!/bin/sh /etc/rc.common + +START=50 + +USE_PROCD=1 + +UHTTPD_BIN="/usr/sbin/uhttpd" + +start_service() { + procd_open_instance + procd_set_param respawn + procd_set_param command "$UHTTPD_BIN" -f -h /lib/gluon/config-mode/www -x /cgi-bin -A 1 -R -p 0.0.0.0:80 + procd_close_instance +} diff --git a/package/gluon-config-mode-core/files/lib/gluon/setup-mode/rc.d/S50uhttpd b/package/gluon-config-mode-core/files/lib/gluon/setup-mode/rc.d/S50uhttpd deleted file mode 100755 index efd1d6121f..0000000000 --- a/package/gluon-config-mode-core/files/lib/gluon/setup-mode/rc.d/S50uhttpd +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/sh /etc/rc.common - -START=50 - -USE_PROCD=1 - -UHTTPD_BIN="/usr/sbin/uhttpd" - -start_service() { - procd_open_instance - procd_set_param respawn - procd_set_param command "$UHTTPD_BIN" -f -h /lib/gluon/config-mode/www -x /cgi-bin -A 1 -R -p 0.0.0.0:80 - procd_close_instance -} diff --git a/package/gluon-config-mode-core/files/lib/gluon/setup-mode/rc.d/S50uhttpd b/package/gluon-config-mode-core/files/lib/gluon/setup-mode/rc.d/S50uhttpd new file mode 120000 index 0000000000..f44eb0e71b --- /dev/null +++ b/package/gluon-config-mode-core/files/lib/gluon/setup-mode/rc.d/S50uhttpd @@ -0,0 +1 @@ +../init.d/uhttpd \ No newline at end of file diff --git a/package/gluon-setup-mode/Makefile b/package/gluon-setup-mode/Makefile index aa2bb40fc7..acc012decb 100644 --- a/package/gluon-setup-mode/Makefile +++ b/package/gluon-setup-mode/Makefile @@ -36,10 +36,9 @@ init_links := \ define Package/gluon-setup-mode/install $(Gluon/Build/Install) - $(LN) S20network $(1)/lib/gluon/setup-mode/rc.d/K90network - for link in $(init_links); do \ - $(LN) "/etc/init.d/$$$${link:3}" "$(1)/lib/gluon/setup-mode/rc.d/$$$${link}"; \ + $(LN) "/etc/init.d/$$$${link:3}" "$(1)/lib/gluon/setup-mode/init.d/$$$${link:3}"; \ + $(LN) "../init.d/$$$${link:3}" "$(1)/lib/gluon/setup-mode/rc.d/$$$${link}"; \ done $(INSTALL_BIN) $(PKG_BUILD_DIR)/ash-wrapper $(1)/lib/gluon/setup-mode/dropbear/ash diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/bootcount b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/bootcount new file mode 100755 index 0000000000..0c1ff1f2db --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/bootcount @@ -0,0 +1,7 @@ +#!/bin/sh /etc/rc.common + +# shellcheck disable=SC1091 + +if [ -x /etc/init.d/bootcount ] && /etc/init.d/bootcount enabled; then + . /etc/init.d/bootcount +fi diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/dnsmasq b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/dnsmasq new file mode 100755 index 0000000000..d275b4bf0b --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/dnsmasq @@ -0,0 +1,17 @@ +#!/bin/sh /etc/rc.common + +SETUP_MODE_DHCP_RANGE=192.168.1.2,192.168.1.254 + + +START=60 + +USE_PROCD=1 +PROG=/usr/sbin/dnsmasq + + +start_service() { + procd_open_instance + procd_set_param command $PROG -k -p 0 -F $SETUP_MODE_DHCP_RANGE -l /tmp/dhcp.leases -O option:router + procd_set_param respawn + procd_close_instance +} diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/dropbear b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/dropbear new file mode 100755 index 0000000000..0e9c7cb9f8 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/dropbear @@ -0,0 +1,15 @@ +#!/bin/sh /etc/rc.common + +# shellcheck disable=SC1091 + +[ -x /etc/init.d/dropbear ] || return 0 +. /etc/init.d/dropbear + +start_service() { + hk_generate_as_needed + + procd_open_instance + procd_set_param command /lib/gluon/setup-mode/dropbear/dropbear -F -B + procd_set_param respawn + procd_close_instance +} diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/gluon-setup-mode b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/gluon-setup-mode new file mode 100755 index 0000000000..6030b9b2c2 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/gluon-setup-mode @@ -0,0 +1,19 @@ +#!/bin/sh /etc/rc.common + +START=15 + +boot() { + local enabled configured + enabled="$(uci -q get 'gluon-setup-mode.@setup_mode[0].enabled')" + configured="$(uci -q get 'gluon-setup-mode.@setup_mode[0].configured')" + + uci set 'gluon-setup-mode.@setup_mode[0].enabled=0' + uci commit gluon-setup-mode + + if [ "$enabled" != 1 ] && [ "$configured" = 1 ]; then + # This can happen after an upgrade from a version before the config file was called gluon-setup-mode + # We'll just reboot to return to the normal mode... + /etc/init.d/done boot + reboot + fi +} diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/led b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/led new file mode 100755 index 0000000000..fb3be6d368 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/led @@ -0,0 +1,30 @@ +#!/bin/sh /etc/rc.common + +# shellcheck disable=SC1091,SC2154 + +START=96 + +start() { + local custom_led + + /etc/init.d/led start + + . /etc/diag.sh + + get_status_led 2> /dev/null + + if [ -z "$status_led" ]; then + status_led="$running" + fi + + if [ -z "$status_led" ]; then + status_led="$boot" + fi + + custom_led="$(lua -e 'print(require("gluon.setup-mode").get_status_led() or "")')" + if [ -z "$status_led" ]; then + status_led="$custom_led" + fi + + status_led_set_timer 1000 300 +} diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/network b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/network new file mode 100755 index 0000000000..9721558299 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/network @@ -0,0 +1,88 @@ +#!/bin/sh /etc/rc.common + +SETUP_MODE_ADDR=192.168.1.1 +SETUP_MODE_NETMASK=255.255.255.0 + +START=20 +STOP=90 + +USE_PROCD=1 + + +delete_interface() { + [ "$1" = 'loopback' ] || uci_remove network "$1" +} + +prepare_config() { +( + export UCI_CONFIG_DIR=/var/gluon/setup-mode/config + + mkdir -p "$UCI_CONFIG_DIR" + + cp /etc/config/network "$UCI_CONFIG_DIR" + + config_load network + config_foreach delete_interface interface + + uci_add network interface setup + uci_set network setup ifname "$(lua -e 'print(require("gluon.sysconfig").setup_ifname)')" + uci_set network setup macaddr "$(lua -e 'print(require("gluon.sysconfig").primary_mac)')" + uci_set network setup type 'bridge' + uci_set network setup proto 'static' + uci_set network setup ipaddr "$SETUP_MODE_ADDR" + uci_set network setup netmask "$SETUP_MODE_NETMASK" + + uci_commit network +) +} + +init_switch() { + setup_switch() { return 0; } + + include /lib/network + setup_switch +} + +start_service() { + prepare_config + init_switch + iw reg set "$(lua -e 'print(require("gluon.site").regdom())')" + + procd_open_instance + procd_set_param command /sbin/netifd -c /var/gluon/setup-mode/config + procd_set_param respawn + procd_set_param watch network.interface + [ -e /proc/sys/kernel/core_pattern ] && { + procd_set_param limits core="unlimited" + echo '/tmp/%e.%p.%s.%t.core' > /proc/sys/kernel/core_pattern + } + procd_close_instance +} + +reload_service() { + init_switch + ubus call network reload + /sbin/wifi reload_legacy +} + +stop_service() { + /sbin/wifi down +} + +service_running() { + ubus -t 30 wait_for network.interface + /sbin/wifi reload_legacy +} + +restart() { + ifdown -a + sleep 1 + trap '' TERM + stop "$@" + start "$@" +} + +shutdown() { + ifdown -a + stop +} diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/urngd b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/urngd new file mode 100755 index 0000000000..6e377bc554 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/init.d/urngd @@ -0,0 +1,7 @@ +#!/bin/sh /etc/rc.common + +# shellcheck disable=SC1091 + +if [ -x /etc/init.d/urngd ] && /etc/init.d/urngd enabled; then + . /etc/init.d/urngd +fi diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K90network b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K90network new file mode 120000 index 0000000000..27f4143b15 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/K90network @@ -0,0 +1 @@ +../init.d/network \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11bootcount b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11bootcount deleted file mode 100755 index 0c1ff1f2db..0000000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11bootcount +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh /etc/rc.common - -# shellcheck disable=SC1091 - -if [ -x /etc/init.d/bootcount ] && /etc/init.d/bootcount enabled; then - . /etc/init.d/bootcount -fi diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11bootcount b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11bootcount new file mode 120000 index 0000000000..a780ed1025 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S11bootcount @@ -0,0 +1 @@ +../init.d/bootcount \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S13urngd b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S13urngd deleted file mode 100755 index 6e377bc554..0000000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S13urngd +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/sh /etc/rc.common - -# shellcheck disable=SC1091 - -if [ -x /etc/init.d/urngd ] && /etc/init.d/urngd enabled; then - . /etc/init.d/urngd -fi diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S13urngd b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S13urngd new file mode 120000 index 0000000000..061fcaaf58 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S13urngd @@ -0,0 +1 @@ +../init.d/urngd \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S15gluon-setup-mode b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S15gluon-setup-mode deleted file mode 100755 index 6030b9b2c2..0000000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S15gluon-setup-mode +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh /etc/rc.common - -START=15 - -boot() { - local enabled configured - enabled="$(uci -q get 'gluon-setup-mode.@setup_mode[0].enabled')" - configured="$(uci -q get 'gluon-setup-mode.@setup_mode[0].configured')" - - uci set 'gluon-setup-mode.@setup_mode[0].enabled=0' - uci commit gluon-setup-mode - - if [ "$enabled" != 1 ] && [ "$configured" = 1 ]; then - # This can happen after an upgrade from a version before the config file was called gluon-setup-mode - # We'll just reboot to return to the normal mode... - /etc/init.d/done boot - reboot - fi -} diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S15gluon-setup-mode b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S15gluon-setup-mode new file mode 120000 index 0000000000..894e76ada4 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S15gluon-setup-mode @@ -0,0 +1 @@ +../init.d/gluon-setup-mode \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network deleted file mode 100755 index 9721558299..0000000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network +++ /dev/null @@ -1,88 +0,0 @@ -#!/bin/sh /etc/rc.common - -SETUP_MODE_ADDR=192.168.1.1 -SETUP_MODE_NETMASK=255.255.255.0 - -START=20 -STOP=90 - -USE_PROCD=1 - - -delete_interface() { - [ "$1" = 'loopback' ] || uci_remove network "$1" -} - -prepare_config() { -( - export UCI_CONFIG_DIR=/var/gluon/setup-mode/config - - mkdir -p "$UCI_CONFIG_DIR" - - cp /etc/config/network "$UCI_CONFIG_DIR" - - config_load network - config_foreach delete_interface interface - - uci_add network interface setup - uci_set network setup ifname "$(lua -e 'print(require("gluon.sysconfig").setup_ifname)')" - uci_set network setup macaddr "$(lua -e 'print(require("gluon.sysconfig").primary_mac)')" - uci_set network setup type 'bridge' - uci_set network setup proto 'static' - uci_set network setup ipaddr "$SETUP_MODE_ADDR" - uci_set network setup netmask "$SETUP_MODE_NETMASK" - - uci_commit network -) -} - -init_switch() { - setup_switch() { return 0; } - - include /lib/network - setup_switch -} - -start_service() { - prepare_config - init_switch - iw reg set "$(lua -e 'print(require("gluon.site").regdom())')" - - procd_open_instance - procd_set_param command /sbin/netifd -c /var/gluon/setup-mode/config - procd_set_param respawn - procd_set_param watch network.interface - [ -e /proc/sys/kernel/core_pattern ] && { - procd_set_param limits core="unlimited" - echo '/tmp/%e.%p.%s.%t.core' > /proc/sys/kernel/core_pattern - } - procd_close_instance -} - -reload_service() { - init_switch - ubus call network reload - /sbin/wifi reload_legacy -} - -stop_service() { - /sbin/wifi down -} - -service_running() { - ubus -t 30 wait_for network.interface - /sbin/wifi reload_legacy -} - -restart() { - ifdown -a - sleep 1 - trap '' TERM - stop "$@" - start "$@" -} - -shutdown() { - ifdown -a - stop -} diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network new file mode 120000 index 0000000000..27f4143b15 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S20network @@ -0,0 +1 @@ +../init.d/network \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear deleted file mode 100755 index 0e9c7cb9f8..0000000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/sh /etc/rc.common - -# shellcheck disable=SC1091 - -[ -x /etc/init.d/dropbear ] || return 0 -. /etc/init.d/dropbear - -start_service() { - hk_generate_as_needed - - procd_open_instance - procd_set_param command /lib/gluon/setup-mode/dropbear/dropbear -F -B - procd_set_param respawn - procd_close_instance -} diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear new file mode 120000 index 0000000000..44af88db34 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S50dropbear @@ -0,0 +1 @@ +../init.d/dropbear \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S60dnsmasq b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S60dnsmasq deleted file mode 100755 index d275b4bf0b..0000000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S60dnsmasq +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/sh /etc/rc.common - -SETUP_MODE_DHCP_RANGE=192.168.1.2,192.168.1.254 - - -START=60 - -USE_PROCD=1 -PROG=/usr/sbin/dnsmasq - - -start_service() { - procd_open_instance - procd_set_param command $PROG -k -p 0 -F $SETUP_MODE_DHCP_RANGE -l /tmp/dhcp.leases -O option:router - procd_set_param respawn - procd_close_instance -} diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S60dnsmasq b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S60dnsmasq new file mode 120000 index 0000000000..e946ac3f32 --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S60dnsmasq @@ -0,0 +1 @@ +../init.d/dnsmasq \ No newline at end of file diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led deleted file mode 100755 index fb3be6d368..0000000000 --- a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh /etc/rc.common - -# shellcheck disable=SC1091,SC2154 - -START=96 - -start() { - local custom_led - - /etc/init.d/led start - - . /etc/diag.sh - - get_status_led 2> /dev/null - - if [ -z "$status_led" ]; then - status_led="$running" - fi - - if [ -z "$status_led" ]; then - status_led="$boot" - fi - - custom_led="$(lua -e 'print(require("gluon.setup-mode").get_status_led() or "")')" - if [ -z "$status_led" ]; then - status_led="$custom_led" - fi - - status_led_set_timer 1000 300 -} diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led new file mode 120000 index 0000000000..f10e20299e --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/rc.d/S96led @@ -0,0 +1 @@ +../init.d/led \ No newline at end of file From 39dcc94389d348f61c21d9afc5458b23359e7a00 Mon Sep 17 00:00:00 2001 From: Nora Schiffer Date: Fri, 27 Feb 2026 20:30:44 +0100 Subject: [PATCH 2/2] gluon-setup-mode: replace procd patch with cleaner solution The new solution does not rely on a magical file /tmp/rc_d_path to pass information from preinit to procd. Instead, the rc.d path is set as a command line argument, which is injected using a bind-mounted wrapper over /sbin/procd. --- .../lib/gluon/setup-mode/procd-setup-mode | 10 + .../files/lib/preinit/90_setup_mode | 3 +- ...ort-for-alternative-rc.d-directories.patch | 90 -------- ...S-allow-overriding-init.d-rc.d-paths.patch | 215 ++++++++++++++++++ 4 files changed, 226 insertions(+), 92 deletions(-) create mode 100755 package/gluon-setup-mode/files/lib/gluon/setup-mode/procd-setup-mode delete mode 100644 patches/openwrt/0001-procd-add-support-for-alternative-rc.d-directories.patch create mode 100644 patches/openwrt/0001-procd-rcS-allow-overriding-init.d-rc.d-paths.patch diff --git a/package/gluon-setup-mode/files/lib/gluon/setup-mode/procd-setup-mode b/package/gluon-setup-mode/files/lib/gluon/setup-mode/procd-setup-mode new file mode 100755 index 0000000000..46085b37ee --- /dev/null +++ b/package/gluon-setup-mode/files/lib/gluon/setup-mode/procd-setup-mode @@ -0,0 +1,10 @@ +#!/bin/sh + +# We need the 'exec sh' here because this script will be mounted over /sbin/procd, +# and we can't umount it while it is still running. + +exec sh -ec 'umount /sbin/procd && \ + exec /sbin/procd \ + -I /lib/gluon/setup-mode/init.d \ + -R /lib/gluon/setup-mode/rc.d \ + "$@"' - "$@" diff --git a/package/gluon-setup-mode/files/lib/preinit/90_setup_mode b/package/gluon-setup-mode/files/lib/preinit/90_setup_mode index 1ec3bd551e..1253730ba5 100644 --- a/package/gluon-setup-mode/files/lib/preinit/90_setup_mode +++ b/package/gluon-setup-mode/files/lib/preinit/90_setup_mode @@ -1,13 +1,12 @@ #!/bin/sh - setup_mode_enable() { local enabled configured enabled="$(uci -q get 'gluon-setup-mode.@setup_mode[0].enabled')" configured="$(uci -q get 'gluon-setup-mode.@setup_mode[0].configured')" if [ "$enabled" = 1 ] || [ "$configured" != 1 ]; then - echo '/lib/gluon/setup-mode/rc.d' > /tmp/rc_d_path + mount --bind /lib/gluon/setup-mode/procd-setup-mode /sbin/procd # This directory is a marker for scripts to know that we're # in config mode, but it is also used for temporary files diff --git a/patches/openwrt/0001-procd-add-support-for-alternative-rc.d-directories.patch b/patches/openwrt/0001-procd-add-support-for-alternative-rc.d-directories.patch deleted file mode 100644 index be6f38e8fe..0000000000 --- a/patches/openwrt/0001-procd-add-support-for-alternative-rc.d-directories.patch +++ /dev/null @@ -1,90 +0,0 @@ -From: Matthias Schiffer -Date: Wed, 6 Aug 2014 19:12:00 +0200 -Subject: procd: add support for alternative rc.d directories - -diff --git a/package/system/procd/patches/0001-Add-support-for-alternative-rc.d-directories.patch b/package/system/procd/patches/0001-Add-support-for-alternative-rc.d-directories.patch -new file mode 100644 -index 0000000000000000000000000000000000000000..16d3179f05c64b7178f883745294c64a27127775 ---- /dev/null -+++ b/package/system/procd/patches/0001-Add-support-for-alternative-rc.d-directories.patch -@@ -0,0 +1,80 @@ -+From 03a2bc70e4260ec9f669391c47b9a7a9ecd0b75d Mon Sep 17 00:00:00 2001 -+Message-Id: <03a2bc70e4260ec9f669391c47b9a7a9ecd0b75d.1407329621.git.mschiffer@universe-factory.net> -+From: Matthias Schiffer -+Date: Wed, 6 Aug 2014 14:51:49 +0200 -+Subject: [PATCH] Add support for alternative rc.d directories -+ -+--- -+ initd/preinit.c | 38 ++++++++++++++++++++++++++++++++++++++ -+ rcS.c | 2 +- -+ 2 files changed, 39 insertions(+), 1 deletion(-) -+ -+--- a/initd/preinit.c -++++ b/initd/preinit.c -+@@ -87,12 +87,42 @@ fail: -+ free(command); -+ } -+ -++static char* -++get_rc_d(void) -++{ -++ size_t n = 0; -++ ssize_t len; -++ char *ret = NULL; -++ -++ FILE *fp = fopen("/tmp/rc_d_path", "r"); -++ -++ if (!fp) -++ return NULL; -++ -++ len = getline(&ret, &n, fp); -++ -++ fclose(fp); -++ -++ unlink("/tmp/rc_d_path"); -++ -++ if (len <= 0) { -++ free(ret); -++ return NULL; -++ } -++ -++ if (ret[len-1] == '\n') -++ ret[len-1] = 0; -++ -++ return ret; -++} -++ -+ static void -+ spawn_procd(struct uloop_process *proc, int ret) -+ { -+ char *wdt_fd = watchdog_fd(); -+ char *argv[] = { "/sbin/procd", NULL}; -+ char dbg[2]; -++ char *rc_d_path; -+ -+ if (plugd_proc.pid > 0) -+ kill(plugd_proc.pid, SIGKILL); -+@@ -112,6 +142,12 @@ spawn_procd(struct uloop_process *proc, -+ setenv("DBGLVL", dbg, 1); -+ } -+ -++ rc_d_path = get_rc_d(); -++ if (rc_d_path) { -++ setenv("RC_D_PATH", rc_d_path, 1); -++ free(rc_d_path); -++ } -++ -+ execvp(argv[0], argv); -+ } -+ -+--- a/rcS.c -++++ b/rcS.c -+@@ -184,7 +184,7 @@ int rcS(char *pattern, char *param, void -+ q.empty_cb = q_empty; -+ q.max_running_tasks = 1; -+ -+- return _rc(&q, "/etc/rc.d", pattern, "*", param); -++ return _rc(&q, getenv("RC_D_PATH") ?: "/etc/rc.d", pattern, "*", param); -+ } -+ -+ int rc(const char *file, char *param) diff --git a/patches/openwrt/0001-procd-rcS-allow-overriding-init.d-rc.d-paths.patch b/patches/openwrt/0001-procd-rcS-allow-overriding-init.d-rc.d-paths.patch new file mode 100644 index 0000000000..1bdf21c6f7 --- /dev/null +++ b/patches/openwrt/0001-procd-rcS-allow-overriding-init.d-rc.d-paths.patch @@ -0,0 +1,215 @@ +From: Nora Schiffer +Date: Fri, 27 Feb 2026 20:42:18 +0100 +Subject: procd: rcS: allow overriding init.d/rc.d paths + +Introduce -I and -R arguments that can be used to override the paths +/etc/init.d and /etc/rc.d, allowing for some runlevel-like usecases. + +Signed-off-by: Nora Schiffer + +diff --git a/package/system/procd/patches/0001-rcS-ubus-constify-char-arguments-and-variables-where.patch b/package/system/procd/patches/0001-rcS-ubus-constify-char-arguments-and-variables-where.patch +new file mode 100644 +index 0000000000000000000000000000000000000000..48cdb1868c8de52000734d967e967b35a85c911e +--- /dev/null ++++ b/package/system/procd/patches/0001-rcS-ubus-constify-char-arguments-and-variables-where.patch +@@ -0,0 +1,95 @@ ++From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 ++From: Nora Schiffer ++Date: Tue, 10 Feb 2026 00:30:35 +0100 ++Subject: [PATCH] rcS, ubus: constify char * arguments and variables where ++ appropriate ++ ++Signed-off-by: Nora Schiffer ++(cherry picked from commit 4e4a34b1a833505ad274d973b3e86c8b5ebcdd8d) ++--- ++ procd.h | 2 +- ++ rcS.c | 8 ++++---- ++ rcS.h | 4 ++-- ++ ubus.c | 2 +- ++ 4 files changed, 8 insertions(+), 8 deletions(-) ++ ++diff --git a/procd.h b/procd.h ++index bca3c42..5f2b12d 100644 ++--- a/procd.h +++++ b/procd.h ++@@ -27,7 +27,7 @@ ++ ++ #define __init __attribute__((constructor)) ++ ++-extern char *ubus_socket; +++extern const char *ubus_socket; ++ ++ void procd_connect_ubus(void); ++ void procd_reconnect_ubus(int reconnect); ++diff --git a/rcS.c b/rcS.c ++index 2851fae..a31cf7c 100644 ++--- a/rcS.c +++++ b/rcS.c ++@@ -125,7 +125,7 @@ static void q_initd_complete(struct runqueue *q, struct runqueue_task *p) ++ free(s); ++ } ++ ++-static void add_initd(struct runqueue *q, char *file, char *param) +++static void add_initd(struct runqueue *q, const char *file, const char *param) ++ { ++ static const struct runqueue_task_type initd_type = { ++ .run = q_initd_run, ++@@ -153,7 +153,7 @@ static void add_initd(struct runqueue *q, char *file, char *param) ++ runqueue_task_add(q, &s->proc.task, false); ++ } ++ ++-static int _rc(struct runqueue *q, char *path, const char *file, char *pattern, char *param) +++static int _rc(struct runqueue *q, const char *path, const char *file, const char *pattern, const char *param) ++ { ++ char *dir = alloca(2 + strlen(path) + strlen(file) + strlen(pattern)); ++ glob_t gl; ++@@ -179,7 +179,7 @@ static int _rc(struct runqueue *q, char *path, const char *file, char *pattern, ++ return 0; ++ } ++ ++-int rcS(char *pattern, char *param, void (*q_empty)(struct runqueue *)) +++int rcS(const char *pattern, const char *param, void (*q_empty)(struct runqueue *)) ++ { ++ runqueue_init(&q); ++ q.empty_cb = q_empty; ++@@ -188,7 +188,7 @@ int rcS(char *pattern, char *param, void (*q_empty)(struct runqueue *)) ++ return _rc(&q, "/etc/rc.d", pattern, "*", param); ++ } ++ ++-int rc(const char *file, char *param) +++int rc(const char *file, const char *param) ++ { ++ return _rc(&r, "/etc/init.d", file, "", param); ++ } ++diff --git a/rcS.h b/rcS.h ++index 91d37d1..9b6bb84 100644 ++--- a/rcS.h +++++ b/rcS.h ++@@ -17,7 +17,7 @@ ++ ++ #include ++ ++-extern int rcS(char *pattern, char *param, void (*q_empty)(struct runqueue *)); ++-extern int rc(const char *file, char *param); +++extern int rcS(const char *pattern, const char *param, void (*q_empty)(struct runqueue *)); +++extern int rc(const char *file, const char *param); ++ ++ #endif ++diff --git a/ubus.c b/ubus.c ++index b0b7c9a..23f640a 100644 ++--- a/ubus.c +++++ b/ubus.c ++@@ -19,7 +19,7 @@ ++ ++ #include "procd.h" ++ ++-char *ubus_socket = NULL; +++const char *ubus_socket = NULL; ++ static struct ubus_context *ctx; ++ static struct uloop_timeout ubus_timer; ++ static int timeout; +diff --git a/package/system/procd/patches/0002-rcS-allow-overriding-init.d-rc.d-paths.patch b/package/system/procd/patches/0002-rcS-allow-overriding-init.d-rc.d-paths.patch +new file mode 100644 +index 0000000000000000000000000000000000000000..aa95dbeb7d803c0aa09060a340199253d19b082d +--- /dev/null ++++ b/package/system/procd/patches/0002-rcS-allow-overriding-init.d-rc.d-paths.patch +@@ -0,0 +1,99 @@ ++From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 ++From: Nora Schiffer ++Date: Tue, 10 Feb 2026 00:30:43 +0100 ++Subject: [PATCH] rcS: allow overriding init.d/rc.d paths ++ ++Introduce -I and -R arguments which can be used to override the paths ++/etc/init.d and /etc/rc.d, allowing for some runlevel-like usecases. ++ ++This will be used in Gluon [1] to support a 'config mode', which is ++currently realized using a downstream patch. ++ ++[1] https://github.com/freifunk-gluon/gluon ++ ++Signed-off-by: Nora Schiffer ++(cherry picked from commit 2881a59f304326cf0a71c849738d052ba317b4cb) ++--- ++ procd.c | 10 +++++++++- ++ procd.h | 3 +++ ++ rcS.c | 7 +++++-- ++ 3 files changed, 17 insertions(+), 3 deletions(-) ++ ++diff --git a/procd.c b/procd.c ++index 1223283..46ba680 100644 ++--- a/procd.c +++++ b/procd.c ++@@ -83,6 +83,8 @@ static int usage(const char *prog) ++ " -s Path to ubus socket\n" ++ " -h run as hotplug daemon\n" ++ " -d Enable debug messages\n" +++ " -I Path to init.d directory\n" +++ " -R Path to rc.d directory\n" ++ " -S Print messages to stdout\n" ++ "\n", prog); ++ return 1; ++@@ -99,7 +101,7 @@ int main(int argc, char **argv) ++ unsetenv("DBGLVL"); ++ } ++ ++- while ((ch = getopt(argc, argv, "d:s:h:S")) != -1) { +++ while ((ch = getopt(argc, argv, "d:s:h:I:R:S")) != -1) { ++ switch (ch) { ++ case 'h': ++ return hotplug_run(optarg); ++@@ -109,6 +111,12 @@ int main(int argc, char **argv) ++ case 'd': ++ debug = atoi(optarg); ++ break; +++ case 'I': +++ init_d_path = optarg; +++ break; +++ case 'R': +++ rc_d_path = optarg; +++ break; ++ case 'S': ++ ulog_channels = ULOG_STDIO; ++ break; ++diff --git a/procd.h b/procd.h ++index 5f2b12d..8bd5b6a 100644 ++--- a/procd.h +++++ b/procd.h ++@@ -27,6 +27,9 @@ ++ ++ #define __init __attribute__((constructor)) ++ +++extern const char *init_d_path; +++extern const char *rc_d_path; +++ ++ extern const char *ubus_socket; ++ ++ void procd_connect_ubus(void); ++diff --git a/rcS.c b/rcS.c ++index a31cf7c..f3617f2 100644 ++--- a/rcS.c +++++ b/rcS.c ++@@ -33,6 +33,9 @@ ++ #include "procd.h" ++ #include "rcS.h" ++ +++const char *init_d_path = "/etc/init.d"; +++const char *rc_d_path = "/etc/rc.d"; +++ ++ static struct runqueue q, r; ++ ++ struct initd { ++@@ -185,12 +188,12 @@ int rcS(const char *pattern, const char *param, void (*q_empty)(struct runqueue ++ q.empty_cb = q_empty; ++ q.max_running_tasks = 1; ++ ++- return _rc(&q, "/etc/rc.d", pattern, "*", param); +++ return _rc(&q, rc_d_path, pattern, "*", param); ++ } ++ ++ int rc(const char *file, const char *param) ++ { ++- return _rc(&r, "/etc/init.d", file, "", param); +++ return _rc(&r, init_d_path, file, "", param); ++ } ++ ++ static void r_empty(struct runqueue *q)