firewall: save firewall.xml with utils.replace_file()

Don't rewrite the file in-place.

Also change the error message from 'save error' to 'firewall save
error'.
This commit is contained in:
Rusty Bird 2021-02-10 12:58:00 +00:00
parent c988a2218b
commit 7159f206a5
No known key found for this signature in database
GPG Key ID: 469D78F47AAF2ADF

View File

@ -31,6 +31,7 @@ import asyncio
import lxml.etree import lxml.etree
import qubes import qubes
import qubes.utils
import qubes.vm.qubesvm import qubes.vm.qubesvm
@ -577,14 +578,13 @@ class Firewall:
xml_tree = lxml.etree.ElementTree(xml_root) xml_tree = lxml.etree.ElementTree(xml_root)
try: try:
old_umask = os.umask(0o002) with qubes.utils.replace_file(firewall_conf,
with open(firewall_conf, 'wb') as firewall_xml: permissions=0o664) as tmp_io:
xml_tree.write(firewall_xml, encoding="UTF-8", xml_tree.write(tmp_io, encoding='UTF-8', pretty_print=True)
pretty_print=True)
os.umask(old_umask)
except EnvironmentError as err: except EnvironmentError as err:
self.vm.log.error("save error: {}".format(err)) msg='firewall save error: {}'.format(err)
raise qubes.exc.QubesException('save error: {}'.format(err)) self.vm.log.error(msg)
raise qubes.exc.QubesException(msg)
self.vm.fire_event('firewall-changed') self.vm.fire_event('firewall-changed')