plugins/python/example_io_plugin: close the file at destroy

to avoid warning of debug python build.
This commit is contained in:
Robert Manner
2020-01-28 14:15:57 +01:00
committed by Todd C. Miller
parent a3a7630ff4
commit 4110800c14
2 changed files with 2 additions and 1 deletions

View File

@@ -63,6 +63,7 @@ class SudoIOPlugin(sudo.Plugin):
def __del__(self): def __del__(self):
if hasattr(self, "_log_file"): if hasattr(self, "_log_file"):
self._log("", "-- Plugin DESTROYED --") self._log("", "-- Plugin DESTROYED --")
self._log_file.close()
def open(self, argv: Tuple[str, ...], command_info: Tuple[str, ...]) -> int: def open(self, argv: Tuple[str, ...], command_info: Tuple[str, ...]) -> int:
"""Receives the command the user wishes to run. """Receives the command the user wishes to run.

View File

@@ -2,6 +2,6 @@ Example sudo python plugin will log to /some/not/writable/directory/sudo.log
Traceback: Traceback:
File "SRC_DIR/example_io_plugin.py", line 60, in __init__ File "SRC_DIR/example_io_plugin.py", line 60, in __init__
self._open_log_file(path.join(log_path, "sudo.log")) self._open_log_file(path.join(log_path, "sudo.log"))
File "SRC_DIR/example_io_plugin.py", line 131, in _open_log_file File "SRC_DIR/example_io_plugin.py", line 132, in _open_log_file
self._log_file = open(log_path, "a") self._log_file = open(log_path, "a")