[LEDE-DEV] [RFC] base-files: call "sync" before removing uci-defaults file

Rafał Miłecki zajec5 at gmail.com
Mon Sep 5 13:29:31 PDT 2016


From: Rafał Miłecki <rafal at milecki.pl>

It makes booting more reliable in case of power cuts. Up to now some
file system changes done in uci-defaults could be lost due to lack of
flushing. It was easy to spot with scripts creating files: after a power
cut created file was empty and uci-defaults script was deleted.

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
Hey,

I'm far from sure if this is a correct solution, you may better treat it
as a problem report. It's trivial for me to reproduce this problem using
BCM47081 evice (with NAND and squashfs+ubifs) and following script:

#!/bin/sh
echo -n "First booted on " > /etc/foo
date >> /etc/foo
echo "FOO FOO FOO" > /dev/kmsg
echo "FOO FOO FOO" > /dev/kmsg
echo "FOO FOO FOO" > /dev/kmsg
exit 0

After seeing "FOO FOO FOO" messages I can wait ~3 seconds, then do:
cat /etc/foo
(see expected output), power off device and see the issue on the next
boot. The created file /etc/foo is empty but /etc/foo is white-outed.
---
 package/base-files/files/etc/init.d/boot | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot
index 904f7db..cad001b 100755
--- a/package/base-files/files/etc/init.d/boot
+++ b/package/base-files/files/etc/init.d/boot
@@ -12,7 +12,7 @@ uci_apply_defaults() {
 	[ -z "$files" ] && return 0
 	mkdir -p /tmp/.uci
 	for file in $files; do
-		( . "./$(basename $file)" ) && rm -f "$file"
+		( . "./$(basename $file)" ) && sync && rm -f "$file"
 	done
 	uci commit
 }
-- 
2.9.3




More information about the Lede-dev mailing list