aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-10-31 18:13:31 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2017-10-31 18:13:31 +0100
commit6e313371cccc13c742a4ed3daaa4d826937f6596 (patch)
tree3adcda34e110bf2fde5e531635d24839f87eb2d9 /src
parentwg-quick: allow for saving existing interface (diff)
downloadwireguard-tools-6e313371cccc13c742a4ed3daaa4d826937f6596.tar.xz
wireguard-tools-6e313371cccc13c742a4ed3daaa4d826937f6596.zip
wg-quick: fsync the temporary file before renaming
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>
Diffstat (limited to 'src')
-rwxr-xr-xsrc/wg-quick.bash1
1 files changed, 1 insertions, 0 deletions
diff --git a/src/wg-quick.bash b/src/wg-quick.bash
index da4c0d4..7dc8be1 100755
--- a/src/wg-quick.bash
+++ b/src/wg-quick.bash
@@ -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"