diff mbox series

[LEDE-DEV] base-files: add comment to uci-defaults.sh script

Message ID 20171212102453.15258-1-john@phrozen.org
State Superseded
Headers show
Series [LEDE-DEV] base-files: add comment to uci-defaults.sh script | expand

Commit Message

John Crispin Dec. 12, 2017, 10:24 a.m. UTC
add comment explaining why we generate board.json in 2 steps

Signed-off-by: John Crispin <john@phrozen.org>
---
 package/base-files/files/lib/functions/uci-defaults.sh | 4 ++++
 1 file changed, 4 insertions(+)

Comments

Matthias Schiffer Dec. 12, 2017, 10:38 a.m. UTC | #1
On 12/12/2017 11:24 AM, John Crispin wrote:
> 
>  
>  board_config_flush() {
> +	# when calling json_dump with a redirect, the shell will truncate the target
> +	# file and not update it until a close/flush is called. this results in a short
> +	# window where the file is 0 bytes. mitigate the issue by generating the file
> +	# in 2 steps

As Roman correctly noted in his patch, this is not the case. The file is
moved between different filesystems (tmpfs to actual root), which is never
guaranteed to be atomic; internally, rename() can't be used, so mv just
falls back to truncate+write as well. The mv makes the race window shorter,
but does not completely mitigate it.

Either the comment should correctly reflect the situation, or we should
actually fix this by creating the temporary file on the root fs.

Regards,
Matthias

>  	json_dump -i > /tmp/.board.json
>  	mv /tmp/.board.json ${CFG}
>  }
>
diff mbox series

Patch

diff --git a/package/base-files/files/lib/functions/uci-defaults.sh b/package/base-files/files/lib/functions/uci-defaults.sh
index 82ac1d2a4d..fd37088208 100755
--- a/package/base-files/files/lib/functions/uci-defaults.sh
+++ b/package/base-files/files/lib/functions/uci-defaults.sh
@@ -609,6 +609,10 @@  board_config_update() {
 }
 
 board_config_flush() {
+	# when calling json_dump with a redirect, the shell will truncate the target
+	# file and not update it until a close/flush is called. this results in a short
+	# window where the file is 0 bytes. mitigate the issue by generating the file
+	# in 2 steps
 	json_dump -i > /tmp/.board.json
 	mv /tmp/.board.json ${CFG}
 }