From bf08ffb05118e9c9e8bb645caf4b29812a0a065f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Tue, 1 Mar 2022 18:46:27 +0100 Subject: [PATCH 1/8] base-files: call "sync" after initial setup MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit OpenWrt uses a lot of (b)ash scripts for initial setup. This isn't the best solution as they almost never consider syncing files / data. Still this is what we have and we need to try living with it. Without proper syncing OpenWrt can easily get into an inconsistent state on power cut. It's because: 1. Actual (flash) inode and data writes are not synchronized 2. Data writeback can take up to 30 seconds (dirty_expire_centisecs) 3. ubifs adds extra 5 seconds (dirty_writeback_centisecs) "delay" Some possible cases (examples) for new files: 1. Power cut during 5 seconds after write() can result in all data loss 2. Power cut happening between 5 and 35 seconds after write() can result in empty file (inode flushed after 5 seconds, data flush queued) Above affects e.g. uci-defaults. After executing some migration script it may get deleted (whited out) without generated data getting actually written. Power cut will result in missing data and deleted file. There are three ways of dealing with that: 1. Rewriting all user-space init to proper C with syncs 2. Trying bash hacks (like creating tmp files & moving them) 3. Adding sync and hoping for no power cut during critical section This change introduces the last solution that is the simplest. It reduces time during which things may go wrong from ~35 seconds to probably less than a second. Of course it applies only to IO operations performed before /etc/init.d/boot . It's probably the stage when the most new files get created. All later changes are usually done using smarter C apps (e.g. busybox or uci) that creates tmp files and uses rename() that is expected to be atomic. Signed-off-by: Rafał Miłecki Acked-by: Hauke Mehrtens Acked-by: Sergey Ryazanov --- package/base-files/files/etc/init.d/boot | 1 + 1 file changed, 1 insertion(+) diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot index e1c60c1c2..749d9e971 100755 --- a/package/base-files/files/etc/init.d/boot +++ b/package/base-files/files/etc/init.d/boot @@ -48,6 +48,7 @@ boot() { /bin/config_generate uci_apply_defaults + sync # temporary hack until configd exists /sbin/reload_config From d8f60f0b7f0269925525be8102ad554b94cafaab Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Fri, 9 Apr 2021 17:22:48 -0700 Subject: [PATCH 2/8] base-files: fix zoneinfo support The system init script currently sets /tmp/localinfo when zoneinfo is populated. However, zoneinfo has spaces in it whereas the actual files have _ instead of spaces. This made the if condition never return true. Example failure when removing the if condition: /tmp/localtime -> /usr/share/zoneinfo/America/Los Angeles This file does not exist. America/Los_Angeles does. Ran through shfmt -w -ci -bn -sr -s Signed-off-by: Rosen Penev --- package/base-files/files/etc/init.d/system | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/package/base-files/files/etc/init.d/system b/package/base-files/files/etc/init.d/system index 08cf86b97..2290964d7 100755 --- a/package/base-files/files/etc/init.d/system +++ b/package/base-files/files/etc/init.d/system @@ -4,8 +4,7 @@ START=10 USE_PROCD=1 -validate_system_section() -{ +validate_system_section() { uci_load_validate system system "$1" "$2" \ 'hostname:string:OpenWrt' \ 'conloglevel:uinteger' \ @@ -22,9 +21,13 @@ system_config() { echo "$hostname" > /proc/sys/kernel/hostname [ -z "$conloglevel" -a -z "$buffersize" ] || dmesg ${conloglevel:+-n $conloglevel} ${buffersize:+-s $buffersize} - echo "$timezone" > /tmp/TZ - [ -n "$zonename" ] && [ -f "/usr/share/zoneinfo/$zonename" ] && \ - ln -sf "/usr/share/zoneinfo/$zonename" /tmp/localtime && rm -f /tmp/TZ + rm -f /tmp/TZ + if [ -n "$zonename" ]; then + local zname=$(echo "$zonename" | tr ' ' _) + [ -f "/usr/share/zoneinfo/$zname" ] && ln -sf "/usr/share/zoneinfo/$zname" /tmp/localtime + else + echo "$timezone" > /tmp/TZ + fi # apply timezone to kernel hwclock -u --systz @@ -35,8 +38,7 @@ reload_service() { config_foreach validate_system_section system system_config } -service_triggers() -{ +service_triggers() { procd_add_reload_trigger "system" procd_add_validation validate_system_section } From 86e7043d56d221c55febe0c240ed4fe1a9b71ab1 Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Thu, 24 Jun 2021 07:42:53 -1000 Subject: [PATCH 3/8] base-files: fix /tmp/TZ when zoneinfo not installed The zoneinfo packages are not installed per default so neither /tmp/localtime nor /tmp/TZ is generated. This patch mostly reverts the previous fix and instead incooperates a solution suggested by Jo. Fixes "base-files: fix zoneinfo support " 8af62ed Signed-off-by: Paul Spooren --- package/base-files/files/etc/init.d/system | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/package/base-files/files/etc/init.d/system b/package/base-files/files/etc/init.d/system index 2290964d7..dcfc2616c 100755 --- a/package/base-files/files/etc/init.d/system +++ b/package/base-files/files/etc/init.d/system @@ -21,13 +21,10 @@ system_config() { echo "$hostname" > /proc/sys/kernel/hostname [ -z "$conloglevel" -a -z "$buffersize" ] || dmesg ${conloglevel:+-n $conloglevel} ${buffersize:+-s $buffersize} - rm -f /tmp/TZ - if [ -n "$zonename" ]; then - local zname=$(echo "$zonename" | tr ' ' _) - [ -f "/usr/share/zoneinfo/$zname" ] && ln -sf "/usr/share/zoneinfo/$zname" /tmp/localtime - else - echo "$timezone" > /tmp/TZ - fi + echo "$timezone" > /tmp/TZ + [ -n "$zonename" ] && [ -f "/usr/share/zoneinfo/${zonename// /_}" ] \ + && ln -sf "/usr/share/zoneinfo/${zonename// /_}" /tmp/localtime \ + && rm -f /tmp/TZ # apply timezone to kernel hwclock -u --systz From 7c60c217687e771d99ccc592bd04f8377faf61a5 Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Sat, 5 Feb 2022 09:38:53 -0800 Subject: [PATCH 4/8] base-files: replace fgrep with grep -F fgrep is deprecated and replaced by grep -F. The latter is used throughout the tree whereas this is the only usage of the former. Signed-off-by: Rosen Penev --- package/base-files/files/etc/profile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/base-files/files/etc/profile b/package/base-files/files/etc/profile index 0beff1608..76b149b9f 100644 --- a/package/base-files/files/etc/profile +++ b/package/base-files/files/etc/profile @@ -3,7 +3,7 @@ [ -f /etc/banner ] && cat /etc/banner [ -n "$FAILSAFE" ] && cat /etc/banner.failsafe -fgrep -sq '/ overlay ro,' /proc/mounts && { +grep -Fsq '/ overlay ro,' /proc/mounts && { echo 'Your JFFS2-partition seems full and overlayfs is mounted read-only.' echo 'Please try to remove files from /overlay/upper/... and reboot!' } From fb92a12a001751ea60040914f4b0bf312d1a97a5 Mon Sep 17 00:00:00 2001 From: Rucke Teg Date: Tue, 22 Feb 2022 22:53:25 +0100 Subject: [PATCH 5/8] base-file: remove password aging feature form /etc/shadow In the default shadow file, as visible in the failsafe mode, the user root has value of `0` set in the 3rd field, the date of last password change. This setting means that the password needs to be changed the next time the user will log in the system. `dropbear` server is ignoring this setting but `openssh-server` tries to enforce it and fails in the failsafe mode because the rootfs is R/O. Disable the password aging feature for user root by setting the 3rd filed empty. Signed-off-by: Rucke Teg --- package/base-files/files/etc/shadow | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/base-files/files/etc/shadow b/package/base-files/files/etc/shadow index 4b4154f21..39bdb9c90 100644 --- a/package/base-files/files/etc/shadow +++ b/package/base-files/files/etc/shadow @@ -1,4 +1,4 @@ -root::0:0:99999:7::: +root:::0:99999:7::: daemon:*:0:0:99999:7::: ftp:*:0:0:99999:7::: network:*:0:0:99999:7::: From cb419fc84740c9495b65de66180afb075cec81a1 Mon Sep 17 00:00:00 2001 From: Olliver Schinagl Date: Wed, 21 Sep 2022 17:57:53 +0200 Subject: [PATCH 6/8] base-files: Actually set default name The currently used shell expansion doesn't seem to exist [0] and also does not work. This surely was not intended, so lets allow default naming to actually work. [0]: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html Fixes: be09c5a3cd65 ("base-files: add board.d support for bridge device") Signed-off-by: Olliver Schinagl --- package/base-files/files/lib/functions/uci-defaults.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh index 407a9c710..13d156ae5 100644 --- a/package/base-files/files/lib/functions/uci-defaults.sh +++ b/package/base-files/files/lib/functions/uci-defaults.sh @@ -96,7 +96,7 @@ ucidef_set_interfaces_lan_wan() { ucidef_set_bridge_device() { json_select_object bridge - json_add_string name "${1:switch0}" + json_add_string name "${1:-switch0}" json_select .. } From 1688dda0ba9d3da13b3d031d4caf0c6f02770956 Mon Sep 17 00:00:00 2001 From: Bob Cantor Date: Mon, 5 Jul 2021 03:03:58 +1000 Subject: [PATCH 7/8] base-files: wifi: for wifi up, scan_wifi after network reload Commit b82cc8071366 included an unintended change and we now call scan_wifi before a network reload. Restore the original behaviour and call scan_wifi only after a network reload. Fixes: b82cc8071366 ("base-files: wifi: swap the order of some ubus calls") Signed-off-by: Bob Cantor --- package/base-files/files/sbin/wifi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/base-files/files/sbin/wifi b/package/base-files/files/sbin/wifi index 6b9662fe9..7e248add9 100755 --- a/package/base-files/files/sbin/wifi +++ b/package/base-files/files/sbin/wifi @@ -128,9 +128,9 @@ wifi_updown() { [ enable = "$1" ] && { _wifi_updown disable "$2" ubus_wifi_cmd "$cmd" "$2" + ubus call network reload scan_wifi cmd=up - ubus call network reload } [ reconf = "$1" ] && { scan_wifi From 5052e706749a33585186cbc6cac8f8832ba62154 Mon Sep 17 00:00:00 2001 From: Bob Cantor Date: Mon, 5 Jul 2021 03:26:46 +1000 Subject: [PATCH 8/8] base-files: wifi: for wifi reconf, scan_wifi after network reload Commit e8b542960921 included an unintended change and we now call scan_wifi before a network reload. Restore the original behaviour and call scan_wifi only after a network reload. Fixes: e8b542960921 ("base-files: wifi: tidy up the reconf code") Signed-off-by: Bob Cantor --- package/base-files/files/sbin/wifi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/base-files/files/sbin/wifi b/package/base-files/files/sbin/wifi index 7e248add9..6a9dce7e8 100755 --- a/package/base-files/files/sbin/wifi +++ b/package/base-files/files/sbin/wifi @@ -133,9 +133,9 @@ wifi_updown() { cmd=up } [ reconf = "$1" ] && { + ubus call network reload scan_wifi cmd=reconf - ubus call network reload } ubus_wifi_cmd "$cmd" "$2" _wifi_updown "$@"