From 6ff836dfa4ec8c876c0dac2246e1d063bed2287e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Marczykowski-G=C3=B3recki?= Date: Thu, 3 Nov 2016 22:46:02 +0100 Subject: [PATCH] qubes/log: add FD_CLOEXEC to log files Don't leak log file descriptors. At least 'lvm' complains. QubesOS/qubes-issues#2412 --- qubes/log.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/qubes/log.py b/qubes/log.py index 1a92b360..0292ee31 100644 --- a/qubes/log.py +++ b/qubes/log.py @@ -30,6 +30,7 @@ See also: :py:attr:`qubes.vm.qubesvm.QubesVM.log` import logging import os import sys +import fcntl import dbus @@ -107,6 +108,8 @@ def enable(): old_umask = os.umask(0o007) try: handler_log = logging.FileHandler(log_path, 'a', encoding='utf-8') + fcntl.fcntl(handler_log.stream.fileno(), + fcntl.F_SETFD, fcntl.FD_CLOEXEC) finally: os.umask(old_umask) handler_log.setFormatter(formatter_log) @@ -140,6 +143,8 @@ def get_vm_logger(vmname): try: handler = logging.FileHandler( os.path.join(LOGPATH, 'vm-{}.log'.format(vmname))) + fcntl.fcntl(handler.stream.fileno(), + fcntl.F_SETFD, fcntl.FD_CLOEXEC) finally: os.umask(old_umask) handler.setFormatter(formatter_log)