Skip to content

Commit

Permalink
add comment and warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nikatlas authored and brianmay committed Jun 2, 2022
1 parent 1def53e commit 93200f7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sshuttle/firewall.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def rewrite_etc_hosts(hostmap, port):
try:
os.link(HOSTSFILE, BAKFILE)
except OSError:
# file is locked - performing non-atomic copy
shutil.copyfile(HOSTSFILE, BAKFILE)
tmpname = "%s.%d.tmp" % (HOSTSFILE, port)
f = open(tmpname, 'w')
Expand All @@ -54,6 +55,9 @@ def rewrite_etc_hosts(hostmap, port):
try:
os.rename(tmpname, HOSTSFILE)
except OSError:
# file is locked - performing non-atomic copy
log('Warning: Using a non-atomic way to overwrite %s that can corrupt the file if '
'multiple processes write to it simultaneously.' % HOSTSFILE)
shutil.move(tmpname, HOSTSFILE)


Expand Down

0 comments on commit 93200f7

Please sign in to comment.