]> git.ipfire.org Git - thirdparty/wireguard-tools.git/commitdiff
wg-quick: fsync the temporary file before renaming
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 31 Oct 2017 17:13:31 +0000 (18:13 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 31 Oct 2017 17:13:31 +0000 (18:13 +0100)
This ensures that on an unclean shutdown, we either see the old content
or the new content, but not empty content.

Suggested-by: Ka Ho Ng <ngkaho1234@gmail.com>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/wg-quick.bash

index da4c0d4bcfc5ecca5b6688af74cb8a9107a877e3..7dc8be1767e6e7bff785eb12b6f96d5218bc6e83 100755 (executable)
@@ -197,6 +197,7 @@ save_config() {
        current_config="$(cmd wg showconf "$INTERFACE")"
        trap 'rm -f "$CONFIG_FILE.tmp"; exit' INT TERM EXIT
        echo "${current_config/\[Interface\]$'\n'/$new_config}" > "$CONFIG_FILE.tmp" || die "Could not write configuration file"
+       sync "$CONFIG_FILE.tmp"
        mv "$CONFIG_FILE.tmp" "$CONFIG_FILE" || die "Could not move configuration file"
        trap - INT TERM EXIT
        umask "$old_umask"