qubes/log: add FD_CLOEXEC to log files
Don't leak log file descriptors. At least 'lvm' complains. QubesOS/qubes-issues#2412
This commit is contained in:
parent
194fb9b99b
commit
6ff836dfa4
@ -30,6 +30,7 @@ See also: :py:attr:`qubes.vm.qubesvm.QubesVM.log`
|
|||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
import fcntl
|
||||||
|
|
||||||
import dbus
|
import dbus
|
||||||
|
|
||||||
@ -107,6 +108,8 @@ def enable():
|
|||||||
old_umask = os.umask(0o007)
|
old_umask = os.umask(0o007)
|
||||||
try:
|
try:
|
||||||
handler_log = logging.FileHandler(log_path, 'a', encoding='utf-8')
|
handler_log = logging.FileHandler(log_path, 'a', encoding='utf-8')
|
||||||
|
fcntl.fcntl(handler_log.stream.fileno(),
|
||||||
|
fcntl.F_SETFD, fcntl.FD_CLOEXEC)
|
||||||
finally:
|
finally:
|
||||||
os.umask(old_umask)
|
os.umask(old_umask)
|
||||||
handler_log.setFormatter(formatter_log)
|
handler_log.setFormatter(formatter_log)
|
||||||
@ -140,6 +143,8 @@ def get_vm_logger(vmname):
|
|||||||
try:
|
try:
|
||||||
handler = logging.FileHandler(
|
handler = logging.FileHandler(
|
||||||
os.path.join(LOGPATH, 'vm-{}.log'.format(vmname)))
|
os.path.join(LOGPATH, 'vm-{}.log'.format(vmname)))
|
||||||
|
fcntl.fcntl(handler.stream.fileno(),
|
||||||
|
fcntl.F_SETFD, fcntl.FD_CLOEXEC)
|
||||||
finally:
|
finally:
|
||||||
os.umask(old_umask)
|
os.umask(old_umask)
|
||||||
handler.setFormatter(formatter_log)
|
handler.setFormatter(formatter_log)
|
||||||
|
Loading…
Reference in New Issue
Block a user